Add the automatic storage manager settings.

This provides a toggle for changing if the storage manager
is turned on or off and how many days of data to retain.

It is currently not hooked up to anything currently and only acts as
the view, pending b/28600825.

Bug: 28560570
Change-Id: Iaa2d819f26addab4dc02ced80e9ba79e0fcf0980
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 8adf331..6827e5b 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1031,4 +1031,18 @@
         <item>Red</item>
     </string-array>
 
+    <!-- Automatic storage management settings. The amount of days for the automatic storage manager
+         to retain. These are shown in a list dialog. [CHAR LIMIT=70] -->
+    <string-array name="automatic_storage_management_days">
+        <item>Over 30 days old</item>
+        <item>Over 60 days old</item>
+        <item>Over 90 days old</item>
+    </string-array>
+
+    <string-array name="automatic_storage_management_days_values" translatable="false">
+        <item>30</item>
+        <item>60</item>
+        <item>90</item>
+    </string-array>
+
 </resources>
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 5ee0f7c..6f04457 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -40,4 +40,7 @@
 
     <!-- Whether none security option is hide or not  (country specific). -->
     <bool name="config_hide_none_security_option">false</bool>
+
+    <!--Whether the storage manager exists. -->
+    <bool name="config_has_storage_manager">false</bool>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 76f573f..be82934 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7604,4 +7604,13 @@
     <!-- Button label for the dialog prompt for clearing data in deletion helper. [CHAR LIMIT=40] -->
     <string name="deletion_helper_clear_dialog_remove">Remove</string>
 
+    <!-- Used as title on the automatic storage manager settings. [CHAR LIMIT=60] -->
+    <string name="automatic_storage_manager_settings">Storage manager</string>
+
+    <!-- Used as wall of text to describe the feature. [CHAR LIMIT=NONE] -->
+    <string name="automatic_storage_manager_text">To help free up storage space, storage manager removes backed up photos and videos from your device.</string>
+
+    <!-- Dropdown preference title for dropdown describing how many days of data to retain.-->
+    <string name="automatic_storage_manager_days_title">Remove photos &amp; videos</string>
+
 </resources>
diff --git a/res/xml/automatic_storage_management_settings.xml b/res/xml/automatic_storage_management_settings.xml
new file mode 100644
index 0000000..78606fb
--- /dev/null
+++ b/res/xml/automatic_storage_management_settings.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:settings="http://schemas.android.com/apk/res-auto"
+        android:title="@string/automatic_storage_manager_settings" >
+
+    <DropDownPreference
+        android:key="days"
+        android:summary="%s"
+        android:title="@string/automatic_storage_manager_days_title"
+        android:entries="@array/automatic_storage_management_days"
+        android:entryValues="@array/automatic_storage_management_days_values"/>
+
+    <com.android.settings.fuelgauge.WallOfTextPreference
+        android:key="disclaimer"
+        android:summary="@string/automatic_storage_manager_text"
+        android:persistent="false"
+        android:selectable="false"
+        settings:allowDividerAbove="true" />
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
new file mode 100644
index 0000000..1112eb1
--- /dev/null
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -0,0 +1,99 @@
+/**
+ * Copyright (C) 2016 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.deletionhelper;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Switch;
+import android.support.v7.preference.DropDownPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.logging.MetricsProto.MetricsEvent;
+import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.R;
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SwitchBar.OnSwitchChangeListener;
+
+/**
+ * AutomaticStorageManagerSettings is the Settings screen for configuration and management of the
+ * automatic storage manager.
+ */
+public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment implements
+        OnSwitchChangeListener, OnPreferenceChangeListener {
+    private static final String KEY_DAYS = "days";
+
+    private SwitchBar mSwitchBar;
+    private DropDownPreference mDaysToRetain;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.automatic_storage_management_settings);
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        Activity activity = getActivity();
+        mSwitchBar = ((SettingsActivity) activity).getSwitchBar();
+        mSwitchBar.show();
+        mSwitchBar.addOnSwitchChangeListener(this);
+        // TODO: Initialize the switch bar position based on if the storage manager is active.
+
+        mDaysToRetain = (DropDownPreference) findPreference(KEY_DAYS);
+        mDaysToRetain.setOnPreferenceChangeListener(this);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        // TODO: Initialize the switch bar position based on if the storage manager is active.
+        maybeShowDayDropdown(mSwitchBar.isChecked());
+    }
+
+    @Override
+    public void onSwitchChanged(Switch switchView, boolean isChecked) {
+        // TODO: Flip a setting which controls if the storage manager should run.
+        maybeShowDayDropdown(isChecked);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        // TODO: Configure a setting which controls how many days of data the storage manager
+        // should retain.
+        return true;
+    }
+
+    @Override
+    protected int getMetricsCategory() {
+        return MetricsEvent.STORAGE_MANAGER_SETTINGS;
+    }
+
+    private void maybeShowDayDropdown(boolean shouldShow) {
+        PreferenceScreen screen = getPreferenceScreen();
+        if (shouldShow) {
+            screen.addPreference(mDaysToRetain);
+        } else {
+            screen.removePreference(mDaysToRetain);
+        }
+    }
+}
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index 442c8e3..d5cc276 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -59,6 +59,7 @@
 import com.android.settings.Utils;
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.deletionhelper.DeletionHelperFragment;
+import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
 import com.android.settings.deviceinfo.StorageSettings.MountTask;
 import com.android.settingslib.deviceinfo.StorageMeasurement;
 import com.android.settingslib.deviceinfo.StorageMeasurement.MeasurementDetails;
@@ -117,6 +118,7 @@
     private int mItemPoolIndex;
 
     private Preference mExplore;
+    private Preference mAutomaticStorageManagement;
 
     private boolean mNeedsUpdate;
 
@@ -164,6 +166,7 @@
         mCurrentUser = mUserManager.getUserInfo(UserHandle.myUserId());
 
         mExplore = buildAction(R.string.storage_menu_explore);
+        mAutomaticStorageManagement = buildAction(R.string.storage_settings);
 
         mNeedsUpdate = true;
 
@@ -190,6 +193,9 @@
 
         screen.removeAll();
 
+        if (getResources().getBoolean(R.bool.config_has_storage_manager)) {
+            addPreference(screen, mAutomaticStorageManagement);
+        }
         addPreference(screen, mSummary);
 
         List<UserInfo> allUsers = mUserManager.getUsers();
@@ -475,6 +481,11 @@
             case R.string.storage_menu_explore: {
                 intent = mSharedVolume.buildBrowseIntent();
             } break;
+            case R.string.storage_settings: {
+                startFragment(this, AutomaticStorageManagerSettings.class.getCanonicalName(),
+                        R.string.automatic_storage_manager_settings, 0, null);
+                return true;
+            }
             case 0: {
                 UserInfoFragment.show(this, pref.getTitle(), pref.getSummary());
                 return true;