Merge "Add permission check to UsageStatsManager#isAppInactive" into rvc-dev

This commit is contained in:
Michael Wachenschwanz
2020-04-20 15:15:35 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 7 deletions

View File

@@ -43,7 +43,7 @@ interface IUsageStatsManager {
@UnsupportedAppUsage
void setAppInactive(String packageName, boolean inactive, int userId);
@UnsupportedAppUsage
boolean isAppInactive(String packageName, int userId);
boolean isAppInactive(String packageName, int userId, String callingPackage);
void onCarrierPrivilegedAppsChanged();
void reportChooserSelection(String packageName, int userId, String contentType,
in String[] annotations, String action);

View File

@@ -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
* could be of the order of several hours or days. Apps are not considered inactive when the
* 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
* @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) {
try {
return mService.isAppInactive(packageName, mContext.getUserId());
return mService.isAppInactive(packageName, mContext.getUserId(),
mContext.getOpPackageName());
} catch (RemoteException e) {
// fall through and return default
}