Merge "Enforce permissions check in getLastTimeAnyComponentUsed" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
dbdd7012bc
@@ -68,5 +68,5 @@ interface IUsageStatsManager {
|
|||||||
void reportUserInteraction(String packageName, int userId);
|
void reportUserInteraction(String packageName, int userId);
|
||||||
int getUsageSource();
|
int getUsageSource();
|
||||||
void forceUsageSourceSettingRead();
|
void forceUsageSourceSettingRead();
|
||||||
long getLastTimeAnyComponentUsed(String packageName);
|
long getLastTimeAnyComponentUsed(String packageName, String callingPackage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1287,7 +1287,7 @@ public final class UsageStatsManager {
|
|||||||
android.Manifest.permission.PACKAGE_USAGE_STATS})
|
android.Manifest.permission.PACKAGE_USAGE_STATS})
|
||||||
public long getLastTimeAnyComponentUsed(@NonNull String packageName) {
|
public long getLastTimeAnyComponentUsed(@NonNull String packageName) {
|
||||||
try {
|
try {
|
||||||
return mService.getLastTimeAnyComponentUsed(packageName);
|
return mService.getLastTimeAnyComponentUsed(packageName, mContext.getOpPackageName());
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
throw re.rethrowFromSystemServer();
|
throw re.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2226,7 +2226,14 @@ public class UsageStatsService extends SystemService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLastTimeAnyComponentUsed(String packageName) {
|
public long getLastTimeAnyComponentUsed(String packageName, String callingPackage) {
|
||||||
|
if (!hasPermissions(
|
||||||
|
callingPackage, android.Manifest.permission.INTERACT_ACROSS_USERS)) {
|
||||||
|
throw new SecurityException("Caller doesn't have INTERACT_ACROSS_USERS permission");
|
||||||
|
}
|
||||||
|
if (!hasPermission(callingPackage)) {
|
||||||
|
throw new SecurityException("Don't have permission to query usage stats");
|
||||||
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
// Truncate the returned milliseconds to the boundary of the last day before exact
|
// Truncate the returned milliseconds to the boundary of the last day before exact
|
||||||
// time for privacy reasons.
|
// time for privacy reasons.
|
||||||
|
|||||||
Reference in New Issue
Block a user