MD5 校验值:290b0e4cd89c7a20355df0a13ec24559
PermissionDelegateImplV23.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.hjq.permissions; import android.app.Activity; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.os.PowerManager; import android.provider.Settings; public class PermissionDelegateImplV23 extends PermissionDelegateImplV21 { @Override public boolean isGrantedPermission(Context context, String str) { if (Permission.getPermissionFromAndroidVersion(str) > AndroidVersion.getAndroidVersionCode()) { if (PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_VISUAL_USER_SELECTED)) { return true; } if (PermissionUtils.equalsPermission(str, Permission.POST_NOTIFICATIONS)) { return super.isGrantedPermission(context, str); } if (PermissionUtils.equalsPermission(str, Permission.NEARBY_WIFI_DEVICES)) { return PermissionUtils.checkSelfPermission(context, Permission.ACCESS_FINE_LOCATION); } if (PermissionUtils.equalsPermission(str, Permission.BODY_SENSORS_BACKGROUND)) { return PermissionUtils.checkSelfPermission(context, Permission.BODY_SENSORS); } if (PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_IMAGES) || PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_VIDEO) || PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_AUDIO)) { return PermissionUtils.checkSelfPermission(context, Permission.READ_EXTERNAL_STORAGE); } if (PermissionUtils.equalsPermission(str, Permission.BLUETOOTH_SCAN)) { return PermissionUtils.checkSelfPermission(context, Permission.ACCESS_FINE_LOCATION); } if (PermissionUtils.equalsPermission(str, Permission.BLUETOOTH_CONNECT) || PermissionUtils.equalsPermission(str, Permission.BLUETOOTH_ADVERTISE)) { return true; } if (PermissionUtils.equalsPermission(str, Permission.MANAGE_EXTERNAL_STORAGE)) { return PermissionUtils.checkSelfPermission(context, Permission.READ_EXTERNAL_STORAGE) && PermissionUtils.checkSelfPermission(context, Permission.WRITE_EXTERNAL_STORAGE); } if (PermissionUtils.equalsPermission(str, Permission.ACCESS_BACKGROUND_LOCATION)) { return PermissionUtils.checkSelfPermission(context, Permission.ACCESS_FINE_LOCATION); } if (PermissionUtils.equalsPermission(str, Permission.ACTIVITY_RECOGNITION)) { return true; } if (PermissionUtils.equalsPermission(str, Permission.ACCESS_MEDIA_LOCATION)) { return PermissionUtils.checkSelfPermission(context, Permission.READ_EXTERNAL_STORAGE); } if (PermissionUtils.equalsPermission(str, Permission.ACCEPT_HANDOVER) || PermissionUtils.equalsPermission(str, Permission.ANSWER_PHONE_CALLS)) { return true; } if (PermissionUtils.equalsPermission(str, Permission.READ_PHONE_NUMBERS)) { return PermissionUtils.checkSelfPermission(context, Permission.READ_PHONE_STATE); } } if (PermissionUtils.equalsPermission(str, Permission.GET_INSTALLED_APPS) || PermissionUtils.equalsPermission(str, Permission.POST_NOTIFICATIONS)) { return super.isGrantedPermission(context, str); } if (Permission.isSpecialPermission(str)) { if (PermissionUtils.equalsPermission(str, Permission.WRITE_SETTINGS)) { return isGrantedSettingPermission(context); } if (PermissionUtils.equalsPermission(str, Permission.ACCESS_NOTIFICATION_POLICY)) { return isGrantedNotDisturbPermission(context); } if (PermissionUtils.equalsPermission(str, Permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { return isGrantedIgnoreBatteryPermission(context); } return super.isGrantedPermission(context, str); } return PermissionUtils.checkSelfPermission(context, str); } @Override public boolean isDoNotAskAgainPermission(Activity activity, String str) { if (Permission.getPermissionFromAndroidVersion(str) > AndroidVersion.getAndroidVersionCode()) { if (PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_VISUAL_USER_SELECTED)) { return false; } if (PermissionUtils.equalsPermission(str, Permission.POST_NOTIFICATIONS)) { return super.isDoNotAskAgainPermission(activity, str); } if (PermissionUtils.equalsPermission(str, Permission.NEARBY_WIFI_DEVICES)) { return (PermissionUtils.checkSelfPermission(activity, Permission.ACCESS_FINE_LOCATION) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.ACCESS_FINE_LOCATION)) ? false : true; } if (PermissionUtils.equalsPermission(str, Permission.BODY_SENSORS_BACKGROUND)) { return (PermissionUtils.checkSelfPermission(activity, Permission.BODY_SENSORS) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.BODY_SENSORS)) ? false : true; } if (PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_IMAGES) || PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_VIDEO) || PermissionUtils.equalsPermission(str, Permission.READ_MEDIA_AUDIO)) { return (PermissionUtils.checkSelfPermission(activity, Permission.READ_EXTERNAL_STORAGE) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.READ_EXTERNAL_STORAGE)) ? false : true; } if (PermissionUtils.equalsPermission(str, Permission.BLUETOOTH_SCAN)) { return (PermissionUtils.checkSelfPermission(activity, Permission.ACCESS_FINE_LOCATION) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.ACCESS_FINE_LOCATION)) ? false : true; } if (PermissionUtils.equalsPermission(str, Permission.BLUETOOTH_CONNECT) || PermissionUtils.equalsPermission(str, Permission.BLUETOOTH_ADVERTISE)) { return false; } if (PermissionUtils.equalsPermission(str, Permission.ACCESS_BACKGROUND_LOCATION)) { return (PermissionUtils.checkSelfPermission(activity, Permission.ACCESS_FINE_LOCATION) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.ACCESS_FINE_LOCATION)) ? false : true; } if (PermissionUtils.equalsPermission(str, Permission.ACTIVITY_RECOGNITION)) { return false; } if (PermissionUtils.equalsPermission(str, Permission.ACCESS_MEDIA_LOCATION)) { return (PermissionUtils.checkSelfPermission(activity, Permission.READ_EXTERNAL_STORAGE) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.READ_EXTERNAL_STORAGE)) ? false : true; } if (PermissionUtils.equalsPermission(str, Permission.ACCEPT_HANDOVER) || PermissionUtils.equalsPermission(str, Permission.ANSWER_PHONE_CALLS)) { return false; } if (PermissionUtils.equalsPermission(str, Permission.READ_PHONE_NUMBERS)) { return (PermissionUtils.checkSelfPermission(activity, Permission.READ_PHONE_STATE) || PermissionUtils.shouldShowRequestPermissionRationale(activity, Permission.READ_PHONE_STATE)) ? false : true; } } if (PermissionUtils.equalsPermission(str, Permission.GET_INSTALLED_APPS) || PermissionUtils.equalsPermission(str, Permission.POST_NOTIFICATIONS)) { return super.isDoNotAskAgainPermission(activity, str); } return (Permission.isSpecialPermission(str) || PermissionUtils.checkSelfPermission(activity, str) || PermissionUtils.shouldShowRequestPermissionRationale(activity, str)) ? false : true; } @Override public Intent getPermissionIntent(Context context, String str) { if (PermissionUtils.equalsPermission(str, Permission.WRITE_SETTINGS)) { return getSettingPermissionIntent(context); } if (PermissionUtils.equalsPermission(str, Permission.ACCESS_NOTIFICATION_POLICY)) { return getNotDisturbPermissionIntent(context); } if (PermissionUtils.equalsPermission(str, Permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { return getIgnoreBatteryPermissionIntent(context); } return super.getPermissionIntent(context, str); } private static boolean isGrantedSettingPermission(Context context) { boolean canWrite; if (!AndroidVersion.isAndroid6()) { return true; } canWrite = Settings.System.canWrite(context); return canWrite; } private static Intent getSettingPermissionIntent(Context context) { Intent intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS"); intent.setData(PermissionUtils.getPackageNameUri(context)); return !PermissionUtils.areActivityIntent(context, intent) ? PermissionIntentManager.getApplicationDetailsIntent(context) : intent; } private static boolean isGrantedNotDisturbPermission(Context context) { Object systemService; boolean isNotificationPolicyAccessGranted; systemService = context.getSystemService((Class<Object>) NotificationManager.class); isNotificationPolicyAccessGranted = ((NotificationManager) systemService).isNotificationPolicyAccessGranted(); return isNotificationPolicyAccessGranted; } private static Intent getNotDisturbPermissionIntent(Context context) { Intent intent; if (AndroidVersion.isAndroid10()) { intent = new Intent("android.settings.NOTIFICATION_POLICY_ACCESS_DETAIL_SETTINGS"); intent.setData(PermissionUtils.getPackageNameUri(context)); if (PhoneRomUtils.isHarmonyOs() || PhoneRomUtils.isMagicOs()) { intent = new Intent("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS"); } } else { intent = new Intent("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS"); } return !PermissionUtils.areActivityIntent(context, intent) ? PermissionIntentManager.getApplicationDetailsIntent(context) : intent; } private static boolean isGrantedIgnoreBatteryPermission(Context context) { Object systemService; boolean isIgnoringBatteryOptimizations; systemService = context.getSystemService((Class<Object>) PowerManager.class); isIgnoringBatteryOptimizations = ((PowerManager) systemService).isIgnoringBatteryOptimizations(context.getPackageName()); return isIgnoringBatteryOptimizations; } private static Intent getIgnoreBatteryPermissionIntent(Context context) { Intent intent = new Intent("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"); intent.setData(PermissionUtils.getPackageNameUri(context)); if (!PermissionUtils.areActivityIntent(context, intent)) { intent = new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"); } return !PermissionUtils.areActivityIntent(context, intent) ? PermissionIntentManager.getApplicationDetailsIntent(context) : intent; } }