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);
}
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);
}
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;
}
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));
}
}
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);
}
Aggregations