Search in sources :

Example 21 with PackageOps

use of android.app.AppOpsManager.PackageOps 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 22 with PackageOps

use of android.app.AppOpsManager.PackageOps 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 23 with PackageOps

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

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 24 with PackageOps

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

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 25 with PackageOps

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

the class AppStateAppOpsBridge method getPermissionInfo.

public PermissionState getPermissionInfo(String pkg, int uid) {
    PermissionState permissionState = new PermissionState(pkg, new UserHandle(UserHandle.getUserId(uid)));
    try {
        permissionState.packageInfo = mIPackageManager.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS | PackageManager.MATCH_ANY_USER, permissionState.userHandle.getIdentifier());
        if (permissionState.packageInfo != null) {
            // Check static permission state (whatever that is declared in package manifest)
            String[] requestedPermissions = permissionState.packageInfo.requestedPermissions;
            int[] permissionFlags = permissionState.packageInfo.requestedPermissionsFlags;
            if (requestedPermissions != null) {
                for (int i = 0; i < requestedPermissions.length; i++) {
                    if (doesAnyPermissionMatch(requestedPermissions[i], mPermissions)) {
                        permissionState.permissionDeclared = true;
                        if ((permissionFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
                            permissionState.staticPermissionGranted = true;
                            break;
                        }
                    }
                }
            }
        }
        // Check app op state.
        List<PackageOps> ops = mAppOpsManager.getOpsForPackage(uid, pkg, mAppOpsOpCodes);
        if (ops != null && ops.size() > 0 && ops.get(0).getOps().size() > 0) {
            permissionState.appOpMode = ops.get(0).getOps().get(0).getMode();
        }
    } catch (RemoteException e) {
        Log.w(TAG, "PackageManager is dead. Can't get package info " + pkg, e);
    }
    return permissionState;
}
Also used : UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) PackageOps(android.app.AppOpsManager.PackageOps)

Aggregations

PackageOps (android.app.AppOpsManager.PackageOps)31 AppOpsManager (android.app.AppOpsManager)21 ApplicationInfo (android.content.pm.ApplicationInfo)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)14 PackageManager (android.content.pm.PackageManager)7 RemoteException (android.os.RemoteException)7 UserHandle (android.os.UserHandle)7 OpEntry (android.app.AppOpsManager.OpEntry)3 AttributedOpEntry (android.app.AppOpsManager.AttributedOpEntry)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 HiddenApi (org.robolectric.annotation.HiddenApi)2 Implementation (org.robolectric.annotation.Implementation)2 ArrayMap (android.util.ArrayMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1