Merge "Add permission check to UsageStatsManager#isAppInactive" into rvc-dev am: dcc388ab44
Change-Id: I0ee8681752311979bf2b8c6e569dff4a42ba9a7d
This commit is contained in:
committed by
Automerger Merge Worker
commit
8c4540ffcf
@@ -43,7 +43,7 @@ interface IUsageStatsManager {
|
|||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void setAppInactive(String packageName, boolean inactive, int userId);
|
void setAppInactive(String packageName, boolean inactive, int userId);
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
boolean isAppInactive(String packageName, int userId);
|
boolean isAppInactive(String packageName, int userId, String callingPackage);
|
||||||
void onCarrierPrivilegedAppsChanged();
|
void onCarrierPrivilegedAppsChanged();
|
||||||
void reportChooserSelection(String packageName, int userId, String contentType,
|
void reportChooserSelection(String packageName, int userId, String contentType,
|
||||||
in String[] annotations, String action);
|
in String[] annotations, String action);
|
||||||
|
|||||||
@@ -622,12 +622,17 @@ public final class UsageStatsManager {
|
|||||||
* app hasn't been used directly or indirectly for a period of time defined by the system. This
|
* app hasn't been used directly or indirectly for a period of time defined by the system. This
|
||||||
* could be of the order of several hours or days. Apps are not considered inactive when the
|
* could be of the order of several hours or days. Apps are not considered inactive when the
|
||||||
* device is charging.
|
* device is charging.
|
||||||
|
* <p> The caller must have {@link android.Manifest.permission#PACKAGE_USAGE_STATS} to query the
|
||||||
|
* inactive state of other apps</p>
|
||||||
|
*
|
||||||
* @param packageName The package name of the app to query
|
* @param packageName The package name of the app to query
|
||||||
* @return whether the app is currently considered inactive
|
* @return whether the app is currently considered inactive or false if querying another app
|
||||||
|
* without {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
|
||||||
*/
|
*/
|
||||||
public boolean isAppInactive(String packageName) {
|
public boolean isAppInactive(String packageName) {
|
||||||
try {
|
try {
|
||||||
return mService.isAppInactive(packageName, mContext.getUserId());
|
return mService.isAppInactive(packageName, mContext.getUserId(),
|
||||||
|
mContext.getOpPackageName());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// fall through and return default
|
// fall through and return default
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2504,7 +2504,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
|
|||||||
|
|
||||||
IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(
|
IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(
|
||||||
Context.USAGE_STATS_SERVICE));
|
Context.USAGE_STATS_SERVICE));
|
||||||
boolean isIdle = usm.isAppInactive(packageName, userId);
|
boolean isIdle = usm.isAppInactive(packageName, userId, SHELL_PACKAGE_NAME);
|
||||||
pw.println("Idle=" + isIdle);
|
pw.println("Idle=" + isIdle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1577,15 +1577,27 @@ public class UsageStatsService extends SystemService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAppInactive(String packageName, int userId) {
|
public boolean isAppInactive(String packageName, int userId, String callingPackage) {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
try {
|
try {
|
||||||
userId = ActivityManager.getService().handleIncomingUser(Binder.getCallingPid(),
|
userId = ActivityManager.getService().handleIncomingUser(Binder.getCallingPid(),
|
||||||
Binder.getCallingUid(), userId, false, false, "isAppInactive", null);
|
callingUid, userId, false, false, "isAppInactive", null);
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
throw re.rethrowFromSystemServer();
|
throw re.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the calling app is asking about itself, continue, else check for permission.
|
||||||
|
if (packageName.equals(callingPackage)) {
|
||||||
|
final int actualCallingUid = mPackageManagerInternal.getPackageUidInternal(
|
||||||
|
callingPackage, 0, userId);
|
||||||
|
if (actualCallingUid != callingUid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!hasPermission(callingPackage)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
|
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
|
||||||
Binder.getCallingUid(), userId);
|
callingUid, userId);
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
return mAppStandby.isAppIdleFiltered(
|
return mAppStandby.isAppIdleFiltered(
|
||||||
|
|||||||
Reference in New Issue
Block a user