/** Forwards the call to {@link #sendBroadcast(Intent)}, disregarding {@code user} param. */ @Implementation(minSdk = JELLY_BEAN_MR1) @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) protected void sendBroadcastAsUser(@RequiresPermission Intent intent, UserHandle user) { sendBroadcast(intent); }
/** * Forwards the call to {@link #sendBroadcast(Intent,String)}, disregarding {@code user} param. */ @Implementation(minSdk = JELLY_BEAN_MR1) @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) protected void sendBroadcastAsUser( @RequiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission) { sendBroadcast(intent, receiverPermission); }
@Implementation(minSdk = KITKAT) @RequiresPermission(value = android.Manifest.permission.WATCH_APPOPS) protected void stopWatchingMode(OnOpChangedListener callback) { appOpListeners.inverse().remove(callback); }
@Implementation(minSdk = KITKAT) @HiddenApi @RequiresPermission(value = android.Manifest.permission.WATCH_APPOPS) protected void startWatchingMode(int op, String packageName, OnOpChangedListener callback) { appOpListeners.put(getListenerKey(op, packageName), callback); }
@Implementation(minSdk = JELLY_BEAN_MR1) @HiddenApi @RequiresPermission( anyOf = { "android.permission.INTERACT_ACROSS_USERS", "android.permission.INTERACT_ACROSS_USERS_FULL" }) protected static int getCurrentUser() { return UserHandle.myUserId(); }
/** * Int version of {@link #setMode(String, int, String, int)}. * * <p>This method is public for testing {@link #checkOpNoThrow}. If {@link #checkOpNoThrow} is * * called afterwards with the {@code op}, {@code ui}, and {@code packageName} provided, it will * * return the {@code mode} set here. */ @Implementation(minSdk = KITKAT) @HiddenApi @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) public void setMode(int op, int uid, String packageName, int mode) { Integer oldMode = appModeMap.put(getOpMapKey(uid, packageName, op), mode); OnOpChangedListener listener = appOpListeners.get(getListenerKey(op, packageName)); if (listener != null && !Objects.equals(oldMode, mode)) { String[] sOpToString = ReflectionHelpers.getStaticField(AppOpsManager.class, "sOpToString"); listener.onOpChanged(sOpToString[op], packageName); } }
/** * Change the operating mode for the given op in the given app package. You must pass in both the * uid and name of the application whose mode is being modified; if these do not match, the * modification will not be applied. * * <p>This method is public for testing {@link #checkOpNoThrow}. If {@link #checkOpNoThrow} is * called afterwards with the {@code op}, {@code ui}, and {@code packageName} provided, it will * return the {@code mode} set here. * * @param op The operation to modify. One of the OPSTR_* constants. * @param uid The user id of the application whose mode will be changed. * @param packageName The name of the application package name whose mode will be changed. */ @Implementation(minSdk = P) @HiddenApi @SystemApi @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) public void setMode(String op, int uid, String packageName, int mode) { setMode(AppOpsManager.strOpToOp(op), uid, packageName, mode); }
@Implementation(minSdk = KITKAT) @RequiresPermission(value = android.Manifest.permission.WATCH_APPOPS) protected void stopWatchingMode(OnOpChangedListener callback) { appOpListeners.inverse().remove(callback); }
@Implementation(minSdk = KITKAT) @HiddenApi @RequiresPermission(value = android.Manifest.permission.WATCH_APPOPS) protected void startWatchingMode(int op, String packageName, OnOpChangedListener callback) { appOpListeners.put(getListenerKey(op, packageName), callback); }
/** * Int version of {@link #setMode(String, int, String, int)}. * * <p>This method is public for testing {@link #checkOpNoThrow}. If {@link #checkOpNoThrow} is * * called afterwards with the {@code op}, {@code ui}, and {@code packageName} provided, it will * * return the {@code mode} set here. */ @Implementation(minSdk = KITKAT) @HiddenApi @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) public void setMode(int op, int uid, String packageName, int mode) { Integer oldMode = appModeMap.put(getOpMapKey(uid, packageName, op), mode); OnOpChangedListener listener = appOpListeners.get(getListenerKey(op, packageName)); if (listener != null && !Objects.equals(oldMode, mode)) { String[] sOpToString = ReflectionHelpers.getStaticField(AppOpsManager.class, "sOpToString"); listener.onOpChanged(sOpToString[op], packageName); } }
/** * Change the operating mode for the given op in the given app package. You must pass in both the * uid and name of the application whose mode is being modified; if these do not match, the * modification will not be applied. * * <p>This method is public for testing {@link #checkOpNoThrow}. If {@link #checkOpNoThrow} is * called afterwards with the {@code op}, {@code ui}, and {@code packageName} provided, it will * return the {@code mode} set here. * * @param op The operation to modify. One of the OPSTR_* constants. * @param uid The user id of the application whose mode will be changed. * @param packageName The name of the application package name whose mode will be changed. */ @Implementation(minSdk = P) @HiddenApi @SystemApi @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) public void setMode(String op, int uid, String packageName, int mode) { setMode(AppOpsManager.strOpToOp(op), uid, packageName, mode); }