2828 */
2929public abstract class BasePermission implements IPermission {
3030
31+ /** Op 权限模式:未知模式 */
32+ public static final int MODE_UNKNOWN = -1 ;
33+
3134 protected BasePermission () {
3235 // default implementation ignored
3336 }
@@ -269,7 +272,7 @@ public static boolean shouldShowRequestPermissionRationale(@NonNull Activity act
269272 @ RequiresApi (PermissionVersion .ANDROID_4_4 )
270273 public static boolean checkOpPermission (@ NonNull Context context , @ NonNull String opName , boolean defaultGranted ) {
271274 int opMode = getOpPermissionMode (context , opName );
272- if (opMode == AppOpsManager . MODE_ERRORED ) {
275+ if (opMode == MODE_UNKNOWN ) {
273276 return defaultGranted ;
274277 }
275278 return opMode == AppOpsManager .MODE_ALLOWED ;
@@ -285,7 +288,7 @@ public static boolean checkOpPermission(@NonNull Context context, @NonNull Strin
285288 @ RequiresApi (PermissionVersion .ANDROID_4_4 )
286289 public static boolean checkOpPermission (Context context , String opFieldName , int opDefaultValue , boolean defaultGranted ) {
287290 int opMode = getOpPermissionMode (context , opFieldName , opDefaultValue );
288- if (opMode == AppOpsManager . MODE_ERRORED ) {
291+ if (opMode == MODE_UNKNOWN ) {
289292 return defaultGranted ;
290293 }
291294 return opMode == AppOpsManager .MODE_ALLOWED ;
@@ -307,7 +310,7 @@ public static int getOpPermissionMode(@NonNull Context context, @NonNull String
307310 }
308311 // 虽然这个 SystemService 永远不为空,但是不怕一万,就怕万一,开展防御性编程
309312 if (appOpsManager == null ) {
310- return AppOpsManager . MODE_ERRORED ;
313+ return MODE_UNKNOWN ;
311314 }
312315 try {
313316 if (PermissionVersion .isAndroid10 ()) {
@@ -317,7 +320,7 @@ public static int getOpPermissionMode(@NonNull Context context, @NonNull String
317320 }
318321 } catch (Throwable e ) {
319322 e .printStackTrace ();
320- return AppOpsManager . MODE_ERRORED ;
323+ return MODE_UNKNOWN ;
321324 }
322325 }
323326
@@ -338,7 +341,7 @@ public static int getOpPermissionMode(Context context, @NonNull String opName, i
338341 }
339342 // 虽然这个 SystemService 永远不为空,但是不怕一万,就怕万一,开展防御性编程
340343 if (appOpsManager == null ) {
341- return AppOpsManager . MODE_ERRORED ;
344+ return MODE_UNKNOWN ;
342345 }
343346 try {
344347 Class <?> appOpsClass = Class .forName (AppOpsManager .class .getName ());
@@ -353,7 +356,7 @@ public static int getOpPermissionMode(Context context, @NonNull String opName, i
353356 return ((int ) checkOpNoThrowMethod .invoke (appOpsManager , opValue , context .getApplicationInfo ().uid , context .getPackageName ()));
354357 } catch (Exception e ) {
355358 e .printStackTrace ();
356- return AppOpsManager . MODE_ERRORED ;
359+ return MODE_UNKNOWN ;
357360 }
358361 }
359362
0 commit comments