Skip to content

Commit

Permalink
Reduce visibility of DevInternalSettings class (#37256)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37256

This class is public but annotated with VisibleForTesting which is not correct (as there are no tests for it).
Apparently this class is used only within this package so it's safe to reduce its visibility to package internal.

On top of this, we had methods which were not annotated with Override, which I've fixed + I've sorted the methods to have first all the public/Override ones and the then others after.

Changelog:
[Android] [Removed] - Reduce visibility of DevInternalSettings class

Reviewed By: mdvacca

Differential Revision: D45566473

fbshipit-source-id: 41cc0d584c328125a7866e15b483b2206958cd80
  • Loading branch information
cortinico authored and facebook-github-bot committed May 4, 2023
1 parent 4c91e8a commit 3f20a1d
Showing 1 changed file with 28 additions and 28 deletions.
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

0 comments on commit 3f20a1d

Please sign in to comment.