Add more sane multi-profile app attribution.

Due to issues w.r.t. attribution across multiple users, we originally
duplicated the previous implementation which zeroed out the sizes. This,
however, caused system bloat due to the change in how we calculate the
system size.

By attributing apps which do not exist in the primary profile to the
first user that shows up with it installed, we can avoid accidentally
attributing it to the system size.

Bug: 62623731
Test: Settings unittest & Settings robotest
Change-Id: I9514c9ecef62ea6270723f62e6bf27c69b75f180
This commit is contained in:
Daniel Nishi
2017-06-15 17:19:31 -07:00
parent 327b9119d7
commit b088010d12
5 changed files with 60 additions and 25 deletions

View File

@@ -120,7 +120,6 @@ public class StorageProfileFragment extends DashboardFragment
@Override
public void onLoadFinished(Loader<SparseArray<AppsStorageResult>> loader,
SparseArray<AppsStorageResult> result) {
scrubAppsFromResult(result.get(mUserId));
mPreferenceController.onLoadFinished(result, mUserId);
}
@@ -132,17 +131,4 @@ public class StorageProfileFragment extends DashboardFragment
void setPreferenceController(StorageItemPreferenceController controller) {
mPreferenceController = controller;
}
private AppsStorageResult scrubAppsFromResult(AppsStorageResult result) {
if (result == null) {
return null;
}
// TODO(b/35927909): Attribute app sizes better than zeroing out for profiles.
result.gamesSize = 0;
result.musicAppsSize = 0;
result.videoAppsSize = 0;
result.otherAppsSize = 0;
return result;
}
}

View File

@@ -25,6 +25,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
@@ -34,6 +35,8 @@ import com.android.settings.utils.AsyncLoader;
import com.android.settingslib.applications.StorageStatsSource;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
@@ -48,6 +51,7 @@ public class StorageAsyncLoader
private String mUuid;
private StorageStatsSource mStatsManager;
private PackageManagerWrapper mPackageManager;
private ArraySet<String> mSeenPackages;
public StorageAsyncLoader(Context context, UserManagerWrapper userManager,
String uuid, StorageStatsSource source, PackageManagerWrapper pm) {
@@ -64,8 +68,18 @@ public class StorageAsyncLoader
}
private SparseArray<AppsStorageResult> loadApps() {
mSeenPackages = new ArraySet<>();
SparseArray<AppsStorageResult> result = new SparseArray<>();
List<UserInfo> infos = mUserManager.getUsers();
// Sort the users by user id ascending.
Collections.sort(
infos,
new Comparator<UserInfo>() {
@Override
public int compare(UserInfo userInfo, UserInfo otherUser) {
return Integer.compare(userInfo.id, otherUser.id);
}
});
for (int i = 0, userCount = infos.size(); i < userCount; i++) {
UserInfo info = infos.get(i);
result.put(info.id, getStorageResultForUser(info.id));
@@ -93,10 +107,11 @@ public class StorageAsyncLoader
long blamedSize = stats.getDataBytes() - stats.getCacheBytes();
// Only count app code against the current user; we don't want
// double-counting on multi-user devices.
if (userId == UserHandle.myUserId()) {
// 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.
if (!mSeenPackages.contains(app.packageName)) {
blamedSize += stats.getCodeBytes();
mSeenPackages.add(app.packageName);
}
switch (app.category) {
@@ -140,6 +155,7 @@ public class StorageAsyncLoader
public long musicAppsSize;
public long videoAppsSize;
public long otherAppsSize;
public long cacheSize;
public StorageStatsSource.ExternalStorageStats externalStats;
}

View File

@@ -96,7 +96,13 @@ public class UserProfileController extends PreferenceController
int userId = mUser.id;
StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
if (result != null) {
setSize(result.externalStats.totalBytes, mTotalSizeBytes);
setSize(
result.externalStats.totalBytes
+ result.otherAppsSize
+ result.videoAppsSize
+ result.musicAppsSize
+ result.gamesSize,
mTotalSizeBytes);
}
}