有UsageStatsService一个hasPermission [1]方法检查是否PACKAGE_USAGE_STATS授予权限。它用于以下方法:
queryEvents [2]
queryConfigurations [3]
queryUsageStats [4]
queryAndAggregateUsageStats(它使用相同的方法queryUsageStats)
这是isAppInactive [5]的代码,你可以看到没有请求权限:
@Override
public boolean isAppInactive(String packageName, int userId) {
try {
userId = ActivityManagerNative.getDefault().handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, true, "isAppInactive", null);
} catch (RemoteException re) {
return false;
}
final long token = Binder.clearCallingIdentity();
try {
return UsageStatsService.this.isAppIdleFilteredOrParoled(packageName, userId, -1);
} finally {
Binder.restoreCallingIdentity(token);
}
}
正如您在添加的提交isAppInactive消息中看到的那样(最初被调用isAppIdle,然后被重命名),API 应该是公共的:
Add ability to get and set idle state of apps
Add am shell command to set and get idle
Add public API to check if an app is idle
我不认为这是一个错误,而只是一个不清楚的文档。