0

I'm using isAppInactive() method from UsageStatsManager class on Android 6 (API 23) to detect the standby state of the app I'm developing.

The docs affirm that it is necessary to request PACKAGE_USAGE_STATS permission but I'm able to use that method without requesting the permission.

Is this a bug?

4

1 回答 1

1

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

我不认为这是一个错误,而只是一个不清楚的文档。

于 2015-11-11T16:27:33.730 回答