本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}