Merge "Re-add the block of text explaining the feature." into oc-mr1-dev am: 3315f38c3f
am: df0e716b43
Change-Id: Ibe767b5bd21ed75ea188a1a6561aa974edd2b449
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* <p>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
|
||||||
|
*
|
||||||
|
* <p>http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* <p>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.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
|
import android.text.format.Formatter;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the wall of text which appears below the options in the Storage Management settings drill
|
||||||
|
* down.
|
||||||
|
*/
|
||||||
|
public class AutomaticStorageManagerDescriptionPreferenceController
|
||||||
|
extends AbstractPreferenceController implements PreferenceControllerMixin {
|
||||||
|
private static final String KEY_FREED = "freed_bytes";
|
||||||
|
|
||||||
|
public AutomaticStorageManagerDescriptionPreferenceController(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_FREED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
Preference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
final Context context = preference.getContext();
|
||||||
|
ContentResolver cr = context.getContentResolver();
|
||||||
|
long freedBytes =
|
||||||
|
Settings.Secure.getLong(
|
||||||
|
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)) {
|
||||||
|
preference.setSummary(R.string.automatic_storage_manager_text);
|
||||||
|
} else {
|
||||||
|
preference.setSummary(
|
||||||
|
context.getString(
|
||||||
|
R.string.automatic_storage_manager_freed_bytes,
|
||||||
|
Formatter.formatFileSize(context, freedBytes),
|
||||||
|
DateUtils.formatDateTime(
|
||||||
|
context, lastRunMillis, DateUtils.FORMAT_SHOW_DATE)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStorageManagerEnabled(ContentResolver cr) {
|
||||||
|
return Settings.Secure.getInt(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)
|
||||||
|
!= 0;
|
||||||
|
}
|
||||||
|
}
|
@@ -16,15 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings.deletionhelper;
|
package com.android.settings.deletionhelper;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.DropDownPreference;
|
import android.support.v7.preference.DropDownPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.text.format.Formatter;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -32,39 +30,34 @@ import android.view.ViewGroup;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AutomaticStorageManagerSettings is the Settings screen for configuration and management of the
|
* AutomaticStorageManagerSettings is the Settings screen for configuration and management of the
|
||||||
* automatic storage manager.
|
* automatic storage manager.
|
||||||
*/
|
*/
|
||||||
public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment
|
public class AutomaticStorageManagerSettings extends DashboardFragment
|
||||||
implements OnPreferenceChangeListener {
|
implements OnPreferenceChangeListener {
|
||||||
private static final String KEY_DAYS = "days";
|
private static final String KEY_DAYS = "days";
|
||||||
private static final String KEY_FREED = "freed_bytes";
|
|
||||||
private static final String STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY =
|
|
||||||
"ro.storage_manager.enabled";
|
|
||||||
|
|
||||||
private AutomaticStorageManagerSwitchBarController mSwitchController;
|
private AutomaticStorageManagerSwitchBarController mSwitchController;
|
||||||
private DropDownPreference mDaysToRetain;
|
private DropDownPreference mDaysToRetain;
|
||||||
private Preference mFreedBytes;
|
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
addPreferencesFromResource(R.xml.automatic_storage_management_settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(
|
public View onCreateView(
|
||||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
|
||||||
initializeDaysToRetainPreference();
|
initializeDaysToRetainPreference();
|
||||||
initializeFreedBytesPreference();
|
|
||||||
initializeSwitchBar();
|
initializeSwitchBar();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
@@ -98,35 +91,25 @@ public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment
|
|||||||
getFragmentManager());
|
getFragmentManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeFreedBytesPreference() {
|
|
||||||
ContentResolver cr = getContentResolver();
|
|
||||||
mFreedBytes = findPreference(KEY_FREED);
|
|
||||||
long freedBytes = Settings.Secure.getLong(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) {
|
|
||||||
mFreedBytes.setVisible(false);
|
|
||||||
} else {
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
mFreedBytes.setSummary(
|
|
||||||
activity.getString(
|
|
||||||
R.string.automatic_storage_manager_freed_bytes,
|
|
||||||
Formatter.formatFileSize(activity, freedBytes),
|
|
||||||
DateUtils.formatDateTime(
|
|
||||||
activity, lastRunMillis, DateUtils.FORMAT_SHOW_DATE)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
boolean isStorageManagerChecked =
|
mDaysToRetain.setEnabled(isStorageManagerEnabled());
|
||||||
Settings.Secure.getInt(getContentResolver(),
|
}
|
||||||
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
|
|
||||||
mDaysToRetain.setEnabled(isStorageManagerChecked);
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.automatic_storage_management_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,4 +151,30 @@ public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment
|
|||||||
return indices.length - 1;
|
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));
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** For Search. */
|
||||||
|
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider() {
|
||||||
|
@Override
|
||||||
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AbstractPreferenceController> getPreferenceControllers(
|
||||||
|
Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,7 @@ import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
|||||||
import com.android.settings.datausage.DataPlanUsageSummary;
|
import com.android.settings.datausage.DataPlanUsageSummary;
|
||||||
import com.android.settings.datausage.DataUsageMeteredSettings;
|
import com.android.settings.datausage.DataUsageMeteredSettings;
|
||||||
import com.android.settings.datausage.DataUsageSummary;
|
import com.android.settings.datausage.DataUsageSummary;
|
||||||
|
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
|
||||||
import com.android.settings.development.DevelopmentSettings;
|
import com.android.settings.development.DevelopmentSettings;
|
||||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||||
import com.android.settings.deviceinfo.StorageSettings;
|
import com.android.settings.deviceinfo.StorageSettings;
|
||||||
@@ -213,6 +214,10 @@ public final class SearchIndexableResources {
|
|||||||
R.drawable.ic_settings_notifications);
|
R.drawable.ic_settings_notifications);
|
||||||
addIndex(DreamSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
|
addIndex(DreamSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
|
||||||
addIndex(SupportDashboardActivity.class, NO_DATA_RES_ID, R.drawable.ic_help);
|
addIndex(SupportDashboardActivity.class, NO_DATA_RES_ID, R.drawable.ic_help);
|
||||||
|
addIndex(
|
||||||
|
AutomaticStorageManagerSettings.class,
|
||||||
|
NO_DATA_RES_ID,
|
||||||
|
R.drawable.ic_settings_storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchIndexableResources() {
|
private SearchIndexableResources() {
|
||||||
|
@@ -64,7 +64,6 @@ com.android.settings.notification.AppNotificationSettings
|
|||||||
com.android.settings.deviceinfo.PrivateVolumeSettings
|
com.android.settings.deviceinfo.PrivateVolumeSettings
|
||||||
com.android.settings.users.AppRestrictionsFragment
|
com.android.settings.users.AppRestrictionsFragment
|
||||||
com.android.settings.deviceinfo.PrivateVolumeUnmount
|
com.android.settings.deviceinfo.PrivateVolumeUnmount
|
||||||
com.android.settings.deletionhelper.AutomaticStorageManagerSettings
|
|
||||||
com.android.settings.notification.ZenAccessSettings
|
com.android.settings.notification.ZenAccessSettings
|
||||||
com.android.settings.accessibility.ToggleFontSizePreferenceFragment
|
com.android.settings.accessibility.ToggleFontSizePreferenceFragment
|
||||||
com.android.settings.applications.PremiumSmsAccess
|
com.android.settings.applications.PremiumSmsAccess
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
package com.android.settings.deletionhelper;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class AutomaticStorageManagerDescriptionPreferenceControllerTest {
|
||||||
|
@Mock private PreferenceScreen mScreen;
|
||||||
|
@Mock private Preference mPreference;
|
||||||
|
private AutomaticStorageManagerDescriptionPreferenceController mController;
|
||||||
|
private Context mContext = RuntimeEnvironment.application;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mController = new AutomaticStorageManagerDescriptionPreferenceController(mContext);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||||
|
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
when(mPreference.getContext()).thenReturn(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_asmDisabled_shouldHaveDescription() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mPreference).setSummary(eq(R.string.automatic_storage_manager_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_asmEnabledButUnused_shouldHaveDescription() {
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
|
||||||
|
1);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mPreference).setSummary(eq(R.string.automatic_storage_manager_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore("Robolectric doesn't do locale switching for date localization -- yet.")
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "en")
|
||||||
|
public void displayPreference_asmEnabledAndUsed_shouldHaveDescriptionFilledOut() {
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
|
||||||
|
1);
|
||||||
|
Settings.Secure.putLong(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED,
|
||||||
|
10);
|
||||||
|
Settings.Secure.putLong(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN,
|
||||||
|
43200000); // January 1, 1970 12:00:00 PM to avoid timezone issues.
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mPreference)
|
||||||
|
.setSummary(eq("10.00B total made available\n\nLast ran on January 1, 1970"));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user