Use correct uid when querying usage data for specific user.
- the data usage list shows usage data for each app, and also the aggregated data for work apps and other user. When user clicks on the app item, we will shows the detail usage data for that item using the app item key. However, if the app item is not for app but for user, the key will not be the app uid, but a key built from the user id. So, querying using the key will not get any data. - for app item corresponding for user, need to sum up all usage data for the uids associated with the user. Change-Id: I1a185ee6b4d59e477f3a03cade97d85d6982e416 Fixes: 122200400 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -31,7 +33,9 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.Bundle;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.view.View;
|
||||
|
||||
@@ -47,6 +51,7 @@ import com.android.settingslib.AppItem;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.net.NetworkCycleDataForUid;
|
||||
import com.android.settingslib.net.NetworkCycleDataForUidLoader;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -188,7 +193,7 @@ public class AppDataUsageTest {
|
||||
ReflectionHelpers.setField(mFragment, "mBackgroundUsage", preference);
|
||||
ReflectionHelpers.setField(mFragment, "mForegroundUsage", preference);
|
||||
ReflectionHelpers.setField(mFragment, "mTotalUsage", preference);
|
||||
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
|
||||
ReflectionHelpers.setField(mFragment, "mContext", RuntimeEnvironment.application);
|
||||
|
||||
mFragment.bindData(0 /* position */);
|
||||
|
||||
@@ -199,7 +204,7 @@ public class AppDataUsageTest {
|
||||
public void bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary() {
|
||||
mFragment = spy(new AppDataUsage());
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
doReturn(context).when(mFragment).getContext();
|
||||
ReflectionHelpers.setField(mFragment, "mContext", context);
|
||||
final long backgroundBytes = 1234L;
|
||||
final long foregroundBytes = 5678L;
|
||||
final List<NetworkCycleDataForUid> appUsage = new ArrayList<>();
|
||||
@@ -223,4 +228,53 @@ public class AppDataUsageTest {
|
||||
verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
|
||||
verify(foregroundPref).setSummary(DataUsageUtils.formatDataUsage(context, foregroundBytes));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateLoader_categoryApp_shouldQueryDataUsageUsingAppKey() {
|
||||
mFragment = new AppDataUsage();
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final int testUid = 123123;
|
||||
final AppItem appItem = new AppItem(testUid);
|
||||
appItem.category = AppItem.CATEGORY_APP;
|
||||
ReflectionHelpers.setField(mFragment, "mContext", context);
|
||||
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
|
||||
ReflectionHelpers.setField(mFragment, "mTemplate",
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
final long end = System.currentTimeMillis();
|
||||
final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
|
||||
|
||||
final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
|
||||
mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
|
||||
|
||||
final List<Integer> uids = loader.getUids();
|
||||
assertThat(uids).hasSize(1);
|
||||
assertThat(uids.get(0)).isEqualTo(testUid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateLoader_categoryUser_shouldQueryDataUsageUsingAssociatedUids() {
|
||||
mFragment = new AppDataUsage();
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final int testUserId = 11;
|
||||
final AppItem appItem = new AppItem(testUserId);
|
||||
appItem.category = AppItem.CATEGORY_USER;
|
||||
appItem.addUid(123);
|
||||
appItem.addUid(456);
|
||||
appItem.addUid(789);
|
||||
ReflectionHelpers.setField(mFragment, "mContext", context);
|
||||
ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
|
||||
ReflectionHelpers.setField(mFragment, "mTemplate",
|
||||
NetworkTemplate.buildTemplateWifiWildcard());
|
||||
final long end = System.currentTimeMillis();
|
||||
final long start = end - (DateUtils.WEEK_IN_MILLIS * 4);
|
||||
|
||||
final NetworkCycleDataForUidLoader loader = (NetworkCycleDataForUidLoader)
|
||||
mFragment.mUidDataCallbacks.onCreateLoader(0, Bundle.EMPTY);
|
||||
|
||||
final List<Integer> uids = loader.getUids();
|
||||
assertThat(uids).hasSize(3);
|
||||
assertThat(uids.get(0)).isEqualTo(123);
|
||||
assertThat(uids.get(1)).isEqualTo(456);
|
||||
assertThat(uids.get(2)).isEqualTo(789);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user