Search in sources :

Example 31 with AppOpsManager

use of android.app.AppOpsManager in project android_packages_apps_Settings by SudaMod.

the class PictureInPictureDetails method setEnterPipStateForPackage.

/**
 * Sets whether the app associated with the given {@param packageName} is allowed to enter
 * picture-in-picture.
 */
static void setEnterPipStateForPackage(Context context, int uid, String packageName, boolean value) {
    final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
    final int newMode = value ? MODE_ALLOWED : MODE_ERRORED;
    appOps.setMode(OP_PICTURE_IN_PICTURE, uid, packageName, newMode);
}
Also used : AppOpsManager(android.app.AppOpsManager)

Example 32 with AppOpsManager

use of android.app.AppOpsManager in project android_packages_apps_Settings by SudaMod.

the class AppManagementFragment method appHasVpnPermission.

@VisibleForTesting
static boolean appHasVpnPermission(Context context, @NonNull ApplicationInfo application) {
    final AppOpsManager service = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    final List<AppOpsManager.PackageOps> ops = service.getOpsForPackage(application.uid, application.packageName, new int[] { OP_ACTIVATE_VPN });
    return !ArrayUtils.isEmpty(ops);
}
Also used : AppOpsManager(android.app.AppOpsManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 33 with AppOpsManager

use of android.app.AppOpsManager in project AndroidStudy by tinggengyan.

the class NotificationsUtils method lowVersionCheck.

private static boolean lowVersionCheck(Context context) {
    AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    ApplicationInfo appInfo = context.getApplicationInfo();
    String pkg = context.getApplicationContext().getPackageName();
    int uid = appInfo.uid;
    Class appOpsClass = null;
    /* Context.APP_OPS_MANAGER */
    try {
        appOpsClass = Class.forName(AppOpsManager.class.getName());
        Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class);
        Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
        int value = (int) opPostNotificationValue.get(Integer.class);
        return ((int) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : Field(java.lang.reflect.Field) AppOpsManager(android.app.AppOpsManager) ApplicationInfo(android.content.pm.ApplicationInfo) Method(java.lang.reflect.Method)

Example 34 with AppOpsManager

use of android.app.AppOpsManager in project android_packages_apps_Settings by DirtyUnicorns.

the class DevelopmentSettings method updateMockLocation.

private void updateMockLocation() {
    AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
    List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
    if (packageOps != null) {
        for (PackageOps packageOp : packageOps) {
            if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
                mMockLocationApp = packageOps.get(0).getPackageName();
                break;
            }
        }
    }
    if (!TextUtils.isEmpty(mMockLocationApp)) {
        String label = mMockLocationApp;
        try {
            ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
            CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
            if (appLabel != null) {
                label = appLabel.toString();
            }
        } catch (PackageManager.NameNotFoundException e) {
        /* ignore */
        }
        mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
        mHaveDebugSettings = true;
    } else {
        mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) PackageOps(android.app.AppOpsManager.PackageOps)

Example 35 with AppOpsManager

use of android.app.AppOpsManager in project android_packages_apps_Settings by DirtyUnicorns.

the class AppManagementFragment method appHasVpnPermission.

@VisibleForTesting
static boolean appHasVpnPermission(Context context, @NonNull ApplicationInfo application) {
    final AppOpsManager service = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    final List<AppOpsManager.PackageOps> ops = service.getOpsForPackage(application.uid, application.packageName, new int[] { OP_ACTIVATE_VPN });
    return !ArrayUtils.isEmpty(ops);
}
Also used : AppOpsManager(android.app.AppOpsManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

AppOpsManager (android.app.AppOpsManager)101 ApplicationInfo (android.content.pm.ApplicationInfo)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)27 PackageManager (android.content.pm.PackageManager)18 PackageOps (android.app.AppOpsManager.PackageOps)14 ArrayList (java.util.ArrayList)14 UserHandle (android.os.UserHandle)13 IOException (java.io.IOException)10 Context (android.content.Context)9 PackageInfo (android.content.pm.PackageInfo)9 Method (java.lang.reflect.Method)9 TargetApi (android.annotation.TargetApi)8 HashMap (java.util.HashMap)8 RemoteException (android.os.RemoteException)7 ActivityManager (android.app.ActivityManager)6 Intent (android.content.Intent)6 ResolveInfo (android.content.pm.ResolveInfo)6 UserManager (android.os.UserManager)6 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)6 Field (java.lang.reflect.Field)6