Merge "Let settings query an app's minimum bucket." into tm-dev
This commit is contained in:
@@ -143,6 +143,11 @@ public interface AppStandbyInternal {
|
||||
void setAppStandbyBuckets(@NonNull List<AppStandbyInfo> appBuckets, int userId, int callingUid,
|
||||
int callingPid);
|
||||
|
||||
/** Return the lowest bucket this app can enter. */
|
||||
@StandbyBuckets
|
||||
int getAppMinStandbyBucket(String packageName, int appId, int userId,
|
||||
boolean shouldObfuscateInstantApps);
|
||||
|
||||
/**
|
||||
* Put the specified app in the
|
||||
* {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED}
|
||||
|
||||
@@ -1436,6 +1436,18 @@ public class AppStandbyController
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@StandbyBuckets
|
||||
public int getAppMinStandbyBucket(String packageName, int appId, int userId,
|
||||
boolean shouldObfuscateInstantApps) {
|
||||
if (shouldObfuscateInstantApps && mInjector.isPackageEphemeral(userId, packageName)) {
|
||||
return STANDBY_BUCKET_NEVER;
|
||||
}
|
||||
synchronized (mAppIdleLock) {
|
||||
return getAppMinBucket(packageName, appId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restrictApp(@NonNull String packageName, int userId,
|
||||
@ForcedReasons int restrictReason) {
|
||||
|
||||
@@ -53,6 +53,7 @@ interface IUsageStatsManager {
|
||||
void setAppStandbyBucket(String packageName, int bucket, int userId);
|
||||
ParceledListSlice getAppStandbyBuckets(String callingPackage, int userId);
|
||||
void setAppStandbyBuckets(in ParceledListSlice appBuckets, int userId);
|
||||
int getAppMinStandbyBucket(String packageName, String callingPackage, int userId);
|
||||
void setEstimatedLaunchTime(String packageName, long estimatedLaunchTime, int userId);
|
||||
void setEstimatedLaunchTimes(in ParceledListSlice appLaunchTimes, int userId);
|
||||
void registerAppUsageObserver(int observerId, in String[] packages, long timeLimitMs,
|
||||
|
||||
@@ -786,6 +786,23 @@ public final class UsageStatsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the lowest bucket this app can ever enter.
|
||||
*
|
||||
* @param packageName the package for which to fetch the minimum allowed standby bucket.
|
||||
* {@hide}
|
||||
*/
|
||||
@StandbyBuckets
|
||||
@RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)
|
||||
public int getAppMinStandbyBucket(String packageName) {
|
||||
try {
|
||||
return mService.getAppMinStandbyBucket(packageName, mContext.getOpPackageName(),
|
||||
mContext.getUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes an app's estimated launch time. An app is considered "launched" when a user opens
|
||||
* one of its {@link android.app.Activity Activities}. The provided time is persisted across
|
||||
|
||||
@@ -2378,6 +2378,40 @@ public class UsageStatsService extends SystemService implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAppMinStandbyBucket(String packageName, String callingPackage, int userId) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
try {
|
||||
userId = ActivityManager.getService().handleIncomingUser(
|
||||
Binder.getCallingPid(), callingUid, userId, false, false,
|
||||
"getAppStandbyBucket", null);
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
final int packageUid = mPackageManagerInternal.getPackageUid(packageName, 0, userId);
|
||||
// If the calling app is asking about itself, continue, else check for permission.
|
||||
if (packageUid != callingUid) {
|
||||
if (!hasPermission(callingPackage)) {
|
||||
throw new SecurityException(
|
||||
"Don't have permission to query min app standby bucket");
|
||||
}
|
||||
}
|
||||
if (packageUid < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot get min standby bucket for non existent package ("
|
||||
+ packageName + ")");
|
||||
}
|
||||
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(callingUid,
|
||||
userId);
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
return mAppStandby.getAppMinStandbyBucket(
|
||||
packageName, UserHandle.getAppId(packageUid), userId, obfuscateInstantApps);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEstimatedLaunchTime(String packageName, long estimatedLaunchTime,
|
||||
int userId) {
|
||||
|
||||
Reference in New Issue
Block a user