當前位置: 首頁>>代碼示例>>Java>>正文


Java AppOpsManager類代碼示例

本文整理匯總了Java中android.app.AppOpsManager的典型用法代碼示例。如果您正苦於以下問題:Java AppOpsManager類的具體用法?Java AppOpsManager怎麽用?Java AppOpsManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AppOpsManager類屬於android.app包,在下文中一共展示了AppOpsManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: usagePermissionCheck

import android.app.AppOpsManager; //導入依賴的package包/類
public static boolean usagePermissionCheck(Context context) {
    boolean granted = false;
    if (context != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        try {
            AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
            int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), context.getPackageName());
            if (mode == AppOpsManager.MODE_DEFAULT) {
                String permissionUsage = "android.permission.PACKAGE_USAGE_STATS";
                granted = (context.checkCallingOrSelfPermission(permissionUsage) == PackageManager.PERMISSION_GRANTED);
            } else {
                granted = (mode == AppOpsManager.MODE_ALLOWED);
            }
        } catch (Throwable e) {
        }
    }
    return granted;
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:18,代碼來源:PackageUsageHelper.java

示例2: checkOp

import android.app.AppOpsManager; //導入依賴的package包/類
@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:17,代碼來源:QMUIDeviceHelper.java

示例3: checkAlertWindowsPermission

import android.app.AppOpsManager; //導入依賴的package包/類
public static boolean checkAlertWindowsPermission(Context context) {
    try {
        Object object = context.getSystemService(Context.APP_OPS_SERVICE);
        if (object == null) {
            return false;
        }
        Class localClass = object.getClass();
        Class[] arrayOfClass = new Class[3];
        arrayOfClass[0] = Integer.TYPE;
        arrayOfClass[1] = Integer.TYPE;
        arrayOfClass[2] = String.class;
        Method method = localClass.getMethod("checkOp", arrayOfClass);
        if (method == null) {
            return false;
        }
        Object[] arrayOfObject1 = new Object[3];
        arrayOfObject1[0] = 24;
        arrayOfObject1[1] = Binder.getCallingUid();
        arrayOfObject1[2] = context.getPackageName();
        int m = ((Integer) method.invoke(object, arrayOfObject1));
        return m == AppOpsManager.MODE_ALLOWED;
    } catch (Exception ex) {

    }
    return false;
}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:27,代碼來源:testThread.java

示例4: checkOp

import android.app.AppOpsManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:MeizuUtils.java

示例5: checkOp

import android.app.AppOpsManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:MiuiUtils.java

示例6: checkOp

import android.app.AppOpsManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:QikuUtils.java

示例7: checkOp

import android.app.AppOpsManager; //導入依賴的package包/類
@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
    }
    return false;
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:18,代碼來源:QMUIDeviceHelper.java

示例8: hasPermissions

import android.app.AppOpsManager; //導入依賴的package包/類
/**
 * Check if the calling context has a set of permissions.
 *
 * @param context     The calling context
 * @param permissions One or more permission.
 * @return True if all permissions are already granted, false if at least one permission is not
 * yet granted.
 * @see android.Manifest.permission
 */
public static boolean hasPermissions(@NonNull Context context,
                                     @NonNull @Size(min = 1) String... permissions) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return true;
    }

    final AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);
    final String packageName = context.getPackageName();
    for (String permission : permissions) {
        if (ContextCompat.checkSelfPermission(context, permission)
                != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        String op = AppOpsManager.permissionToOp(permission);
        if (!TextUtils.isEmpty(op) && appOpsManager != null
                && appOpsManager.noteProxyOp(op, packageName) != AppOpsManager.MODE_ALLOWED) {
            return false;
        }
    }
    return true;
}
 
開發者ID:parkingwang,項目名稱:hey-permission,代碼行數:31,代碼來源:HeyPermission.java

示例9: HavaPermissionForTest

