android.app.AppOpsManager Java Examples

The following examples show how to use android.app.AppOpsManager. 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: MeizuUtils.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #2
Source File: ClipboardService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean clipboardAccessAllowed(int op, String callingPackage, int callingUid) {
    // Check the AppOp.
    if (mAppOps.noteOp(op, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
        return false;
    }
    try {
        // Installed apps can access the clipboard at any time.
        if (!AppGlobals.getPackageManager().isInstantApp(callingPackage,
                    UserHandle.getUserId(callingUid))) {
            return true;
        }
        // Instant apps can only access the clipboard if they are in the foreground.
        return mAm.isAppForeground(callingUid);
    } catch (RemoteException e) {
        Slog.e("clipboard", "Failed to get Instant App status for package " + callingPackage,
                e);
        return false;
    }
}
 
Example #3
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public Bundle getCache(String packageName, Uri key, int userId) {
    enforceCrossUserPermission(userId, TAG);
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CACHE_CONTENT, TAG);
    mContext.getSystemService(AppOpsManager.class).checkPackage(Binder.getCallingUid(),
            packageName);

    final String providerPackageName = getProviderPackageName(key);
    final Pair<String, Uri> fullKey = Pair.create(packageName, key);

    synchronized (mCache) {
        final ArrayMap<Pair<String, Uri>, Bundle> cache = findOrCreateCacheLocked(userId,
                providerPackageName);
        return cache.get(fullKey);
    }
}
 
Example #4
Source File: AppPermissionActivity.java    From AppOpsX with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case android.R.id.home:
      finish();
      return true;
    case R.id.action_reset:
      mPresenter.reset();
      return true;
    case R.id.action_hide_perm:
      showHidePerms();
      return true;
    case R.id.action_open_all:
      changeAll(AppOpsManager.MODE_ALLOWED);
      break;
    case R.id.action_close_all:
      changeAll(AppOpsManager.MODE_IGNORED);
      break;
    case R.id.action_app_info:
      startAppinfo();
      break;
  }
  return super.onOptionsItemSelected(item);
}
 
Example #5
Source File: PackageInstallerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void systemReady() {
    mAppOps = mContext.getSystemService(AppOpsManager.class);

    synchronized (mSessions) {
        readSessionsLocked();

        reconcileStagesLocked(StorageManager.UUID_PRIVATE_INTERNAL, false /*isInstant*/);
        reconcileStagesLocked(StorageManager.UUID_PRIVATE_INTERNAL, true /*isInstant*/);

        final ArraySet<File> unclaimedIcons = newArraySet(
                mSessionsDir.listFiles());

        // Ignore stages and icons claimed by active sessions
        for (int i = 0; i < mSessions.size(); i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            unclaimedIcons.remove(buildAppIconFile(session.sessionId));
        }

        // Clean up orphaned icons
        for (File icon : unclaimedIcons) {
            Slog.w(TAG, "Deleting orphan icon " + icon);
            icon.delete();
        }
    }
}
 
Example #6
Source File: PermissionUtil.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
public static boolean isMockLocationEnabled(Context context) {
    boolean isMockLocation = false;
    try {
        //if marshmallow
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            AppOpsManager opsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
            if (opsManager != null) {
                isMockLocation = (opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, android.os.Process.myUid(), context.getPackageName()) == AppOpsManager.MODE_ALLOWED);
            }
        } else {
            // in marshmallow this will always return true
            isMockLocation = !android.provider.Settings.Secure.getString(context.getContentResolver(), "mock_location").equals("0");
        }
    } catch (Exception e) {
        return false;
    }
    return isMockLocation;
}
 
