-->
<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/inactive_apps_title">
-
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ settings:searchable="false">
</PreferenceScreen>
android:orderingFromXml="false">
<com.android.settings.deviceinfo.storage.StorageSummaryDonutPreference
android:key="pref_summary"
- android:order="0" />
+ android:order="0"
+ settings:searchable="false"
+ settings:controller="com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController"/>
<com.android.settings.widget.MasterSwitchPreference
android:fragment="com.android.settings.deletionhelper.AutomaticStorageManagerSettings"
android:key="toggle_asm"
--- /dev/null
+<!--
+ ~ Copyright (C) 2019 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:key="storage_dashboard_screen"
+ android:title="@string/storage_settings"
+ android:orderingFromXml="false">
+ <com.android.settings.deviceinfo.storage.StorageSummaryDonutPreference
+ android:key="pref_summary"
+ android:order="0"
+ settings:searchable="false"
+ settings:controller="com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController"/>
+</PreferenceScreen>
\ No newline at end of file
import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
-
import android.annotation.Nullable;
import android.app.ActionBar;
import android.app.Activity;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.profileselector.ProfileFragmentBridge;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settingslib.widget.ActionBarShadowController;
*/
public static Fragment getTargetFragment(Activity activity, String fragmentName, Bundle args) {
Fragment f = null;
- final boolean isWorkOnly = args == null ? false : args.getBoolean(EXTRA_WORK_ONLY);
- final boolean isPersonalOnly = args == null ? false : args.getBoolean(EXTRA_PERSONAL_ONLY);
+ final boolean isPersonal = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.PERSONAL : false;
+ final boolean isWork = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.WORK : false;
if (FeatureFlagUtils.isEnabled(activity, FeatureFlags.PERSONAL_WORK_PROFILE)
&& UserManager.get(activity).getUserProfiles().size() > 1
&& ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName) != null
- && !isWorkOnly && !isPersonalOnly) {
+ && !isWork && !isPersonal) {
f = Fragment.instantiate(activity, ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName),
args);
} else {
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_WHITELIST_ALL;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_RECENT;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WORK;
+import static com.android.settings.search.actionbar.SearchMenuController.MENU_SEARCH;
import android.annotation.Nullable;
import android.annotation.StringRes;
import com.android.settings.applications.appinfo.WriteSettingsDetails;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.fuelgauge.HighPowerDetail;
import com.android.settings.notification.AppNotificationSettings;
import com.android.settings.notification.ConfigureNotificationSettings;
public static final String EXTRA_VOLUME_UUID = "volumeUuid";
public static final String EXTRA_VOLUME_NAME = "volumeName";
public static final String EXTRA_STORAGE_TYPE = "storageType";
- public static final String EXTRA_WORK_ONLY = "workProfileOnly";
public static final String EXTRA_WORK_ID = "workId";
- public static final String EXTRA_PERSONAL_ONLY = "personalOnly";
private static final String EXTRA_SORT_ORDER = "sortOrder";
private static final String EXTRA_SHOW_SYSTEM = "showSystem";
}
final AppFilterRegistry appFilterRegistry = AppFilterRegistry.getInstance();
mFilter = appFilterRegistry.get(appFilterRegistry.getDefaultFilterType(mListType));
- mIsPersonalOnly = args != null ? args.getBoolean(EXTRA_PERSONAL_ONLY) : false;
- mIsWorkOnly = args != null ? args.getBoolean(EXTRA_WORK_ONLY) : false;
+ mIsPersonalOnly = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.PERSONAL : false;
+ mIsWorkOnly = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.WORK : false;
mWorkUserId = args != null ? args.getInt(EXTRA_WORK_ID) : NO_USER_SPECIFIED;
mExpandSearch = activity.getIntent().getBooleanExtra(EXTRA_EXPAND_SEARCH_VIEW, false);
// Hide notification menu items, because sorting happens when filtering
mOptionsMenu.findItem(R.id.sort_order_recent_notification).setVisible(false);
mOptionsMenu.findItem(R.id.sort_order_frequent_notification).setVisible(false);
+ final MenuItem searchItem = mOptionsMenu.findItem(MENU_SEARCH);
+ if (searchItem != null) {
+ searchItem.setVisible(false);
+ }
}
@Override
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.android.settings.R;
-import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.dashboard.DashboardFragment;
import com.google.android.material.tabs.TabLayout;
/**
* Base fragment class for profile settings.
*/
-public abstract class ProfileSelectFragment extends InstrumentedFragment {
+public abstract class ProfileSelectFragment extends DashboardFragment {
+
+ private static final String TAG = "ProfileSelectFragment";
/**
* Denotes the profile type.
*/
public static final int ALL = PERSONAL | WORK;
- private View mContentView;
+ /**
+ * Used in fragment argument and pass {@link ProfileType} to it
+ */
+ public static final String EXTRA_PROFILE = "profile";
+
+ private ViewGroup mContentView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- mContentView = inflater.inflate(R.layout.profile_select_tablayout, null /* root */);
- final ViewPager viewPager = mContentView.findViewById(R.id.view_pager);
- viewPager.setAdapter(new ViewPagerAdapter(this));
- final TabLayout tabs = mContentView.findViewById(R.id.tabs);
+ mContentView = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
+
+ final View tabContainer = mContentView.findViewById(R.id.tab_container);
+ final ViewPager viewPager = tabContainer.findViewById(R.id.view_pager);
+ viewPager.setAdapter(new ProfileSelectFragment.ViewPagerAdapter(this));
+ final TabLayout tabs = tabContainer.findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
+ tabContainer.setVisibility(View.VISIBLE);
+
+ final FrameLayout listContainer = mContentView.findViewById(android.R.id.list_container);
+ listContainer.setLayoutParams(new LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
return mContentView;
}
*/
public abstract Fragment[] getFragments();
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.dummy_preference_screen;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
static class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final Fragment[] mChildFragments;
private final Context mContext;
ViewPagerAdapter(ProfileSelectFragment fragment) {
- super(fragment.getActivity().getSupportFragmentManager());
+ super(fragment.getChildFragmentManager());
mContext = fragment.getContext();
mChildFragments = fragment.getFragments();
}
package com.android.settings.dashboard.profileselector;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
-
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@Override
public Fragment[] getFragments() {
final Bundle workOnly = new Bundle();
- workOnly.putBoolean(EXTRA_WORK_ONLY, true);
+ workOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.WORK);
final Fragment workFragment = new ManageApplications();
workFragment.setArguments(workOnly);
final Bundle personalOnly = new Bundle();
- personalOnly.putBoolean(EXTRA_PERSONAL_ONLY, true);
+ personalOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.PERSONAL);
final Fragment personalFragment = new ManageApplications();
personalFragment.setArguments(personalOnly);
return new Fragment[]{
import androidx.fragment.app.Fragment;
+import com.android.settings.R;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageProfileFragment;
final Bundle storageBundle = new Bundle();
storageBundle.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
+ storageBundle.putInt(EXTRA_PROFILE, ProfileSelectFragment.PERSONAL);
final Fragment storageDashboardFragment = new StorageDashboardFragment();
storageDashboardFragment.setArguments(storageBundle);
break;
}
}
- // TODO(b/143330969): Need to think about more profile users case
if (targetUser != null) {
storageBundle.putInt(StorageProfileFragment.USER_ID_EXTRA, targetUser.id);
}
storageProfileFragment
};
}
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.storage_summary_donut;
+ }
}
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
+import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.deviceinfo.storage.AutomaticStorageManagementSwitchPreferenceController;
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
import com.android.settings.deviceinfo.storage.SecondaryUserController;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
-import com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController;
import com.android.settings.deviceinfo.storage.UserIconLoader;
import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
import com.android.settings.search.BaseSearchIndexProvider;
implements
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
private static final String TAG = "StorageDashboardFrag";
+ private static final String SUMMARY_PREF_KEY = "pref_summary";
private static final int STORAGE_JOB_ID = 0;
private static final int ICON_JOB_ID = 1;
private static final int VOLUME_SIZE_JOB_ID = 2;
private SparseArray<StorageAsyncLoader.AppsStorageResult> mAppsResult;
private CachedStorageValuesHelper mCachedStorageValuesHelper;
- private StorageSummaryDonutPreferenceController mSummaryController;
private StorageItemPreferenceController mPreferenceController;
private PrivateVolumeOptionMenuController mOptionMenuController;
private List<AbstractPreferenceController> mSecondaryUsers;
+ private boolean mPersonalOnly;
@Override
public void onCreate(Bundle icicle) {
final Activity activity = getActivity();
StorageManager sm = activity.getSystemService(StorageManager.class);
mVolume = Utils.maybeInitializeVolume(sm, getArguments());
+ mPersonalOnly = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.PERSONAL;
if (mVolume == null) {
activity.finish();
return;
}
-
initializeOptionsMenu(activity);
+ if (mPersonalOnly) {
+ final Preference summary = getPreferenceScreen().findPreference(SUMMARY_PREF_KEY);
+ if (summary != null) {
+ summary.setVisible(false);
+ }
+ }
}
@Override
null /* header view */)
.setRecyclerView(getListView(), getSettingsLifecycle())
.styleActionBar(activity);
-
}
@Override
boolean stopLoading = false;
if (mStorageInfo != null) {
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
- mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
mPreferenceController.setVolume(mVolume);
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- mSummaryController = new StorageSummaryDonutPreferenceController(context);
- controllers.add(mSummaryController);
StorageManager sm = context.getSystemService(StorageManager.class);
mPreferenceController = new StorageItemPreferenceController(context, this,
final StorageManager sm = context.getSystemService(StorageManager.class);
final UserManager userManager = context.getSystemService(UserManager.class);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new StorageSummaryDonutPreferenceController(context));
controllers.add(new StorageItemPreferenceController(context, null /* host */,
null /* volume */, new StorageManagerVolumeProvider(sm)));
controllers.addAll(SecondaryUserController.getSecondaryUserControllers(
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.deviceinfo.PrivateVolumeSettings.SystemInfoFragment;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.overlay.FeatureFactory;
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.PERSONAL_WORK_PROFILE)) {
- final Bundle args = new Bundle(3 + additionalCapacity);
- args.putBoolean(ManageApplications.EXTRA_WORK_ONLY, mIsWorkProfile);
+ final Bundle args = new Bundle(2 + additionalCapacity);
+ args.putInt(ProfileSelectFragment.EXTRA_PROFILE,
+ mIsWorkProfile ? ProfileSelectFragment.WORK : ProfileSelectFragment.PERSONAL);
args.putInt(ManageApplications.EXTRA_WORK_ID, mUserId);
- args.putBoolean(ManageApplications.EXTRA_PERSONAL_ONLY, !mIsWorkProfile);
return args;
} else {
final Bundle args = new Bundle(2 + additionalCapacity);
- args.putBoolean(ManageApplications.EXTRA_WORK_ONLY, mIsWorkProfile);
+ args.putInt(ProfileSelectFragment.EXTRA_PROFILE,
+ mIsWorkProfile ? ProfileSelectFragment.WORK : ProfileSelectFragment.ALL);
args.putInt(ManageApplications.EXTRA_WORK_ID, mUserId);
return args;
}
package com.android.settings.deviceinfo.storage;
import android.content.Context;
+import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.text.TextUtils;
import android.text.format.Formatter;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.deviceinfo.PrivateStorageInfo;
+import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.text.NumberFormat;
/**
- * StorgaeSummaryPreferenceController updates the donut storage summary preference to have the
+ * SummaryPreferenceController updates the donut storage summary preference to have the
* correct sizes showing.
*/
-public class StorageSummaryDonutPreferenceController extends AbstractPreferenceController implements
- PreferenceControllerMixin {
+public class StorageSummaryDonutPreferenceController extends BasePreferenceController {
private long mUsedBytes;
private long mTotalBytes;
private StorageSummaryDonutPreference mSummary;
+ private final StorageManager mStorageManager;
+ private final StorageManagerVolumeProvider mStorageManagerVolumeProvider;
- public StorageSummaryDonutPreferenceController(Context context) {
- super(context);
+ public StorageSummaryDonutPreferenceController(Context context, String key) {
+ super(context, key);
+ mStorageManager = mContext.getSystemService(StorageManager.class);
+ mStorageManagerVolumeProvider = new StorageManagerVolumeProvider(mStorageManager);
}
/**
@Override
public void displayPreference(PreferenceScreen screen) {
- mSummary = screen.findPreference("pref_summary");
+ mSummary = screen.findPreference(getPreferenceKey());
mSummary.setEnabled(true);
+
+ ThreadUtils.postOnBackgroundThread(() -> {
+ final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
+ final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
+ mStorageManagerVolumeProvider);
+ final double privateUsedBytes = info.totalBytes - info.freeBytes;
+ mTotalBytes = info.totalBytes;
+ mUsedBytes = info.totalBytes - info.freeBytes;
+
+ ThreadUtils.postOnMainThread(() -> {
+ updateState(mSummary);
+ });
+ });
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- StorageSummaryDonutPreference summary = (StorageSummaryDonutPreference) preference;
- summary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
- summary.setSummary(mContext.getString(R.string.storage_volume_total,
+ mSummary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
+ mSummary.setSummary(mContext.getString(R.string.storage_volume_total,
Formatter.formatShortFileSize(mContext, mTotalBytes)));
- summary.setPercent(mUsedBytes, mTotalBytes);
- summary.setEnabled(true);
+ mSummary.setPercent(mUsedBytes, mTotalBytes);
+ mSummary.setEnabled(true);
}
/** Invalidates the data on the view and re-renders. */
}
@Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return "pref_summary";
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
}
/**
super.onCreate(icicle);
mUsageStats = getActivity().getSystemService(UsageStatsManager.class);
- addPreferencesFromResource(R.xml.inactive_apps);
+ addPreferencesFromResource(R.xml.dummy_preference_screen);
+ getActivity().setTitle(R.string.inactive_apps_title);
}
@Override
public class SearchMenuController implements LifecycleObserver, OnCreateOptionsMenu {
public static final String NEED_SEARCH_ICON_IN_ACTION_BAR = "need_search_icon_in_action_bar";
+ public static final int MENU_SEARCH = Menu.FIRST + 10;
private final Fragment mHost;
private final int mPageId;
if (arguments != null && !arguments.getBoolean(NEED_SEARCH_ICON_IN_ACTION_BAR, true)) {
return;
}
- final MenuItem searchItem = menu.add(Menu.NONE, Menu.NONE, 0 /* order */,
+ // menu contains search item, skip it
+ if (menu.findItem(MENU_SEARCH) != null) {
+ return;
+ }
+ final MenuItem searchItem = menu.add(Menu.NONE, MENU_SEARCH, 0 /* order */,
R.string.search_menu);
searchItem.setIcon(R.drawable.ic_search_24dp);
searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
package com.android.settings.deviceinfo.storage;
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ID;
-import static com.android.settings.applications.manageapplications.ManageApplications
- .EXTRA_WORK_ONLY;
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.applications.manageapplications.ManageApplications;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.deviceinfo.PrivateVolumeSettings;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.testutils.FakeFeatureFactory;
.isEqualTo(R.string.apps_storage);
assertThat(
intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
- .getBoolean(EXTRA_WORK_ONLY))
- .isTrue();
+ .getInt(ProfileSelectFragment.EXTRA_PROFILE))
+ .isEqualTo(ProfileSelectFragment.WORK);
assertThat(
intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
.getInt(EXTRA_WORK_ID))
import android.widget.Button;
import android.widget.LinearLayout;
+import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.ShadowPrivateStorageInfo;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
import java.io.File;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowPrivateStorageInfo.class)
public class StorageSummaryDonutPreferenceControllerTest {
private Context mContext;
private PreferenceViewHolder mHolder;
private FakeFeatureFactory mFakeFeatureFactory;
private MetricsFeatureProvider mMetricsFeatureProvider;
+ private PreferenceScreen mScreen;
@Before
public void setUp() throws Exception {
+ ShadowPrivateStorageInfo.setPrivateStorageInfo(new PrivateStorageInfo(10L, 100L));
mContext = spy(Robolectric.setupActivity(Activity.class));
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
- mController = new StorageSummaryDonutPreferenceController(mContext);
+ mController = new StorageSummaryDonutPreferenceController(mContext, "key");
mPreference = new StorageSummaryDonutPreference(mContext);
+ mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.findPreference("key")).thenReturn(mPreference);
LayoutInflater inflater = LayoutInflater.from(mContext);
final View view =
mHolder = PreferenceViewHolder.createInstanceForTests(view);
}
+ @After
+ public void tearDown() {
+ ShadowPrivateStorageInfo.reset();
+ }
+
@Test
public void testEmpty() {
final long totalSpace = 32 * GIGABYTE;
final long usedSpace = 0;
+ mController.displayPreference(mScreen);
mController.updateBytes(0, 32 * GIGABYTE);
mController.updateState(mPreference);
public void testTotalStorage() {
final long totalSpace = KILOBYTE * 10;
final long usedSpace = KILOBYTE;
+ mController.displayPreference(mScreen);
mController.updateBytes(KILOBYTE, totalSpace);
mController.updateState(mPreference);
when(file.getTotalSpace()).thenReturn(totalSpace);
when(file.getFreeSpace()).thenReturn(freeSpace);
when(svp.getPrimaryStorageSize()).thenReturn(totalSpace);
+ mController.displayPreference(mScreen);
mController.updateSizes(svp, volume);
mController.updateState(mPreference);
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
+import com.android.settings.testutils.shadow.ShadowPrivateStorageInfo;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
-import com.android.settingslib.deviceinfo.StorageVolumeProvider;
import org.junit.After;
import org.junit.Before;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-import org.robolectric.annotation.Resetter;
@RunWith(RobolectricTestRunner.class)
public class LowStorageSliceTest {
assertThat(slice.hasHint(HINT_ERROR)).isTrue();
}
-
- @Implements(PrivateStorageInfo.class)
- public static class ShadowPrivateStorageInfo {
-
- private static PrivateStorageInfo sPrivateStorageInfo = null;
-
- @Resetter
- public static void reset() {
- sPrivateStorageInfo = null;
- }
-
- @Implementation
- public static PrivateStorageInfo getPrivateStorageInfo(
- StorageVolumeProvider storageVolumeProvider) {
- return sPrivateStorageInfo;
- }
-
- private static void setPrivateStorageInfo(
- PrivateStorageInfo privateStorageInfo) {
- sPrivateStorageInfo = privateStorageInfo;
- }
- }
}
\ No newline at end of file
package com.android.settings.search.actionbar;
+import static com.android.settings.search.actionbar.SearchMenuController.MENU_SEARCH;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
Global.putInt(mActivity.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
when(mHost.getActivity()).thenReturn(mActivity);
- when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
+ when(mMenu.add(Menu.NONE, MENU_SEARCH, 0 /* order */, R.string.search_menu))
.thenReturn(mock(MenuItem.class));
}
SearchMenuController.init(mHost);
mHost.getSettingsLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
- verify(mMenu).add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu);
+ verify(mMenu).add(Menu.NONE, MENU_SEARCH, 0 /* order */, R.string.search_menu);
}
@Test
--- /dev/null
+/*
+ * Copyright (C) 2019 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.testutils.shadow;
+
+import com.android.settingslib.deviceinfo.PrivateStorageInfo;
+import com.android.settingslib.deviceinfo.StorageVolumeProvider;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.Resetter;
+
+@Implements(PrivateStorageInfo.class)
+public class ShadowPrivateStorageInfo {
+
+ private static PrivateStorageInfo sPrivateStorageInfo = null;
+
+ @Resetter
+ public static void reset() {
+ sPrivateStorageInfo = null;
+ }
+
+ @Implementation
+ protected static PrivateStorageInfo getPrivateStorageInfo(
+ StorageVolumeProvider storageVolumeProvider) {
+ return sPrivateStorageInfo;
+ }
+
+ public static void setPrivateStorageInfo(
+ PrivateStorageInfo privateStorageInfo) {
+ sPrivateStorageInfo = privateStorageInfo;
+ }
+}