Java Code Examples for android.app.AppOpsManager#PackageOps

The following examples show how to use android.app.AppOpsManager#PackageOps . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
        int[] ops) {
    mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
            Binder.getCallingPid(), Binder.getCallingUid(), null);
    String resolvedPackageName = resolvePackageName(uid, packageName);
    if (resolvedPackageName == null) {
        return Collections.emptyList();
    }
    synchronized (this) {
        Ops pkgOps = getOpsRawLocked(uid, resolvedPackageName, false /* edit */,
                false /* uidMismatchExpected */);
        if (pkgOps == null) {
            return null;
        }
        ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
        if (resOps == null) {
            return null;
        }
        ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
        AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
                pkgOps.packageName, pkgOps.uidState.uid, resOps);
        res.add(resPackage);
        return res;
    }
}
 
Example 2
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public List<AppOpsManager.PackageOps> getUidOps(int uid, int[] ops) {
    mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
            Binder.getCallingPid(), Binder.getCallingUid(), null);
    synchronized (this) {
        UidState uidState = getUidStateLocked(uid, false);
        if (uidState == null) {
            return null;
        }
        ArrayList<AppOpsManager.OpEntry> resOps = collectOps(uidState.opModes, ops);
        if (resOps == null) {
            return null;
        }
        ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
        AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
                null, uidState.uid, resOps);
        res.add(resPackage);
        return res;
    }
}
 
Example 3
Source File: AppStateTracker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Update {@link #mRunAnyRestrictedPackages} with the current app ops state.
 */
@GuardedBy("mLock")
private void refreshForcedAppStandbyUidPackagesLocked() {
    mRunAnyRestrictedPackages.clear();
    final List<PackageOps> ops = mAppOpsManager.getPackagesForOps(
            new int[] {TARGET_OP});

    if (ops == null) {
        return;
    }
    final int size = ops.size();
    for (int i = 0; i < size; i++) {
        final AppOpsManager.PackageOps pkg = ops.get(i);
        final List<AppOpsManager.OpEntry> entries = ops.get(i).getOps();

        for (int j = 0; j < entries.size(); j++) {
            AppOpsManager.OpEntry ent = entries.get(j);
            if (ent.getOp() != TARGET_OP) {
                continue;
            }
            if (ent.getMode() != AppOpsManager.MODE_ALLOWED) {
                mRunAnyRestrictedPackages.add(Pair.create(
                        pkg.getUid(), pkg.getPackageName()));
            }
        }
    }
}