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