Remove injecting developer options into Settings itself
- It can improve performance because we use less injected item - Also use RestrictedPreference instead just checking restrictions, so we follow policy transparency. Note: Renamed DevelopmentSettingsDashboardActivity to DevelopmentSettingsActivity, because DevelopmentSettingsDashboardActivity could in disabled state even after Settings upgrades, use a new name to prevent this issue. Bug: 311604902 Test: manual - turn on / off Developer Options Test: unit test Change-Id: I17be117ae59e59410687e6d08fd5edd034d0508f
This commit is contained in:
@@ -134,7 +134,7 @@ public class Settings extends SettingsActivity {
|
||||
public static class HighPowerApplicationsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class BackgroundCheckSummaryActivity extends SettingsActivity { /* empty */ }
|
||||
public static class StorageUseActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DevelopmentSettingsDashboardActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DevelopmentSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class AccessibilitySettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class AccessibilityDetailsSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class CaptioningSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
@@ -48,7 +48,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
@@ -70,7 +69,6 @@ import com.android.settings.wfd.WifiDisplaySettings;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||
import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
@@ -174,8 +172,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
private CharSequence mInitialTitle;
|
||||
private int mInitialTitleResId;
|
||||
|
||||
private BroadcastReceiver mDevelopmentSettingsListener;
|
||||
|
||||
private boolean mBatteryPresent = true;
|
||||
private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -614,15 +610,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
super.onResume();
|
||||
setActionBarStatus();
|
||||
|
||||
mDevelopmentSettingsListener = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
updateTilesList();
|
||||
}
|
||||
};
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mDevelopmentSettingsListener,
|
||||
new IntentFilter(DevelopmentSettingsEnabler.DEVELOPMENT_SETTINGS_CHANGED_ACTION));
|
||||
|
||||
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
|
||||
updateTilesList();
|
||||
@@ -631,8 +618,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mDevelopmentSettingsListener);
|
||||
mDevelopmentSettingsListener = null;
|
||||
unregisterReceiver(mBatteryInfoReceiver);
|
||||
}
|
||||
|
||||
@@ -781,13 +766,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
Utils.isBandwidthControlEnabled(), isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
|
||||
&& !Utils.isMonkeyRunning();
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
Settings.DevelopmentSettingsDashboardActivity.class.getName()),
|
||||
showDev, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
Settings.WifiDisplaySettingsActivity.class.getName()),
|
||||
WifiDisplaySettings.isAvailable(this), isAdmin)
|
||||
|
||||
@@ -47,6 +47,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
@@ -230,6 +231,12 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
getActivity().finish();
|
||||
return;
|
||||
}
|
||||
Context context = requireContext();
|
||||
if (!DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context)) {
|
||||
Toast.makeText(context, R.string.dev_settings_disabled_warning, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class DevelopmentSettingsDisabledActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Toast.makeText(this, R.string.dev_settings_disabled_warning, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.system
|
||||
|
||||
import android.app.settings.SettingsEnums
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.UserManager
|
||||
import android.provider.Settings
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.android.settings.R
|
||||
import com.android.settings.core.SubSettingLauncher
|
||||
import com.android.settings.development.DevelopmentSettingsDashboardFragment
|
||||
import com.android.settings.spa.preference.ComposePreferenceController
|
||||
import com.android.settingslib.spa.widget.preference.PreferenceModel
|
||||
import com.android.settingslib.spa.widget.ui.SettingsIcon
|
||||
import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
|
||||
import com.android.settingslib.spaprivileged.settingsprovider.settingsGlobalBooleanFlow
|
||||
import com.android.settingslib.spaprivileged.template.preference.RestrictedPreference
|
||||
|
||||
class DeveloperOptionsController(context: Context, preferenceKey: String) :
|
||||
ComposePreferenceController(context, preferenceKey) {
|
||||
|
||||
override fun getAvailabilityStatus() = AVAILABLE
|
||||
|
||||
private val isDevelopmentSettingsEnabledFlow = context.settingsGlobalBooleanFlow(
|
||||
name = Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
|
||||
defaultValue = Build.IS_ENG,
|
||||
)
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val isDevelopmentSettingsEnabled by isDevelopmentSettingsEnabledFlow
|
||||
.collectAsStateWithLifecycle(initialValue = false)
|
||||
if (isDevelopmentSettingsEnabled) {
|
||||
DeveloperOptionsPreference()
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@Composable
|
||||
fun DeveloperOptionsPreference() {
|
||||
RestrictedPreference(
|
||||
model = object : PreferenceModel {
|
||||
override val title =
|
||||
stringResource(com.android.settingslib.R.string.development_settings_title)
|
||||
override val icon = @Composable {
|
||||
SettingsIcon(ImageVector.vectorResource(R.drawable.ic_settings_development))
|
||||
}
|
||||
override val onClick = {
|
||||
SubSettingLauncher(mContext).apply {
|
||||
setDestination(DevelopmentSettingsDashboardFragment::class.qualifiedName)
|
||||
setSourceMetricsCategory(SettingsEnums.SETTINGS_SYSTEM_CATEGORY)
|
||||
}.launch()
|
||||
}
|
||||
},
|
||||
restrictions = Restrictions(keys = listOf(UserManager.DISALLOW_DEBUGGING_FEATURES)),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user