Implements profile selection tab in Storage Settings
- StorageDashboardFragment and StorageItemPreferenceController works only
for one profile per instance.
- StorageAsyncLoader loads for all users(profiles) and regards each user independent.
- SecondaryUserController will not load personal profile user in work profile tab.
- Cleanup some unused profile related files.
Bug: 174964885
Test: atest com.android.settings.deviceinfo
atest com.android.settings.deviceinfo.storage
make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo
make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo.storage
Change-Id: I8361c29bc240c519c7261b19522c41439479c1c2
Merged-In: I8361c29bc240c519c7261b19522c41439479c1c2
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index fd67aa8..7614070 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -469,6 +469,19 @@
return UserHandle.USER_NULL;
}
+ /** Returns user ID of current user, throws IllegalStateException if it's not available. */
+ public static int getCurrentUserId(UserManager userManager, boolean isWorkProfile)
+ throws IllegalStateException {
+ if (isWorkProfile) {
+ final UserHandle managedUserHandle = getManagedProfile(userManager);
+ if (managedUserHandle == null) {
+ throw new IllegalStateException("Work profile user ID is not available.");
+ }
+ return managedUserHandle.getIdentifier();
+ }
+ return UserHandle.myUserId();
+ }
+
/**
* Returns the target user for a Settings activity.
* <p>
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
index c324aca..704d00b 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileFragmentBridge.java
@@ -20,6 +20,7 @@
import com.android.settings.accounts.AccountDashboardFragment;
import com.android.settings.applications.manageapplications.ManageApplications;
+import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.location.LocationServices;
import com.android.settings.location.RecentLocationAccessSeeAllFragment;
@@ -46,5 +47,7 @@
ProfileSelectRecentLocationAccessFragment.class.getName());
FRAGMENT_MAP.put(LocationServices.class.getName(),
ProfileSelectLocationServicesFragment.class.getName());
+ FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
+ ProfileSelectStorageFragment.class.getName());
}
}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
new file mode 100644
index 0000000..9e505e3
--- /dev/null
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 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.dashboard.profileselector;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.deviceinfo.StorageDashboardFragment;
+
+/**
+ * Storage Settings page for personal/managed profile.
+ */
+public class ProfileSelectStorageFragment extends ProfileSelectFragment {
+
+ @Override
+ public Fragment[] getFragments() {
+ final Bundle workBundle = new Bundle();
+ workBundle.putInt(EXTRA_PROFILE, ProfileType.WORK);
+ final Fragment workFragment = new StorageDashboardFragment();
+ workFragment.setArguments(workBundle);
+
+ final Bundle personalBundle = new Bundle();
+ personalBundle.putInt(EXTRA_PROFILE, ProfileType.PERSONAL);
+ final Fragment personalFragment = new StorageDashboardFragment();
+ personalFragment.setArguments(personalBundle);
+
+ return new Fragment[] {
+ personalFragment,
+ workFragment
+ };
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index e7f5ba6..6a3bb51 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -85,6 +85,7 @@
private static final int VOLUME_SIZE_JOB_ID = 2;
private StorageManager mStorageManager;
+ private UserManager mUserManager;
private final List<StorageEntry> mStorageEntries = new ArrayList<>();
private StorageEntry mSelectedStorageEntry;
private PrivateStorageInfo mStorageInfo;
@@ -96,7 +97,8 @@
private StorageSelectionPreferenceController mStorageSelectionController;
private StorageUsageProgressBarPreferenceController mStorageUsageProgressBarController;
private List<AbstractPreferenceController> mSecondaryUsers;
- private boolean mPersonalOnly;
+ private boolean mIsWorkProfile;
+ private int mUserId;
private Preference mFreeUpSpacePreference;
private final StorageEventListener mStorageEventListener = new StorageEventListener() {
@@ -270,8 +272,6 @@
final Activity activity = getActivity();
mStorageManager = activity.getSystemService(StorageManager.class);
- mPersonalOnly = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE)
- == ProfileSelectFragment.ProfileType.PERSONAL;
if (icicle == null) {
final VolumeInfo specifiedVolumeInfo =
@@ -288,18 +288,19 @@
}
private void initializePreference() {
- if (mPersonalOnly) {
- final Preference summary = getPreferenceScreen().findPreference(SUMMARY_PREF_KEY);
- if (summary != null) {
- summary.setVisible(false);
- }
- }
mFreeUpSpacePreference = getPreferenceScreen().findPreference(FREE_UP_SPACE_PREF_KEY);
mFreeUpSpacePreference.setOnPreferenceClickListener(this);
}
@Override
public void onAttach(Context context) {
+ // These member variables are initialized befoer super.onAttach for
+ // createPreferenceControllers to work correctly.
+ mUserManager = context.getSystemService(UserManager.class);
+ mIsWorkProfile = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.ProfileType.WORK;
+ mUserId = Utils.getCurrentUserId(mUserManager, mIsWorkProfile);
+
super.onAttach(context);
use(AutomaticStorageManagementSwitchPreferenceController.class).setFragmentManager(
getFragmentManager());
@@ -396,7 +397,7 @@
}
if (mAppsResult != null) {
- mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
+ mPreferenceController.onLoadFinished(mAppsResult, mUserId);
updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
stopLoading = true;
}
@@ -427,14 +428,13 @@
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
-
StorageManager sm = context.getSystemService(StorageManager.class);
mPreferenceController = new StorageItemPreferenceController(context, this,
- null /* volume */, new StorageManagerVolumeProvider(sm));
+ null /* volume */, new StorageManagerVolumeProvider(sm), mIsWorkProfile);
controllers.add(mPreferenceController);
- final UserManager userManager = context.getSystemService(UserManager.class);
- mSecondaryUsers = SecondaryUserController.getSecondaryUserControllers(context, userManager);
+ mSecondaryUsers = SecondaryUserController.getSecondaryUserControllers(context,
+ mUserManager, mIsWorkProfile /* isWorkProfileOnly */);
controllers.addAll(mSecondaryUsers);
return controllers;
@@ -480,9 +480,10 @@
final UserManager userManager = context.getSystemService(UserManager.class);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new StorageItemPreferenceController(context, null /* host */,
- null /* volume */, new StorageManagerVolumeProvider(sm)));
+ null /* volume */, new StorageManagerVolumeProvider(sm),
+ false /* isWorkProfile */));
controllers.addAll(SecondaryUserController.getSecondaryUserControllers(
- context, userManager));
+ context, userManager, false /* isWorkProfileOnly */));
return controllers;
}
@@ -492,7 +493,7 @@
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
Bundle args) {
final Context context = getContext();
- return new StorageAsyncLoader(context, context.getSystemService(UserManager.class),
+ return new StorageAsyncLoader(context, mUserManager,
mSelectedStorageEntry.getFsUuid(),
new StorageStatsSource(context),
context.getPackageManager());
@@ -519,7 +520,7 @@
metricsFeatureProvider.logClickedPreference(preference, getMetricsCategory());
metricsFeatureProvider.action(context, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW);
final Intent intent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
- context.startActivity(intent);
+ context.startActivityAsUser(intent, new UserHandle(mUserId));
return true;
}
return false;
@@ -574,16 +575,14 @@
}
private void initializeCacheProvider() {
- mCachedStorageValuesHelper =
- new CachedStorageValuesHelper(getContext(), UserHandle.myUserId());
+ mCachedStorageValuesHelper = new CachedStorageValuesHelper(getContext(), mUserId);
initializeCachedValues();
onReceivedSizes();
}
private void maybeCacheFreshValues() {
if (mStorageInfo != null && mAppsResult != null) {
- mCachedStorageValuesHelper.cacheResult(
- mStorageInfo, mAppsResult.get(UserHandle.myUserId()));
+ mCachedStorageValuesHelper.cacheResult(mStorageInfo, mAppsResult.get(mUserId));
}
}
diff --git a/src/com/android/settings/deviceinfo/StorageProfileFragment.java b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
deleted file mode 100644
index 360265c..0000000
--- a/src/com/android/settings/deviceinfo/StorageProfileFragment.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2017 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.deviceinfo;
-
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.os.Bundle;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.os.storage.StorageManager;
-import android.os.storage.VolumeInfo;
-import android.util.SparseArray;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.loader.app.LoaderManager;
-import androidx.loader.content.Loader;
-
-import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
-import com.android.settings.deviceinfo.storage.StorageAsyncLoader.AppsStorageResult;
-import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
-import com.android.settingslib.applications.StorageStatsSource;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * StorageProfileFragment is a fragment which shows the storage results for a profile of the
- * primary user.
- */
-public class StorageProfileFragment extends DashboardFragment
- implements LoaderManager.LoaderCallbacks<SparseArray<AppsStorageResult>> {
- private static final String TAG = "StorageProfileFragment";
- public static final String USER_ID_EXTRA = "userId";
- private static final int APPS_JOB_ID = 0;
-
- private VolumeInfo mVolume;
- private int mUserId;
- private StorageItemPreferenceController mPreferenceController;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- final Bundle args = getArguments();
-
- // Initialize the storage sizes that we can quickly calc.
- final Context context = getActivity();
- final StorageManager sm = context.getSystemService(StorageManager.class);
- mVolume = Utils.maybeInitializeVolume(sm, args);
- if (mVolume == null) {
- getActivity().finish();
- return;
- }
-
- mPreferenceController.setVolume(mVolume);
- mUserId = args.getInt(USER_ID_EXTRA, UserHandle.myUserId());
- mPreferenceController.setUserId(UserHandle.of(mUserId));
- }
-
- @Override
- public void onResume() {
- super.onResume();
- getLoaderManager().initLoader(APPS_JOB_ID, Bundle.EMPTY, this);
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.SETTINGS_STORAGE_PROFILE;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.storage_profile_fragment;
- }
-
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- final StorageManager sm = context.getSystemService(StorageManager.class);
- mPreferenceController =
- new StorageItemPreferenceController(
- context,
- this,
- mVolume,
- new StorageManagerVolumeProvider(sm),
- /* isWorkProfile */ true);
- controllers.add(mPreferenceController);
- return controllers;
- }
-
- @Override
- public Loader<SparseArray<AppsStorageResult>> onCreateLoader(int id, Bundle args) {
- final Context context = getContext();
- return new StorageAsyncLoader(context,
- context.getSystemService(UserManager.class),
- mVolume.fsUuid,
- new StorageStatsSource(context),
- context.getPackageManager());
- }
-
- @Override
- public void onLoadFinished(Loader<SparseArray<AppsStorageResult>> loader,
- SparseArray<AppsStorageResult> result) {
- mPreferenceController.onLoadFinished(result, mUserId);
- }
-
- @Override
- public void onLoaderReset(Loader<SparseArray<AppsStorageResult>> loader) {
- }
-
- @VisibleForTesting
- void setPreferenceController(StorageItemPreferenceController controller) {
- mPreferenceController = controller;
- }
-}
diff --git a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
index 5d58547..99b6752 100644
--- a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
+++ b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
@@ -63,9 +63,11 @@
*
* @param context Context for initializing the preference controllers.
* @param userManager UserManagerWrapper for figuring out which controllers to add.
+ * @param isWorkProfileOnly only shows secondary users of work profile.
+ * (e.g., it should be true in work profile tab)
*/
public static List<AbstractPreferenceController> getSecondaryUserControllers(
- Context context, UserManager userManager) {
+ Context context, UserManager userManager, boolean isWorkProfileOnly) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
UserInfo primaryUser = userManager.getPrimaryUser();
@@ -77,7 +79,11 @@
continue;
}
- if (info == null || Utils.isProfileOf(primaryUser, info)) {
+ if (Utils.isProfileOf(primaryUser, info)) {
+ continue;
+ }
+
+ if (isWorkProfileOnly && !info.isManagedProfile()) {
continue;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index f53b68f..3d8a822 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -82,7 +82,7 @@
}
});
for (int i = 0, userCount = infos.size(); i < userCount; i++) {
- UserInfo info = infos.get(i);
+ final UserInfo info = infos.get(i);
result.put(info.id, getStorageResultForUser(info.id));
}
return result;
@@ -109,7 +109,7 @@
final long dataSize = stats.getDataBytes();
final long cacheQuota = mStatsManager.getCacheQuotaBytes(mUuid, app.uid);
final long cacheBytes = stats.getCacheBytes();
- long blamedSize = dataSize;
+ long blamedSize = dataSize + stats.getCodeBytes();
// Technically, we could overages as freeable on the storage settings screen.
// If the app is using more cache than its quota, we would accidentally subtract the
// overage from the system size (because it shows up as unused) during our attribution.
@@ -118,12 +118,11 @@
blamedSize = blamedSize - cacheBytes + cacheQuota;
}
- // This isn't quite right because it slams the first user by user id with the whole code
- // size, but this ensures that we count all apps seen once.
- boolean isAddCodeBytesForFirstUserId = false;
- if (!mSeenPackages.contains(app.packageName)) {
- isAddCodeBytesForFirstUserId = true;
- blamedSize += stats.getCodeBytes();
+ // Code bytes may share between different profiles. To know all the duplicate code size
+ // and we can get a reasonable system size in StorageItemPreferenceController.
+ if (mSeenPackages.contains(app.packageName)) {
+ result.duplicateCodeSize += stats.getCodeBytes();
+ } else {
mSeenPackages.add(app.packageName);
}
@@ -135,9 +134,7 @@
// TODO(b/170918505): Should revamp audio size calculation with the data
// from media provider.
result.musicAppsSize += blamedSize;
- if (isAddCodeBytesForFirstUserId) {
- result.musicAppsSize -= stats.getCodeBytes();
- }
+ result.musicAppsSize -= stats.getCodeBytes();
result.otherAppsSize += blamedSize;
break;
@@ -145,9 +142,7 @@
// TODO(b/170918505): Should revamp video size calculation with the data
// from media provider.
result.videoAppsSize += blamedSize;
- if (isAddCodeBytesForFirstUserId) {
- result.videoAppsSize -= stats.getCodeBytes();
- }
+ result.videoAppsSize -= stats.getCodeBytes();
result.otherAppsSize += blamedSize;
break;
@@ -155,9 +150,7 @@
// TODO(b/170918505): Should revamp image size calculation with the data
// from media provider.
result.photosAppsSize += blamedSize;
- if (isAddCodeBytesForFirstUserId) {
- result.photosAppsSize -= stats.getCodeBytes();
- }
+ result.photosAppsSize -= stats.getCodeBytes();
result.otherAppsSize += blamedSize;
break;
@@ -194,6 +187,7 @@
public long videoAppsSize;
public long otherAppsSize;
public long cacheSize;
+ public long duplicateCodeSize;
public StorageStatsSource.ExternalStorageStats externalStats;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index bc46110..656f337 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -101,6 +101,7 @@
private static final int LAST_STORAGE_CATEGORY_PREFERENCE_ORDER = 200;
private PackageManager mPackageManager;
+ private UserManager mUserManager;
private final Fragment mFragment;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final StorageVolumeProvider mSvp;
@@ -134,15 +135,17 @@
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
- public StorageItemPreferenceController(
- Context context, Fragment hostFragment, VolumeInfo volume, StorageVolumeProvider svp) {
+ public StorageItemPreferenceController(Context context, Fragment hostFragment,
+ VolumeInfo volume, StorageVolumeProvider svp, boolean isWorkProfile) {
super(context);
mPackageManager = context.getPackageManager();
+ mUserManager = context.getSystemService(UserManager.class);
mFragment = hostFragment;
mVolume = volume;
mSvp = svp;
+ mIsWorkProfile = isWorkProfile;
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
- mUserId = UserHandle.myUserId();
+ mUserId = getCurrentUserId();
mImagesUri = Uri.parse(context.getResources()
.getString(R.string.config_images_storage_category_uri));
@@ -154,14 +157,9 @@
.getString(R.string.config_documents_and_other_storage_category_uri));
}
- public StorageItemPreferenceController(
- Context context,
- Fragment hostFragment,
- VolumeInfo volume,
- StorageVolumeProvider svp,
- boolean isWorkProfile) {
- this(context, hostFragment, volume, svp);
- mIsWorkProfile = isWorkProfile;
+ @VisibleForTesting
+ int getCurrentUserId() {
+ return Utils.getCurrentUserId(mUserManager, mIsWorkProfile);
}
@Override
@@ -311,6 +309,9 @@
* Sets the user id for which this preference controller is handling.
*/
public void setUserId(UserHandle userHandle) {
+ if (mIsWorkProfile && !mUserManager.isManagedProfile(userHandle.getIdentifier())) {
+ throw new IllegalArgumentException("Only accept work profile userHandle");
+ }
mUserId = userHandle.getIdentifier();
tintPreference(mPublicStoragePreference);
@@ -359,21 +360,21 @@
public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
int userId) {
final StorageAsyncLoader.AppsStorageResult data = result.get(userId);
- final StorageAsyncLoader.AppsStorageResult profileData = result.get(
- Utils.getManagedProfileId(mContext.getSystemService(UserManager.class), userId));
- mImagesPreference.setStorageSize(getImagesSize(data, profileData), mTotalSize);
- mVideosPreference.setStorageSize(getVideosSize(data, profileData), mTotalSize);
- mAudiosPreference.setStorageSize(getAudiosSize(data, profileData), mTotalSize);
- mAppsPreference.setStorageSize(getAppsSize(data, profileData), mTotalSize);
- mGamesPreference.setStorageSize(getGamesSize(data, profileData), mTotalSize);
- mDocumentsAndOtherPreference.setStorageSize(getDocumentsAndOtherSize(data, profileData),
+ mImagesPreference.setStorageSize(getImagesSize(data), mTotalSize);
+ mVideosPreference.setStorageSize(getVideosSize(data), mTotalSize);
+ mAudiosPreference.setStorageSize(getAudiosSize(data), mTotalSize);
+ mAppsPreference.setStorageSize(getAppsSize(data), mTotalSize);
+ mGamesPreference.setStorageSize(getGamesSize(data), mTotalSize);
+ mDocumentsAndOtherPreference.setStorageSize(getDocumentsAndOtherSize(data),
mTotalSize);
- mTrashPreference.setStorageSize(getTrashSize(data, profileData), mTotalSize);
+ mTrashPreference.setStorageSize(getTrashSize(data), mTotalSize);
if (mSystemPreference != null) {
// Everything else that hasn't already been attributed is tracked as
// belonging to system.
+ // TODO(b/170918505): Should revamp system size calculation with the data
+ // from media provider.
long attributedSize = 0;
for (int i = 0; i < result.size(); i++) {
final StorageAsyncLoader.AppsStorageResult otherData = result.valueAt(i);
@@ -385,6 +386,7 @@
+ otherData.otherAppsSize;
attributedSize += otherData.externalStats.totalBytes
- otherData.externalStats.appBytes;
+ attributedSize -= otherData.duplicateCodeSize;
}
final long systemSize = Math.max(TrafficStats.GB_IN_BYTES, mUsedBytes - attributedSize);
@@ -404,47 +406,28 @@
private void launchPublicStorageIntent() {
final Intent intent = mVolume.buildBrowseIntent();
- if (intent != null) {
- mContext.startActivity(intent);
+ if (intent == null) {
+ return;
}
+ mContext.startActivityAsUser(intent, new UserHandle(mUserId));
}
private void launchActivityWithUri(Uri dataUri) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(dataUri);
- mContext.startActivity(intent);
+ mContext.startActivityAsUser(intent, new UserHandle(mUserId));
}
- private long getImagesSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
- if (profileData != null) {
- return data.photosAppsSize + data.externalStats.imageBytes
- + data.externalStats.videoBytes
- + profileData.photosAppsSize + profileData.externalStats.imageBytes
- + profileData.externalStats.videoBytes;
- } else {
- return data.photosAppsSize + data.externalStats.imageBytes
- + data.externalStats.videoBytes;
- }
+ private long getImagesSize(StorageAsyncLoader.AppsStorageResult data) {
+ return data.photosAppsSize + data.externalStats.imageBytes + data.externalStats.videoBytes;
}
- private long getVideosSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
- if (profileData != null) {
- return data.videoAppsSize + profileData.videoAppsSize;
- } else {
- return data.videoAppsSize;
- }
+ private long getVideosSize(StorageAsyncLoader.AppsStorageResult data) {
+ return data.videoAppsSize;
}
- private long getAudiosSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
- if (profileData != null) {
- return data.musicAppsSize + data.externalStats.audioBytes
- + profileData.musicAppsSize + profileData.externalStats.audioBytes;
- } else {
- return data.musicAppsSize + data.externalStats.audioBytes;
- }
+ private long getAudiosSize(StorageAsyncLoader.AppsStorageResult data) {
+ return data.musicAppsSize + data.externalStats.audioBytes;
}
private void launchAppsIntent() {
@@ -463,13 +446,8 @@
Utils.launchIntent(mFragment, intent);
}
- private long getAppsSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
- if (profileData != null) {
- return data.otherAppsSize + profileData.otherAppsSize;
- } else {
- return data.otherAppsSize;
- }
+ private long getAppsSize(StorageAsyncLoader.AppsStorageResult data) {
+ return data.otherAppsSize;
}
private void launchGamesIntent() {
@@ -486,13 +464,8 @@
Utils.launchIntent(mFragment, intent);
}
- private long getGamesSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
- if (profileData != null) {
- return data.gamesSize + profileData.gamesSize;
- } else {
- return data.gamesSize;
- }
+ private long getGamesSize(StorageAsyncLoader.AppsStorageResult data) {
+ return data.gamesSize;
}
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
@@ -502,26 +475,12 @@
return args;
}
- private long getDocumentsAndOtherSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
- if (profileData != null) {
- return data.externalStats.totalBytes
- - data.externalStats.audioBytes
- - data.externalStats.videoBytes
- - data.externalStats.imageBytes
- - data.externalStats.appBytes
- + profileData.externalStats.totalBytes
- - profileData.externalStats.audioBytes
- - profileData.externalStats.videoBytes
- - profileData.externalStats.imageBytes
- - profileData.externalStats.appBytes;
- } else {
- return data.externalStats.totalBytes
- - data.externalStats.audioBytes
- - data.externalStats.videoBytes
- - data.externalStats.imageBytes
- - data.externalStats.appBytes;
- }
+ private long getDocumentsAndOtherSize(StorageAsyncLoader.AppsStorageResult data) {
+ return data.externalStats.totalBytes
+ - data.externalStats.audioBytes
+ - data.externalStats.videoBytes
+ - data.externalStats.imageBytes
+ - data.externalStats.appBytes;
}
private void launchTrashIntent() {
@@ -530,12 +489,11 @@
if (intent.resolveActivity(mPackageManager) == null) {
EmptyTrashFragment.show(mFragment);
} else {
- mContext.startActivity(intent);
+ mContext.startActivityAsUser(intent, new UserHandle(mUserId));
}
}
- private long getTrashSize(StorageAsyncLoader.AppsStorageResult data,
- StorageAsyncLoader.AppsStorageResult profileData) {
+ private long getTrashSize(StorageAsyncLoader.AppsStorageResult data) {
// TODO(170918505): Implement it.
return 0L;
}
diff --git a/src/com/android/settings/deviceinfo/storage/UserProfileController.java b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
deleted file mode 100644
index a2e19db..0000000
--- a/src/com/android/settings/deviceinfo/storage/UserProfileController.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2017 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.deviceinfo.storage;
-
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.content.pm.UserInfo;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.os.storage.VolumeInfo;
-import android.util.SparseArray;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.internal.util.Preconditions;
-import com.android.settings.Utils;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.deviceinfo.StorageItemPreference;
-import com.android.settings.deviceinfo.StorageProfileFragment;
-import com.android.settingslib.core.AbstractPreferenceController;
-
-/**
- * Defines a {@link AbstractPreferenceController} which handles a single profile of the primary
- * user.
- */
-public class UserProfileController extends AbstractPreferenceController implements
- PreferenceControllerMixin, StorageAsyncLoader.ResultHandler,
- UserIconLoader.UserIconHandler {
- private static final String PREFERENCE_KEY_BASE = "pref_profile_";
- private StorageItemPreference mStoragePreference;
- private UserInfo mUser;
- private long mTotalSizeBytes;
- private final int mPreferenceOrder;
-
- public UserProfileController(Context context, UserInfo info, int preferenceOrder) {
- super(context);
- mUser = Preconditions.checkNotNull(info);
- mPreferenceOrder = preferenceOrder;
- }
-
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return PREFERENCE_KEY_BASE + mUser.id;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- mStoragePreference = new StorageItemPreference(screen.getContext());
- mStoragePreference.setOrder(mPreferenceOrder);
- mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
- mStoragePreference.setTitle(mUser.name);
- screen.addPreference(mStoragePreference);
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (preference != null && mStoragePreference == preference) {
- final Bundle args = new Bundle();
- args.putInt(StorageProfileFragment.USER_ID_EXTRA, mUser.id);
- args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
-
- new SubSettingLauncher(mContext)
- .setDestination(StorageProfileFragment.class.getName())
- .setArguments(args)
- .setTitleText(mUser.name)
- .setSourceMetricsCategory(SettingsEnums.DEVICEINFO_STORAGE)
- .launch();
- return true;
- }
-
- return false;
- }
-
- @Override
- public void handleResult(SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
- Preconditions.checkNotNull(stats);
-
- int userId = mUser.id;
- StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
- if (result != null) {
- setSize(result.externalStats.totalBytes
- + result.otherAppsSize
- + result.videoAppsSize
- + result.musicAppsSize
- + result.gamesSize,
- mTotalSizeBytes);
- }
- }
-
- /**
- * Sets the size for the preference using a byte count.
- */
- public void setSize(long size, long totalSize) {
- if (mStoragePreference != null) {
- mStoragePreference.setStorageSize(size, totalSize);
- }
- }
-
- public void setTotalSize(long totalSize) {
- mTotalSizeBytes = totalSize;
- }
-
- @Override
- public void handleUserIcons(SparseArray<Drawable> fetchedIcons) {
- Drawable userIcon = fetchedIcons.get(mUser.id);
- if (userIcon != null) {
- mStoragePreference.setIcon(applyTint(mContext, userIcon));
- }
- }
-
- private static Drawable applyTint(Context context, Drawable icon) {
- icon = icon.mutate();
- icon.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal));
- return icon;
- }
-
-}