From 116b95666f8031680a4bb66d366c18ae6c5023f3 Mon Sep 17 00:00:00 2001 From: Daniel Nishi Date: Tue, 27 Sep 2016 15:59:42 -0700 Subject: [PATCH] Add a warning message to the ASM toggle. This trigger fires if ASM is not enabled by default for the device and the toggle is only visible if the ASM visible flag is enabled. Bug: 30455784 Change-Id: Id6adf8a75dbd4290f042d743689a75f496efb0c9 --- res/values/strings.xml | 3 ++ .../ActivationWarningFragment.java | 44 +++++++++++++++++++ .../AutomaticStorageManagerSettings.java | 19 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/com/android/settings/deletionhelper/ActivationWarningFragment.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 299ef24847b..606c16692c4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7828,4 +7828,7 @@ Installed apps + + + Your storage is now being managed by the storage manager diff --git a/src/com/android/settings/deletionhelper/ActivationWarningFragment.java b/src/com/android/settings/deletionhelper/ActivationWarningFragment.java new file mode 100644 index 00000000000..f7d46d1c433 --- /dev/null +++ b/src/com/android/settings/deletionhelper/ActivationWarningFragment.java @@ -0,0 +1,44 @@ +/* + * 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.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; +import com.android.settings.R; + +/** + * Fragment to warn the user about activating the storage manager. + */ +public class ActivationWarningFragment extends DialogFragment { + public static final String TAG = "ActivationWarningFragment"; + + public static ActivationWarningFragment newInstance() { + return new ActivationWarningFragment(); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + return new AlertDialog.Builder(getActivity()) + .setMessage(R.string.automatic_storage_manager_activation_warning) + .setPositiveButton(android.R.string.ok, null) + .create(); + } + +} diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java index 20efdda9f45..f9b1a579027 100644 --- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java +++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java @@ -17,11 +17,13 @@ package com.android.settings.deletionhelper; import android.app.Activity; +import android.app.AlertDialog; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; +import android.os.SystemProperties; import android.os.storage.StorageManager; import android.provider.Settings; import android.text.format.DateUtils; @@ -55,6 +57,8 @@ public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment private static final String KEY_DELETION_HELPER = "deletion_helper"; private static final String KEY_FREED = "freed_bytes"; private static final String KEY_STORAGE_MANAGER_SWITCH = "storage_manager_active"; + private static final String STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY = + "ro.storage_manager.enabled"; private DropDownPreference mDaysToRetain; private Preference mFreedBytes; @@ -126,6 +130,10 @@ public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment mDaysToRetain.setEnabled(checked); Settings.Secure.putInt(getContentResolver(), Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, checked ? 1 : 0); + // Only show a warning if enabling. + if (checked) { + maybeShowWarning(); + } break; case KEY_DAYS: Settings.Secure.putInt(getContentResolver(), @@ -164,4 +172,15 @@ public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment } return indices.length - 1; } + + private void maybeShowWarning() { + // If the storage manager is on by default, we can use the normal message. + boolean warningUnneeded = SystemProperties.getBoolean( + STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false); + if (warningUnneeded) { + return; + } + ActivationWarningFragment fragment = ActivationWarningFragment.newInstance(); + fragment.show(getFragmentManager(), ActivationWarningFragment.TAG); + } }