Example #7
Source File: FloatWindowParamManager.java    From FloatWindow with Apache License 2.0 6 votes vote down vote up
public static boolean checkOverlayPermission(Context context) {
    AppOpsManager appOpsMgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    try {
        if (appOpsMgr != null) {
            int mode = appOpsMgr.checkOpNoThrow("android:system_alert_window",
                    android.os.Process.myUid(), context.getPackageName());
            if (mode == 0) {
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
Example #8
Source File: FloatWindowParamManager.java    From FloatWindow with Apache License 2.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private static boolean checkOps(Context context) {
    try {
        Object object = context.getSystemService(Context.APP_OPS_SERVICE);
        if (object == null) {
            return false;
        }
        Class localClass = object.getClass();
        Class[] arrayOfClass = new Class[3];
        arrayOfClass[0] = Integer.TYPE;
        arrayOfClass[1] = Integer.TYPE;
        arrayOfClass[2] = String.class;
        Method method = localClass.getMethod("checkOp", arrayOfClass);
        if (method == null) {
            return false;
        }
        Object[] arrayOfObject1 = new Object[3];
        arrayOfObject1[0] = 24;
        arrayOfObject1[1] = Binder.getCallingUid();
        arrayOfObject1[2] = AppUtils.getAppPackageName();
        int m = (Integer) method.invoke(object, arrayOfObject1);
        return m == AppOpsManager.MODE_ALLOWED || !RomUtils.isDomesticSpecialRom();
    } catch (Exception ignore) {
    }
    return false;
}
 
Example #9
Source File: HuaweiUtils.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
  final int version = Build.VERSION.SDK_INT;
  if (version >= 19) {
    AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    try {
      Class clazz = AppOpsManager.class;
      Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
      return AppOpsManager.MODE_ALLOWED == (int) method
          .invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
    } catch (Exception e) {
      Log.e(TAG, Log.getStackTraceString(e));
    }
  } else {
    Log.e(TAG, "Below API 19 cannot invoke!");
  }
  return false;
}
 
Example #10
Source File: QikuUtils.java    From zone-sdk with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #11
Source File: MeizuUtils.java    From zone-sdk with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #12
Source File: PermissionUtils.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check if application can draw over other apps
 * @param context Context
 * @return Boolean
 */
public static boolean canDrawOverlays(@NonNull Context context) {
    final int sdkInt = Build.VERSION.SDK_INT;
    if (sdkInt >= Build.VERSION_CODES.M) {
        if (sdkInt == Build.VERSION_CODES.O) {
            // Sometimes Settings.canDrawOverlays returns false after allowing permission.
            // Google Issue Tracker: https://issuetracker.google.com/issues/66072795
            AppOpsManager appOpsMgr = context.getSystemService(AppOpsManager.class);
            if (appOpsMgr != null) {
                int mode = appOpsMgr.checkOpNoThrow(
                        "android:system_alert_window",
                        android.os.Process.myUid(),
                        context.getPackageName()
                );
                return mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED;
            } else {
                return false;
            }
        }
        // Default
        return android.provider.Settings.canDrawOverlays(context);
    }
    return true; // This fallback may returns a incorrect result.
}
 
Example #13
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void putCache(String packageName, Uri key, Bundle value, int userId) {
    Bundle.setDefusable(value, true);
    enforceCrossUserPermission(userId, TAG);
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CACHE_CONTENT, TAG);
    mContext.getSystemService(AppOpsManager.class).checkPackage(Binder.getCallingUid(),
            packageName);

    final String providerPackageName = getProviderPackageName(key);
    final Pair<String, Uri> fullKey = Pair.create(packageName, key);

    synchronized (mCache) {
        final ArrayMap<Pair<String, Uri>, Bundle> cache = findOrCreateCacheLocked(userId,
                providerPackageName);
        if (value != null) {
            cache.put(fullKey, value);
        } else {
            cache.remove(fullKey);
        }
    }
}
 
Example #14
Source File: Notifier.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Called when a wake lock is released.
 */
public void onWakeLockReleased(int flags, String tag, String packageName,
        int ownerUid, int ownerPid, WorkSource workSource, String historyTag) {
    if (DEBUG) {
        Slog.d(TAG, "onWakeLockReleased: flags=" + flags + ", tag=\"" + tag
                + "\", packageName=" + packageName
                + ", ownerUid=" + ownerUid + ", ownerPid=" + ownerPid
                + ", workSource=" + workSource);
    }

    final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
    if (monitorType >= 0) {
        try {
            if (workSource != null) {
                mBatteryStats.noteStopWakelockFromSource(workSource, ownerPid, tag,
                        historyTag, monitorType);
            } else {
                mBatteryStats.noteStopWakelock(ownerUid, ownerPid, tag,
                        historyTag, monitorType);
                mAppOps.finishOp(AppOpsManager.OP_WAKE_LOCK, ownerUid, packageName);
            }
        } catch (RemoteException ex) {
            // Ignore
        }
    }
}
 
Example #15
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean isOpRestrictedLocked(int uid, int code, String packageName) {
    int userHandle = UserHandle.getUserId(uid);
    final int restrictionSetCount = mOpUserRestrictions.size();

    for (int i = 0; i < restrictionSetCount; i++) {
        // For each client, check that the given op is not restricted, or that the given
        // package is exempt from the restriction.
        ClientRestrictionState restrictionState = mOpUserRestrictions.valueAt(i);
        if (restrictionState.hasRestriction(code, packageName, userHandle)) {
            if (AppOpsManager.opAllowSystemBypassRestriction(code)) {
                // If we are the system, bypass user restrictions for certain codes
                synchronized (this) {
                    Ops ops = getOpsRawLocked(uid, packageName, true /* edit */,
                            false /* uidMismatchExpected */);
                    if ((ops != null) && ops.isPrivileged) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
    return false;
}
 
Example #16
Source File: MeizuUtils.java    From GrabQQPWD with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == method.invoke(manager, op, Binder.getCallingUid(),
                    context.getPackageName());
        } catch (Exception e) {
            Log.e("", e.getMessage());
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #17
Source File: QikuUtils.java    From FloatBall with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #18
Source File: CaptureActivity.java    From ZbarCode with Apache License 2.0 6 votes vote down vote up
private void checkPermissionCamera() {
    int checkPermission = 0;
    if (Build.VERSION.SDK_INT >= 23) {
        // checkPermission =ContextCompat.checkSelfPermission(this,Manifest.permission.CAMERA);
        checkPermission = PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (checkPermission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CAMERA},
                    MY_PERMISSIONS_REQUEST_CAMERA);
        } else {
            isOpenCamera = true;
        }

    } else {
        checkPermission = checkPermission(26);
        if (checkPermission == AppOpsManager.MODE_ALLOWED) {
            isOpenCamera = true;
        } else if (checkPermission == AppOpsManager.MODE_IGNORED) {
            isOpenCamera = false;
            displayFrameworkBugMessageAndExit();
        }
    }
}
 
Example #19
Source File: NetworkStatsAccess.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static boolean hasAppOpsPermission(
        Context context, int callingUid, String callingPackage) {
    if (callingPackage != null) {
        AppOpsManager appOps = (AppOpsManager) context.getSystemService(
                Context.APP_OPS_SERVICE);

        final int mode = appOps.noteOp(AppOpsManager.OP_GET_USAGE_STATS,
                callingUid, callingPackage);
        if (mode == AppOpsManager.MODE_DEFAULT) {
            // The default behavior here is to check if PackageManager has given the app
            // permission.
            final int permissionCheck = context.checkCallingPermission(
                    Manifest.permission.PACKAGE_USAGE_STATS);
            return permissionCheck == PackageManager.PERMISSION_GRANTED;
        }
        return (mode == AppOpsManager.MODE_ALLOWED);
    }
    return false;
}
 
Example #20
Source File: SkinDeviceUtils.java    From Android-skin-support with MIT License 6 votes vote down vote up
@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
Example #21
Source File: HuaweiUtils.java    From FloatBall with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #22
Source File: MiuiUtils.java    From GrabQQPWD with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == method.invoke(manager, op, Binder.getCallingUid(),
                    context.getPackageName());
        } catch (Exception e) {
            Log.e("", e.getMessage());
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #23
Source File: DeviceUtils.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
Example #24
Source File: CaptureActivity.java    From ScanZbar with Apache License 2.0 6 votes vote down vote up
private void checkPermissionCamera() {
    int checkPermission = 0;
    if (Build.VERSION.SDK_INT >= 23) {
        // checkPermission =ContextCompat.checkSelfPermission(this,Manifest.permission.CAMERA);
        checkPermission = PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (checkPermission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CAMERA},
                    MY_PERMISSIONS_REQUEST_CAMERA);
        } else {
            isOpenCamera = true;
        }

    } else {
        checkPermission = checkPermission(26);
        if (checkPermission == AppOpsManager.MODE_ALLOWED) {
            isOpenCamera = true;
        } else if (checkPermission == AppOpsManager.MODE_IGNORED) {
            isOpenCamera = false;
            displayFrameworkBugMessageAndExit();
        }
    }
}
 
Example #25
Source File: OppoUtils.java    From zone-sdk with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
Example #26
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int noteOperation(int code, int uid, String packageName) {
    verifyIncomingUid(uid);
    verifyIncomingOp(code);
    String resolvedPackageName = resolvePackageName(uid, packageName);
    if (resolvedPackageName == null) {
        return AppOpsManager.MODE_IGNORED;
    }
    return noteOperationUnchecked(code, uid, resolvedPackageName, 0, null);
}
 
Example #27
Source File: ActivityUsageStatsImpl.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isEnabled(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);

        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
        return Objects.requireNonNull(appOpsManager).checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
                applicationInfo.uid, applicationInfo.packageName) == AppOpsManager.MODE_ALLOWED;
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }

    return false;
}
 
