Use Settings.Secure for days to retain.

Previously, we used Shared Preferences, which worked when the
storage manager was localized to Settings. Now that it is in
its own separate APK, we need to use a separate setting to configure
it.

Bug: 28965462
Change-Id: I073859ef1a764679bbc63d3c0cd96af82306212e
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index 6163576..670eed1 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -18,7 +18,6 @@
 
 import android.app.Activity;
 import android.content.Context;
-import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.provider.Settings;
@@ -46,11 +45,9 @@
         OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
     public static final int DEFAULT_DAYS_TO_RETAIN = 90;
 
-    private static final String SHARED_PREFRENCES_NAME = "automatic_storage_manager_settings";
     private static final String KEY_DAYS = "days";
     private static final String KEY_DELETION_HELPER = "deletion_helper";
     private static final String KEY_STORAGE_MANAGER_SWITCH = "storage_manager_active";
-    private static final String KEY_DAYS_TO_RETAIN = "days_to_retain";
 
     private DropDownPreference mDaysToRetain;
     private Preference mDeletionHelper;
@@ -72,16 +69,11 @@
         mDeletionHelper.setOnPreferenceClickListener(this);
 
         mStorageManagerSwitch = (SwitchPreference) findPreference(KEY_STORAGE_MANAGER_SWITCH);
-        boolean isChecked =
-                Settings.Secure.getInt(getContentResolver(),
-                        Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
-        mStorageManagerSwitch.setChecked(isChecked);
         mStorageManagerSwitch.setOnPreferenceChangeListener(this);
 
-        SharedPreferences sharedPreferences =
-                getContext().getSharedPreferences(SHARED_PREFRENCES_NAME,
-                        Context.MODE_PRIVATE);
-        int value = sharedPreferences.getInt(KEY_DAYS_TO_RETAIN, DEFAULT_DAYS_TO_RETAIN);
+        int value = Settings.Secure.getInt(getContentResolver(),
+                Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN,
+                Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN_DEFAULT);
         String[] stringValues =
                 getResources().getStringArray(R.array.automatic_storage_management_days_values);
         mDaysToRetain.setValue(stringValues[daysValueToIndex(value, stringValues)]);
@@ -90,7 +82,11 @@
     @Override
     public void onResume() {
         super.onResume();
-        mDaysToRetain.setEnabled(mStorageManagerSwitch.isChecked());
+        boolean isChecked =
+                Settings.Secure.getInt(getContentResolver(),
+                        Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
+        mStorageManagerSwitch.setChecked(isChecked);
+        mDaysToRetain.setEnabled(isChecked);
     }
 
     @Override
@@ -103,11 +99,9 @@
                         Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, checked ? 1 : 0);
                 break;
             case KEY_DAYS:
-                SharedPreferences.Editor editor =
-                        getContext().getSharedPreferences(SHARED_PREFRENCES_NAME,
-                                Context.MODE_PRIVATE).edit();
-                editor.putInt(KEY_DAYS_TO_RETAIN, Integer.parseInt((String) newValue));
-                editor.apply();
+                Settings.Secure.putInt(getContentResolver(),
+                        Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN,
+                        Integer.parseInt((String) newValue));
                 break;
         }
         return true;