Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce visibility of DevInternalSettings class #37256

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
import com.facebook.react.packagerconnection.PackagerConnectionSettings;

/**
* Helper class for accessing developers settings that should not be accessed outside of the package
* Helper class for accessing developers settings that can not be accessed outside of the package
* {@link com.facebook.react.devsupport}. For accessing some of the settings by external modules
* this class implements an external interface {@link DeveloperSettings}.
*/
@VisibleForTesting
public class DevInternalSettings
class DevInternalSettings
implements DeveloperSettings, SharedPreferences.OnSharedPreferenceChangeListener {

private static final String PREFS_FPS_DEBUG_KEY = "fps_debug";
Expand All @@ -45,19 +43,11 @@ public DevInternalSettings(Context applicationContext, Listener listener) {
mPackagerConnectionSettings = new PackagerConnectionSettings(applicationContext);
}

public PackagerConnectionSettings getPackagerConnectionSettings() {
return mPackagerConnectionSettings;
}

@Override
public boolean isFpsDebugEnabled() {
return mPreferences.getBoolean(PREFS_FPS_DEBUG_KEY, false);
}

public void setFpsDebugEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_FPS_DEBUG_KEY, enabled).apply();
}

@Override
public boolean isAnimationFpsDebugEnabled() {
return mPreferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false);
Expand All @@ -68,15 +58,12 @@ public boolean isJSDevModeEnabled() {
return mPreferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true);
}

public void setJSDevModeEnabled(boolean value) {
mPreferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply();
}

@Override
public boolean isJSMinifyEnabled() {
return mPreferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (mListener != null) {
if (PREFS_FPS_DEBUG_KEY.equals(key)
Expand All @@ -88,22 +75,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}

public boolean isHotModuleReplacementEnabled() {
return mPreferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, true);
}

public void setHotModuleReplacementEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply();
}

@Override
public boolean isElementInspectorEnabled() {
return mPreferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false);
}

public void setElementInspectorEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply();
}

@Override
public boolean isDeviceDebugEnabled() {
return ReactBuildConfig.IS_INTERNAL_BUILD && ReactBuildConfig.DEBUG;
Expand All @@ -129,6 +105,30 @@ public void addMenuItem(String title) {
// Not supported.
}

void setElementInspectorEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply();
}

boolean isHotModuleReplacementEnabled() {
return mPreferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, true);
}

void setHotModuleReplacementEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply();
}

void setJSDevModeEnabled(boolean value) {
mPreferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply();
}

void setFpsDebugEnabled(boolean enabled) {
mPreferences.edit().putBoolean(PREFS_FPS_DEBUG_KEY, enabled).apply();
}

PackagerConnectionSettings getPackagerConnectionSettings() {
return mPackagerConnectionSettings;
}

public interface Listener {
void onInternalSettingsChanged();
}
Expand Down