Restore state when activity is destroyed
- Fixes a bug where developer options would be re-enabled if the activity is destroyed when the master switch is set to off Bug: 34203528 Test: Manual testing with screen rotation Change-Id: Ic8e04858f6e3dd2353feb6fa94be9f420ab8adbb
This commit is contained in:
@@ -154,6 +154,13 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
mSwitchBarController = new DevelopmentSwitchBarController(
|
mSwitchBarController = new DevelopmentSwitchBarController(
|
||||||
this /* DevelopmentSettings */, mSwitchBar, mIsAvailable, getLifecycle());
|
this /* DevelopmentSettings */, mSwitchBar, mIsAvailable, getLifecycle());
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
|
|
||||||
|
// Restore UI state based on whether developer options is enabled
|
||||||
|
if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
|
||||||
|
enableDeveloperOptions();
|
||||||
|
} else {
|
||||||
|
disableDeveloperOptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -197,17 +204,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
EnableDevelopmentSettingWarningDialog.show(this /* host */);
|
EnableDevelopmentSettingWarningDialog.show(this /* host */);
|
||||||
} else {
|
} else {
|
||||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
|
disableDeveloperOptions();
|
||||||
final SystemPropPoker poker = SystemPropPoker.getInstance();
|
|
||||||
poker.blockPokes();
|
|
||||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
|
||||||
if (controller instanceof DeveloperOptionsPreferenceController) {
|
|
||||||
((DeveloperOptionsPreferenceController) controller)
|
|
||||||
.onDeveloperOptionsDisabled();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
poker.unblockPokes();
|
|
||||||
poker.poke();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,7 +315,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
getActivity().unregisterReceiver(mBluetoothA2dpReceiver);
|
getActivity().unregisterReceiver(mBluetoothA2dpReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onEnableDevelopmentOptionsConfirmed() {
|
private void enableDeveloperOptions() {
|
||||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
|
||||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||||
if (controller instanceof DeveloperOptionsPreferenceController) {
|
if (controller instanceof DeveloperOptionsPreferenceController) {
|
||||||
@@ -327,6 +324,24 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableDeveloperOptions() {
|
||||||
|
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
|
||||||
|
final SystemPropPoker poker = SystemPropPoker.getInstance();
|
||||||
|
poker.blockPokes();
|
||||||
|
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||||
|
if (controller instanceof DeveloperOptionsPreferenceController) {
|
||||||
|
((DeveloperOptionsPreferenceController) controller)
|
||||||
|
.onDeveloperOptionsDisabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
poker.unblockPokes();
|
||||||
|
poker.poke();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onEnableDevelopmentOptionsConfirmed() {
|
||||||
|
enableDeveloperOptions();
|
||||||
|
}
|
||||||
|
|
||||||
void onEnableDevelopmentOptionsRejected() {
|
void onEnableDevelopmentOptionsRejected() {
|
||||||
// Reset the toggle
|
// Reset the toggle
|
||||||
mSwitchBar.setChecked(false);
|
mSwitchBar.setChecked(false);
|
||||||
|
Reference in New Issue
Block a user