Centralize the automatic storage manager on check.

Bug: 70893105
Test: Existing tests pass.
Change-Id: I83fa0e1033eb530a02eca230d0dd79495cbcbc9d
This commit is contained in:
Daniel Nishi
2018-01-23 18:28:11 -08:00
parent 956dd9451b
commit da4fa80717
4 changed files with 13 additions and 28 deletions

View File

@@ -23,6 +23,7 @@ import android.text.format.Formatter;
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 @@ public class AutomaticStorageManagerDescriptionPreferenceController
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 @@ public class AutomaticStorageManagerDescriptionPreferenceController
context, lastRunMillis, DateUtils.FORMAT_SHOW_DATE)));
}
}
private boolean isStorageManagerEnabled(ContentResolver cr) {
return Settings.Secure.getInt(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)
!= 0;
}
}

View File

@@ -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 @@ public class AutomaticStorageManagerSettings extends DashboardFragment
@Override
public void onResume() {
super.onResume();
mDaysToRetain.setEnabled(isStorageManagerEnabled());
mDaysToRetain.setEnabled(Utils.isStorageManagerEnabled(getContext()));
}
@Override
@@ -153,12 +153,6 @@ public class AutomaticStorageManagerSettings extends DashboardFragment
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));

View File

@@ -27,6 +27,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
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 @@ public class AutomaticStorageManagerSwitchBarController
}
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);
}