Search in sources :

Example 76 with AppOpsManager

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

the class DevelopmentSettings method writeMockLocation.

private void writeMockLocation() {
    AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
    // Disable the app op of the previous mock location app if such.
    List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
    if (packageOps != null) {
        // Should be one but in case we are in a bad state due to use of command line tools.
        for (PackageOps packageOp : packageOps) {
            if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
                String oldMockLocationApp = packageOp.getPackageName();
                try {
                    ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
                    appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, oldMockLocationApp, AppOpsManager.MODE_ERRORED);
                } catch (NameNotFoundException e) {
                /* ignore */
                }
            }
        }
    }
    // Enable the app op of the new mock location app if such.
    if (!TextUtils.isEmpty(mMockLocationApp)) {
        try {
            ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
            appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, mMockLocationApp, AppOpsManager.MODE_ALLOWED);
        } catch (NameNotFoundException e) {
        /* ignore */
        }
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) PackageOps(android.app.AppOpsManager.PackageOps)

Example 77 with AppOpsManager

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

the class DevelopmentSettings method writeMockLocation.

private void writeMockLocation() {
    AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
    // Disable the app op of the previous mock location app if such.
    List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
    if (packageOps != null) {
        // Should be one but in case we are in a bad state due to use of command line tools.
        for (PackageOps packageOp : packageOps) {
            if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
                String oldMockLocationApp = packageOp.getPackageName();
                try {
                    ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
                    appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, oldMockLocationApp, AppOpsManager.MODE_ERRORED);
                } catch (NameNotFoundException e) {
                /* ignore */
                }
            }
        }
    }
    // Enable the app op of the new mock location app if such.
    if (!TextUtils.isEmpty(mMockLocationApp)) {
        try {
            ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
            appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, mMockLocationApp, AppOpsManager.MODE_ALLOWED);
        } catch (NameNotFoundException e) {
        /* ignore */
        }
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) PackageOps(android.app.AppOpsManager.PackageOps)

Example 78 with AppOpsManager

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

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 79 with AppOpsManager

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

the class VpnSettings method getVpnApps.

static List<AppVpnInfo> getVpnApps(Context context, boolean includeProfiles) {
    List<AppVpnInfo> result = Lists.newArrayList();
    final Set<Integer> profileIds;
    if (includeProfiles) {
        profileIds = new ArraySet<>();
        for (UserHandle profile : UserManager.get(context).getUserProfiles()) {
            profileIds.add(profile.getIdentifier());
        }
    } else {
        profileIds = Collections.singleton(UserHandle.myUserId());
    }
    // Fetch VPN-enabled apps from AppOps.
    AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    List<AppOpsManager.PackageOps> apps = aom.getPackagesForOps(new int[] { OP_ACTIVATE_VPN });
    if (apps != null) {
        for (AppOpsManager.PackageOps pkg : apps) {
            int userId = UserHandle.getUserId(pkg.getUid());
            if (!profileIds.contains(userId)) {
                // Skip packages for users outside of our profile group.
                continue;
            }
            // Look for a MODE_ALLOWED permission to activate VPN.
            boolean allowed = false;
            for (AppOpsManager.OpEntry op : pkg.getOps()) {
                if (op.getOp() == OP_ACTIVATE_VPN && op.getMode() == AppOpsManager.MODE_ALLOWED) {
                    allowed = true;
                }
            }
            if (allowed) {
                result.add(new AppVpnInfo(userId, pkg.getPackageName()));
            }
        }
    }
    Collections.sort(result);
    return result;
}
Also used : AppOpsManager(android.app.AppOpsManager) UserHandle(android.os.UserHandle)

Example 80 with AppOpsManager

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

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)

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