Skip to content

Commit

Permalink
修复oppo手机Security异常
Browse files Browse the repository at this point in the history
  • Loading branch information
liyong committed Oct 15, 2018
1 parent b23c552 commit 94ea4bb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/src/main/java/com/allen/android/lib/PermissionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ public static boolean hasPermission(@NonNull Context context, @NonNull String pe
public static boolean hasPermission(@NonNull Context context, @NonNull List<String> permissions) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true;
for (String permission : permissions) {
String op = AppOpsManagerCompat.permissionToOp(permission);
if (TextUtils.isEmpty(op)) continue;
int result = AppOpsManagerCompat.noteOp(context, op, android.os.Process.myUid(), context.getPackageName());
if (result == AppOpsManagerCompat.MODE_IGNORED) return false;
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
String ops = AppOpsManager.permissionToOp(permission);
int locationOp = appOpsManager.checkOp(ops, Binder.getCallingUid(), context.getPackageName());
if (locationOp == AppOpsManager.MODE_IGNORED) return false;
result = ContextCompat.checkSelfPermission(context, permission);
if (result != PackageManager.PERMISSION_GRANTED) return false;
try {
String op = AppOpsManagerCompat.permissionToOp(permission);
if (TextUtils.isEmpty(op)) continue;
int result = AppOpsManagerCompat.noteOp(context, op, android.os.Process.myUid(), context.getPackageName());
if (result == AppOpsManagerCompat.MODE_IGNORED) return false;
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
String ops = AppOpsManager.permissionToOp(permission);
int locationOp = appOpsManager.checkOp(ops, Binder.getCallingUid(), context.getPackageName());
if (locationOp == AppOpsManager.MODE_IGNORED) return false;
result = ContextCompat.checkSelfPermission(context, permission);
if (result != PackageManager.PERMISSION_GRANTED) return false;
} catch (Exception ex) {
Log.e(TAG, "[hasPermission] error ", ex);
}
}
return true;
}
Expand Down

0 comments on commit 94ea4bb

Please sign in to comment.