Merge "Centralize the automatic storage manager on check."
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java
index 261f66c..23fc35b 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java
@@ -23,6 +23,7 @@
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
/**
@@ -57,7 +58,7 @@
cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED, 0);
long lastRunMillis =
Settings.Secure.getLong(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN, 0);
- if (freedBytes == 0 || lastRunMillis == 0 || !isStorageManagerEnabled(cr)) {
+ if (freedBytes == 0 || lastRunMillis == 0 || !Utils.isStorageManagerEnabled(context)) {
preference.setSummary(R.string.automatic_storage_manager_text);
} else {
preference.setSummary(
@@ -68,9 +69,4 @@
context, lastRunMillis, DateUtils.FORMAT_SHOW_DATE)));
}
}
-
- private boolean isStorageManagerEnabled(ContentResolver cr) {
- return Settings.Secure.getInt(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)
- != 0;
- }
}
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index 184c0c5..22ecb09 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -96,7 +96,7 @@
@Override
public void onResume() {
super.onResume();
- mDaysToRetain.setEnabled(isStorageManagerEnabled());
+ mDaysToRetain.setEnabled(Utils.isStorageManagerEnabled(getContext()));
}
@Override
@@ -153,12 +153,6 @@
return indices.length - 1;
}
- private boolean isStorageManagerEnabled() {
- return Settings.Secure.getInt(
- getContentResolver(), Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)
- != 0;
- }
-
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new AutomaticStorageManagerDescriptionPreferenceController(context));
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
index a20afa1..c02fb10 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
@@ -27,6 +27,7 @@
import com.android.internal.util.Preconditions;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.Utils;
/** Handles the logic for flipping the storage management toggle on a {@link SwitchBar}. */
public class AutomaticStorageManagerSwitchBarController
@@ -56,13 +57,7 @@
}
private void initializeCheckedStatus() {
- boolean isStorageManagerChecked =
- Settings.Secure.getInt(
- mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
- 0)
- != 0;
- mSwitchBar.setChecked(isStorageManagerChecked);
+ mSwitchBar.setChecked(Utils.isStorageManagerEnabled(mContext));
mSwitchBar.addOnSwitchChangeListener(this);
}
diff --git a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
index 8ab21b3..7724b00 100644
--- a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -23,12 +23,14 @@
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.PreferenceScreen;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.deletionhelper.ActivationWarningFragment;
import com.android.settings.widget.MasterSwitchController;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.SwitchWidgetController;
+import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -74,9 +76,7 @@
if (!isAvailable()) {
return;
}
- boolean isStorageManagerEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
- mSwitch.setChecked(isStorageManagerEnabled);
+ mSwitch.setChecked(Utils.isStorageManagerEnabled(mContext));
if (mSwitch != null) {
mSwitchController = new MasterSwitchController(mSwitch);
@@ -97,9 +97,9 @@
SystemProperties.getBoolean(STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false);
final boolean storageManagerDisabledByPolicy =
Settings.Secure.getInt(
- mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY,
- 0)
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY,
+ 0)
!= 0;
// Show warning if it is disabled by default and turning it on or if it was disabled by
// policy and we're turning it on.