Add SDK sandbox network usage to corresponding apps.
SDK sandboxes run in a separate UID range. Their network usage should be attributed to the corresponding app. Make sure we collapse the usage collection of sandboxes to the corresponding app UID in DataUsageList. For AppDataUsage, make sure we add in the sandbox UID when being asked to calculate data usage for a regular app UID. Invoke DataUsageCycleLoader with all UIDs in AppItem, because there can now be multiple UIDs associated with a regular app, too. Also make sure that all new instances of AppItem for regular applications have their own application UID. Bug: 225319220 Test: manual Change-Id: Id101a96ee4e3ba02376fa2ac64a9f9c2581acb61
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.ArraySet;
|
||||
@@ -140,6 +141,14 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
|
||||
}
|
||||
}
|
||||
|
||||
if (mAppItem.key > 0 && UserHandle.isApp(mAppItem.key)) {
|
||||
// In case we've been asked data usage for an app, automatically
|
||||
// include data usage of the corresponding SDK sandbox
|
||||
final int appSandboxUid = Process.toSdkSandboxUid(mAppItem.key);
|
||||
if (!mAppItem.uids.get(appSandboxUid)) {
|
||||
mAppItem.addUid(appSandboxUid);
|
||||
}
|
||||
}
|
||||
mTotalUsage = findPreference(KEY_TOTAL_USAGE);
|
||||
mForegroundUsage = findPreference(KEY_FOREGROUND_USAGE);
|
||||
mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
|
||||
@@ -295,6 +304,10 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
|
||||
}
|
||||
|
||||
private void addUid(int uid) {
|
||||
if (Process.isSdkSandboxUid(uid)) {
|
||||
// For a sandbox process, get the associated app UID
|
||||
uid = Process.getAppUidForSdkSandboxUid(uid);
|
||||
}
|
||||
String[] packages = mPackageManager.getPackagesForUid(uid);
|
||||
if (packages != null) {
|
||||
for (int i = 0; i < packages.length; i++) {
|
||||
@@ -394,12 +407,8 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
|
||||
= NetworkCycleDataForUidLoader.builder(mContext);
|
||||
builder.setRetrieveDetail(true)
|
||||
.setNetworkTemplate(mTemplate);
|
||||
if (mAppItem.category == AppItem.CATEGORY_USER) {
|
||||
for (int i = 0; i < mAppItem.uids.size(); i++) {
|
||||
builder.addUid(mAppItem.uids.keyAt(i));
|
||||
}
|
||||
} else {
|
||||
builder.addUid(mAppItem.key);
|
||||
for (int i = 0; i < mAppItem.uids.size(); i++) {
|
||||
builder.addUid(mAppItem.uids.keyAt(i));
|
||||
}
|
||||
if (mCycles != null) {
|
||||
builder.setCycles(mCycles);
|
||||
|
Reference in New Issue
Block a user