当前位置: 首页>>代码示例>>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;未经允许,请勿转载。