List of usage examples for android.app AppOpsManager checkOp
@UnsupportedAppUsage public int checkOp(int op, int uid, String packageName)
From source file:Main.java
@SuppressWarnings("IncompatibleBitwiseMaskOperation") public static boolean isFloatWindowOpAllowed(Context context) { if (Build.VERSION.SDK_INT >= 19) { // 19, 4.4, KITKAT final AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); final int mode = manager.checkOp(AppOpsManager.OPSTR_SYSTEM_ALERT_WINDOW, Binder.getCallingUid(), context.getPackageName()); return AppOpsManager.MODE_ALLOWED == mode; } else {/*from ww w . j a v a2 s . c o m*/ return (context.getApplicationInfo().flags & 1 << 27) == 1; } }
From source file:com.dena.app.usage.watcher.service.WatchService.java
public void onCreate() { super.onCreate(); try {/*from w w w. j a v a2 s . c om*/ final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); mTimer = new Timer(true); mTimer.scheduleAtFixedRate(new TimerTask() { @TargetApi(Build.VERSION_CODES.KITKAT) public void run() { if (WatchUtil.isScreenLocked(WatchService.this)) { return; } try { WatchDatabase db = ((App) getApplication()).getDatabase(); if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT) { AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); if (null != appOpsManager && AppOpsManager.MODE_ALLOWED != appOpsManager.checkOp( AppOpsManager.OPSTR_GET_USAGE_STATS, packageInfo.applicationInfo.uid, getPackageName())) { Intent intent = new Intent(getApplicationContext(), DialogActivity.class); intent.addFlags(WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); startActivity(intent); return; } } long time = System.currentTimeMillis(); String packageName = WatchUtil.getTopPackageName(WatchService.this); if (null != packageName) { db.addUsageAt(time, packageName); db.addUsageAt(time); } } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } } }, 0L, 1000L); startForeground(R.mipmap.ic_launcher, buildNotification()); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } }
From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java
public boolean isMockLocationEnabled() { // Checks if mock location is enabled in settings boolean isMockLocation; try {//from ww w . j a v a 2s . com //If marshmallow or higher then we need to check that this app is set as the provider if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { AppOpsManager opsManager = (AppOpsManager) appContext.getSystemService(Context.APP_OPS_SERVICE); isMockLocation = opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, android.os.Process.myUid(), BuildConfig.APPLICATION_ID) == AppOpsManager.MODE_ALLOWED; } else { // Anything below it then we just need to check the tickbox is checked. isMockLocation = !android.provider.Settings.Secure .getString(appContext.getContentResolver(), "mock_location").equals("0"); } } catch (Exception e) { return false; } return isMockLocation; }