Example #28
Source File: NotProguardUtils.java    From XKnife-Android with Apache License 2.0 5 votes vote down vote up
private static Integer invokeMethod(AppOpsManager manager, String methodName, int op,
                                    int callingUid, String packageName) {
    Class<AppOpsManager> c = AppOpsManager.class;
    try {
        Method method = c.getMethod(methodName, int.class, int.class, String.class);
        if (method != null) {
            method.setAccessible(true);
            Object object = method.invoke(manager, op, callingUid, packageName);
            return (Integer) object;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return -1;
}
 
Example #29
Source File: MmsServiceBroker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setAutoPersisting(String callingPkg, boolean enabled) throws RemoteException {
    if (getAppOpsManager().noteOp(AppOpsManager.OP_WRITE_SMS, Binder.getCallingUid(),
            callingPkg) != AppOpsManager.MODE_ALLOWED) {
        return;
    }
    getServiceGuarded().setAutoPersisting(callingPkg, enabled);
}
 
Example #30
Source File: XiaomiUtilities.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("JavaReflectionMemberAccess")
@TargetApi(19)
public static boolean isCustomPermissionGranted(int permission) {
	try {
		AppOpsManager mgr = (AppOpsManager) ApplicationLoader.applicationContext.getSystemService(Context.APP_OPS_SERVICE);
		Method m = AppOpsManager.class.getMethod("checkOpNoThrow", int.class, int.class, String.class);
		int result = (int) m.invoke(mgr, permission, android.os.Process.myUid(), ApplicationLoader.applicationContext.getPackageName());
		return result == AppOpsManager.MODE_ALLOWED;
	} catch (Exception x) {
		FileLog.e(x);
	}
	return true;
}