import android.app.AppOpsManager; //導入依賴的package包/類
/**
 * 判斷是否有用權限
 *
 * @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 = 0;
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName);
        }
        return (mode == AppOpsManager.MODE_ALLOWED);
    } catch (PackageManager.NameNotFoundException e)
    {
        return true;
    }
}
 
開發者ID:heipidage,項目名稱:GcmForMojo,代碼行數:25,代碼來源:MessageUtil.java

示例10: isMockLocationEnabled

import android.app.AppOpsManager; //導入依賴的package包/類
private boolean isMockLocationEnabled() {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            AppOpsManager opsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
            return (opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION,
                    android.os.Process.myUid(),
                    BuildConfig.APPLICATION_ID)
                    == AppOpsManager.MODE_ALLOWED);
        } else {
            String mockLocationSettingValue = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION);
            return (mockLocationSettingValue.equals(ENABLED_MOCK_LOCATION_VALUE));
        }
    } catch (SecurityException e) {
        return false;
    }
}
 
開發者ID:MusalaSoft,項目名稱:atmosphere-service,代碼行數:17,代碼來源:LocationMockHandler.java

示例11: onOptionsItemSelected

import android.app.AppOpsManager; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case android.R.id.home:
      finish();
      return true;
    case R.id.action_reset:
      mPresenter.reset();
      return true;
    case R.id.action_hide_perm:
      showHidePerms();
      return true;
    case R.id.action_open_all:
      changeAll(AppOpsManager.MODE_ALLOWED);
      ATracker.send(AEvent.C_APP_OPEN_ALL);
      break;
    case R.id.action_close_all:
      changeAll(AppOpsManager.MODE_IGNORED);
      ATracker.send(AEvent.C_APP_IGNOR_ALL);
      break;
    case R.id.action_app_info:
      startAppinfo();
      break;
  }
  return super.onOptionsItemSelected(item);
}
 
開發者ID:8enet,項目名稱:AppOpsX,代碼行數:27,代碼來源:AppPermissionActivity.java

示例12: disableAllPermission

import android.app.AppOpsManager; //導入依賴的package包/類
public OpsResult disableAllPermission(final String packageName) throws Exception {
  OpsResult opsForPackage = getOpsForPackage(packageName);
  if (opsForPackage != null) {
    if (opsForPackage.getException() == null) {
      List<PackageOps> list = opsForPackage.getList();
      if (list != null && !list.isEmpty()) {
        for (PackageOps packageOps : list) {
          List<OpEntry> ops = packageOps.getOps();
          if (ops != null) {
            for (OpEntry op : ops) {
              if (op.getMode() != AppOpsManager.MODE_IGNORED) {
                setOpsMode(packageName, op.getOp(), AppOpsManager.MODE_IGNORED);
              }
            }
          }
        }
      }
    } else {
      throw new Exception(opsForPackage.getException());
    }
  }
  return opsForPackage;
}
 
開發者ID:8enet,項目名稱:AppOpsX,代碼行數:24,代碼來源:OpsxManager.java

示例13: permissionToCode

import android.app.AppOpsManager; //導入依賴的package包/類
static int permissionToCode(String permission) {
  if (sRuntimePermToOp == null) {
    sRuntimePermToOp = new HashMap<>();
    Object sOpPerms = ReflectUtils.getFieldValue(AppOpsManager.class, "sOpPerms");
    Object sOpToSwitch = ReflectUtils.getFieldValue(AppOpsManager.class, "sOpToSwitch");

    if (sOpPerms instanceof String[] && sOpToSwitch instanceof int[]) {
      String[] opPerms = (String[]) sOpPerms;
      int[] opToSwitch = (int[]) sOpToSwitch;

      if (opPerms.length == opToSwitch.length) {
        for (int i = 0; i < opToSwitch.length; i++) {
          if (opPerms[i] != null) {
            sRuntimePermToOp.put(opPerms[i], opToSwitch[i]);
          }
        }
      }
    }
  }
  Integer code = sRuntimePermToOp.get(permission);
  if (code != null) {
    return code;
  }
  return -1;
}
 
開發者ID:8enet,項目名稱:AppOpsX,代碼行數:26,代碼來源:Helper.java

示例14: hasAuthorFloatWin

import android.app.AppOpsManager; //導入依賴的package包/類
/**
 * 判斷是否開啟浮窗權限
 * @return
 */
public static int hasAuthorFloatWin(Context context){

    if (DeviceInfoUtil.getSystemVersion() < 19){
        return NOT_SUPPORT_AUTHOR;
    }
    try {
        AppOpsManager appOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
        Class c = appOps.getClass();
        Class[] cArg = new Class[3];
        cArg[0] = int.class;
        cArg[1] = int.class;
        cArg[2] = String.class;
        Method lMethod = c.getDeclaredMethod("checkOp", cArg);
        if (AppOpsManager.MODE_ALLOWED == (Integer) lMethod.invoke(appOps, 24, Binder.getCallingUid(), context.getPackageName())){
            return HAS_AUTHOR;
        } else {
            return NOT_AUTHOR;
        }

    } catch(Exception e) {
       return NOT_SUPPORT_AUTHOR;
    }

}
 
開發者ID:liuguangli,項目名稱:FloatUtil,代碼行數:29,代碼來源:SmartFloatUtil.java

示例15: isPermissionGranted

import android.app.AppOpsManager; //導入依賴的package包/類
public static boolean isPermissionGranted(@NonNull Context context) {
    if(!"Xiaomi".equalsIgnoreCase(Build.MANUFACTURER)) {
        return true;
    }
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, 24/*AppOpsManager.OP_SYSTEM_ALERT_WINDOW*/,
                    Binder.getCallingUid(), context.getApplicationContext().getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        }catch (Throwable e) {
            WXLogUtils.e(TAG,e.getMessage());
            return true;
        }
    } else {
        return true;
    }
}
 
開發者ID:weexteam,項目名稱:weex-analyzer-android,代碼行數:20,代碼來源:XiaomiOverlayViewPermissionHelper.java


注:本文中的android.app.AppOpsManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。