use of android.app.AppOpsManager in project AndroidProcess by wenmingvs.
the class BackgroundUtil method HavaPermissionForTest.
/**
* 判断是否有用权限
*
* @param context 上下文参数
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean HavaPermissionForTest(Context context) {
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName);
return (mode == AppOpsManager.MODE_ALLOWED);
} catch (PackageManager.NameNotFoundException e) {
return true;
}
}
use of android.app.AppOpsManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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 Resurrection_packages_apps_Settings by ResurrectionRemix.
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 MLib by DaoBillTang.
the class SystemUtils method havaPermissionForTest.
/**
* 判断是否有用权限
*
* @param context 上下文参数
*/
@TargetApi(19)
private static boolean havaPermissionForTest(Context context) {
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName);
return (mode == AppOpsManager.MODE_ALLOWED);
} catch (PackageManager.NameNotFoundException e) {
return true;
}
}
use of android.app.AppOpsManager in project platform_frameworks_base by android.
the class RecentLocationApps method getAppList.
/**
* Fills a list of applications which queried location recently within specified time.
*/
public List<Request> getAppList() {
// Retrieve a location usage list from AppOps
AppOpsManager aoManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(LOCATION_OPS);
final int appOpsCount = appOps != null ? appOps.size() : 0;
// Process the AppOps list and generate a preference list.
ArrayList<Request> requests = new ArrayList<>(appOpsCount);
final long now = System.currentTimeMillis();
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final List<UserHandle> profiles = um.getUserProfiles();
for (int i = 0; i < appOpsCount; ++i) {
AppOpsManager.PackageOps ops = appOps.get(i);
// Don't show the Android System in the list - it's not actionable for the user.
// Also don't show apps belonging to background users except managed users.
String packageName = ops.getPackageName();
int uid = ops.getUid();
int userId = UserHandle.getUserId(uid);
boolean isAndroidOs = (uid == Process.SYSTEM_UID) && ANDROID_SYSTEM_PACKAGE_NAME.equals(packageName);
if (isAndroidOs || !profiles.contains(new UserHandle(userId))) {
continue;
}
Request request = getRequestFromOps(now, ops);
if (request != null) {
requests.add(request);
}
}
return requests;
}
Aggregations