Merge "Make UsageStats query API UserHandle-aware" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
51fbb49435
@@ -30,7 +30,7 @@ import java.util.Map;
|
||||
interface IUsageStatsManager {
|
||||
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
|
||||
ParceledListSlice queryUsageStats(int bucketType, long beginTime, long endTime,
|
||||
String callingPackage);
|
||||
String callingPackage, int userId);
|
||||
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
|
||||
ParceledListSlice queryConfigurationStats(int bucketType, long beginTime, long endTime,
|
||||
String callingPackage);
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.SystemService;
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.UserHandleAware;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
@@ -437,11 +438,12 @@ public final class UsageStatsManager {
|
||||
* @see #INTERVAL_YEARLY
|
||||
* @see #INTERVAL_BEST
|
||||
*/
|
||||
@UserHandleAware
|
||||
public List<UsageStats> queryUsageStats(int intervalType, long beginTime, long endTime) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
ParceledListSlice<UsageStats> slice = mService.queryUsageStats(intervalType, beginTime,
|
||||
endTime, mContext.getOpPackageName());
|
||||
endTime, mContext.getOpPackageName(), mContext.getUserId());
|
||||
if (slice != null) {
|
||||
return slice.getList();
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class ResolverListControllerTest {
|
||||
final List<UsageStats> slices = new ArrayList<>();
|
||||
slices.add(packageStats);
|
||||
ParceledListSlice<UsageStats> stats = new ParceledListSlice<>(slices);
|
||||
when(mMockService.queryUsageStats(anyInt(), anyLong(), anyLong(), anyString()))
|
||||
when(mMockService.queryUsageStats(anyInt(), anyLong(), anyLong(), anyString(), anyInt()))
|
||||
.thenReturn(stats);
|
||||
Answer<Void> answer = new Answer<Void>() {
|
||||
@Override
|
||||
|
||||
@@ -1526,15 +1526,19 @@ public class UsageStatsService extends SystemService implements
|
||||
|
||||
@Override
|
||||
public ParceledListSlice<UsageStats> queryUsageStats(int bucketType, long beginTime,
|
||||
long endTime, String callingPackage) {
|
||||
long endTime, String callingPackage, int userId) {
|
||||
if (!hasPermission(callingPackage)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
|
||||
Binder.getCallingUid(), UserHandle.getCallingUserId());
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), callingUid,
|
||||
userId, false, true, "queryUsageStats", callingPackage);
|
||||
|
||||
// Check the caller's userId for obfuscation decision, not the user being queried
|
||||
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
|
||||
callingUid, UserHandle.getCallingUserId());
|
||||
|
||||
final int userId = UserHandle.getCallingUserId();
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
final List<UsageStats> results = UsageStatsService.this.queryUsageStats(
|
||||
|
||||
Reference in New Issue
Block a user