package com.baseflow.permissionhandler; import android.app.Activity; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Environment; import androidx.core.app.ActivityCompat; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; /* loaded from: classes.dex */ public class PermissionUtils { static final String SHARED_PREFERENCES_PERMISSION_WAS_DENIED_BEFORE_KEY = "sp_permission_handler_permission_was_denied_before"; /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */ public static int parseManifestName(String str) { char c; str.hashCode(); switch (str.hashCode()) { case -2062386608: if (str.equals("android.permission.READ_SMS")) { c = 0; break; } c = 65535; break; case -1928411001: if (str.equals("android.permission.READ_CALENDAR")) { c = 1; break; } c = 65535; break; case -1925850455: if (str.equals("android.permission.POST_NOTIFICATIONS")) { c = 2; break; } c = 65535; break; case -1921431796: if (str.equals("android.permission.READ_CALL_LOG")) { c = 3; break; } c = 65535; break; case -1888586689: if (str.equals("android.permission.ACCESS_FINE_LOCATION")) { c = 4; break; } c = 65535; break; case -1813079487: if (str.equals("android.permission.MANAGE_EXTERNAL_STORAGE")) { c = 5; break; } c = 65535; break; case -1783097621: if (str.equals("android.permission.ACCESS_NOTIFICATION_POLICY")) { c = 6; break; } c = 65535; break; case -1561629405: if (str.equals("android.permission.SYSTEM_ALERT_WINDOW")) { c = 7; break; } c = 65535; break; case -1479758289: if (str.equals("android.permission.RECEIVE_WAP_PUSH")) { c = '\b'; break; } c = 65535; break; case -1238066820: if (str.equals("android.permission.BODY_SENSORS")) { c = '\t'; break; } c = 65535; break; case -1164582768: if (str.equals("android.permission.READ_PHONE_NUMBERS")) { c = '\n'; break; } c = 65535; break; case -909527021: if (str.equals("android.permission.NEARBY_WIFI_DEVICES")) { c = 11; break; } c = 65535; break; case -901151997: if (str.equals("android.permission.BIND_CALL_REDIRECTION_SERVICE")) { c = '\f'; break; } c = 65535; break; case -895679497: if (str.equals("android.permission.RECEIVE_MMS")) { c = '\r'; break; } c = 65535; break; case -895673731: if (str.equals("android.permission.RECEIVE_SMS")) { c = 14; break; } c = 65535; break; case -798669607: if (str.equals("android.permission.BLUETOOTH_CONNECT")) { c = 15; break; } c = 65535; break; case -406040016: if (str.equals("android.permission.READ_EXTERNAL_STORAGE")) { c = 16; break; } c = 65535; break; case -63024214: if (str.equals("android.permission.ACCESS_COARSE_LOCATION")) { c = 17; break; } c = 65535; break; case -5573545: if (str.equals("android.permission.READ_PHONE_STATE")) { c = 18; break; } c = 65535; break; case 52602690: if (str.equals("android.permission.SEND_SMS")) { c = 19; break; } c = 65535; break; case 112197485: if (str.equals("android.permission.CALL_PHONE")) { c = 20; break; } c = 65535; break; case 175802396: if (str.equals("android.permission.READ_MEDIA_IMAGES")) { c = 21; break; } c = 65535; break; case 214526995: if (str.equals("android.permission.WRITE_CONTACTS")) { c = 22; break; } c = 65535; break; case 361658321: if (str.equals("android.permission.BODY_SENSORS_BACKGROUND")) { c = 23; break; } c = 65535; break; case 463403621: if (str.equals("android.permission.CAMERA")) { c = 24; break; } c = 65535; break; case 603653886: if (str.equals("android.permission.WRITE_CALENDAR")) { c = 25; break; } c = 65535; break; case 610633091: if (str.equals("android.permission.WRITE_CALL_LOG")) { c = 26; break; } c = 65535; break; case 691260818: if (str.equals("android.permission.READ_MEDIA_AUDIO")) { c = 27; break; } c = 65535; break; case 710297143: if (str.equals("android.permission.READ_MEDIA_VIDEO")) { c = 28; break; } c = 65535; break; case 784519842: if (str.equals("android.permission.USE_SIP")) { c = 29; break; } c = 65535; break; case 970694249: if (str.equals("android.permission.SCHEDULE_EXACT_ALARM")) { c = 30; break; } c = 65535; break; case 1166454870: if (str.equals("android.permission.BLUETOOTH_ADVERTISE")) { c = 31; break; } c = 65535; break; case 1271781903: if (str.equals("android.permission.GET_ACCOUNTS")) { c = ' '; break; } c = 65535; break; case 1365911975: if (str.equals("android.permission.WRITE_EXTERNAL_STORAGE")) { c = '!'; break; } c = 65535; break; case 1777263169: if (str.equals("android.permission.REQUEST_INSTALL_PACKAGES")) { c = '\"'; break; } c = 65535; break; case 1780337063: if (str.equals("android.permission.ACTIVITY_RECOGNITION")) { c = '#'; break; } c = 65535; break; case 1831139720: if (str.equals("android.permission.RECORD_AUDIO")) { c = '$'; break; } c = 65535; break; case 1977429404: if (str.equals("android.permission.READ_CONTACTS")) { c = '%'; break; } c = 65535; break; case 2024715147: if (str.equals("android.permission.ACCESS_BACKGROUND_LOCATION")) { c = '&'; break; } c = 65535; break; case 2062356686: if (str.equals("android.permission.BLUETOOTH_SCAN")) { c = '\''; break; } c = 65535; break; case 2114579147: if (str.equals("android.permission.ACCESS_MEDIA_LOCATION")) { c = '('; break; } c = 65535; break; case 2133799037: if (str.equals("com.android.voicemail.permission.ADD_VOICEMAIL")) { c = ')'; break; } c = 65535; break; default: c = 65535; break; } switch (c) { case 0: case '\b': case '\r': case 14: case 19: return 13; case 1: case 25: return 0; case 2: return 17; case 3: case '\n': case '\f': case 18: case 20: case 26: case 29: case ')': return 8; case 4: case 17: return 3; case 5: return 22; case 6: return 27; case 7: return 23; case '\t': return 12; case 11: return 31; case 15: return 30; case 16: case '!': return 15; case 21: return 9; case 22: case ' ': case '%': return 2; case 23: return 35; case 24: return 1; case 27: return 33; case 28: return 32; case 30: return 34; case 31: return 29; case '\"': return 24; case '#': return 19; case '$': return 7; case '&': return 4; case '\'': return 28; case '(': return 18; default: return 20; } } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */ public static List getManifestNames(Context context, int i) { ArrayList arrayList = new ArrayList(); switch (i) { case 0: if (hasPermissionInManifest(context, arrayList, "android.permission.READ_CALENDAR")) { arrayList.add("android.permission.READ_CALENDAR"); } if (hasPermissionInManifest(context, arrayList, "android.permission.WRITE_CALENDAR")) { arrayList.add("android.permission.WRITE_CALENDAR"); } return arrayList; case 1: if (hasPermissionInManifest(context, arrayList, "android.permission.CAMERA")) { arrayList.add("android.permission.CAMERA"); } return arrayList; case 2: if (hasPermissionInManifest(context, arrayList, "android.permission.READ_CONTACTS")) { arrayList.add("android.permission.READ_CONTACTS"); } if (hasPermissionInManifest(context, arrayList, "android.permission.WRITE_CONTACTS")) { arrayList.add("android.permission.WRITE_CONTACTS"); } if (hasPermissionInManifest(context, arrayList, "android.permission.GET_ACCOUNTS")) { arrayList.add("android.permission.GET_ACCOUNTS"); } return arrayList; case 3: case 4: case 5: if (i == 4 && Build.VERSION.SDK_INT >= 29) { if (hasPermissionInManifest(context, arrayList, "android.permission.ACCESS_BACKGROUND_LOCATION")) { arrayList.add("android.permission.ACCESS_BACKGROUND_LOCATION"); } } else { if (hasPermissionInManifest(context, arrayList, "android.permission.ACCESS_COARSE_LOCATION")) { arrayList.add("android.permission.ACCESS_COARSE_LOCATION"); } if (hasPermissionInManifest(context, arrayList, "android.permission.ACCESS_FINE_LOCATION")) { arrayList.add("android.permission.ACCESS_FINE_LOCATION"); } } return arrayList; case 6: case 11: case 20: return null; case 7: case 14: if (hasPermissionInManifest(context, arrayList, "android.permission.RECORD_AUDIO")) { arrayList.add("android.permission.RECORD_AUDIO"); } return arrayList; case 8: if (hasPermissionInManifest(context, arrayList, "android.permission.READ_PHONE_STATE")) { arrayList.add("android.permission.READ_PHONE_STATE"); } if (Build.VERSION.SDK_INT > 29 && hasPermissionInManifest(context, arrayList, "android.permission.READ_PHONE_NUMBERS")) { arrayList.add("android.permission.READ_PHONE_NUMBERS"); } if (hasPermissionInManifest(context, arrayList, "android.permission.CALL_PHONE")) { arrayList.add("android.permission.CALL_PHONE"); } if (hasPermissionInManifest(context, arrayList, "android.permission.READ_CALL_LOG")) { arrayList.add("android.permission.READ_CALL_LOG"); } if (hasPermissionInManifest(context, arrayList, "android.permission.WRITE_CALL_LOG")) { arrayList.add("android.permission.WRITE_CALL_LOG"); } if (hasPermissionInManifest(context, arrayList, "com.android.voicemail.permission.ADD_VOICEMAIL")) { arrayList.add("com.android.voicemail.permission.ADD_VOICEMAIL"); } if (hasPermissionInManifest(context, arrayList, "android.permission.USE_SIP")) { arrayList.add("android.permission.USE_SIP"); } if (Build.VERSION.SDK_INT >= 29 && hasPermissionInManifest(context, arrayList, "android.permission.BIND_CALL_REDIRECTION_SERVICE")) { arrayList.add("android.permission.BIND_CALL_REDIRECTION_SERVICE"); } if (hasPermissionInManifest(context, arrayList, "android.permission.ANSWER_PHONE_CALLS")) { arrayList.add("android.permission.ANSWER_PHONE_CALLS"); } return arrayList; case 9: if (Build.VERSION.SDK_INT >= 33 && hasPermissionInManifest(context, arrayList, "android.permission.READ_MEDIA_IMAGES")) { arrayList.add("android.permission.READ_MEDIA_IMAGES"); } return arrayList; case 10: case 25: case 26: default: return arrayList; case 12: if (hasPermissionInManifest(context, arrayList, "android.permission.BODY_SENSORS")) { arrayList.add("android.permission.BODY_SENSORS"); } return arrayList; case 13: if (hasPermissionInManifest(context, arrayList, "android.permission.SEND_SMS")) { arrayList.add("android.permission.SEND_SMS"); } if (hasPermissionInManifest(context, arrayList, "android.permission.RECEIVE_SMS")) { arrayList.add("android.permission.RECEIVE_SMS"); } if (hasPermissionInManifest(context, arrayList, "android.permission.READ_SMS")) { arrayList.add("android.permission.READ_SMS"); } if (hasPermissionInManifest(context, arrayList, "android.permission.RECEIVE_WAP_PUSH")) { arrayList.add("android.permission.RECEIVE_WAP_PUSH"); } if (hasPermissionInManifest(context, arrayList, "android.permission.RECEIVE_MMS")) { arrayList.add("android.permission.RECEIVE_MMS"); } return arrayList; case 15: if (hasPermissionInManifest(context, arrayList, "android.permission.READ_EXTERNAL_STORAGE")) { arrayList.add("android.permission.READ_EXTERNAL_STORAGE"); } if ((Build.VERSION.SDK_INT < 29 || (Build.VERSION.SDK_INT == 29 && Environment.isExternalStorageLegacy())) && hasPermissionInManifest(context, arrayList, "android.permission.WRITE_EXTERNAL_STORAGE")) { arrayList.add("android.permission.WRITE_EXTERNAL_STORAGE"); } return arrayList; case 16: if (hasPermissionInManifest(context, arrayList, "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS")) { arrayList.add("android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"); } return arrayList; case 17: if (Build.VERSION.SDK_INT >= 33 && hasPermissionInManifest(context, arrayList, "android.permission.POST_NOTIFICATIONS")) { arrayList.add("android.permission.POST_NOTIFICATIONS"); } return arrayList; case 18: if (Build.VERSION.SDK_INT < 29) { return null; } if (hasPermissionInManifest(context, arrayList, "android.permission.ACCESS_MEDIA_LOCATION")) { arrayList.add("android.permission.ACCESS_MEDIA_LOCATION"); } return arrayList; case 19: if (Build.VERSION.SDK_INT < 29) { return null; } if (hasPermissionInManifest(context, arrayList, "android.permission.ACTIVITY_RECOGNITION")) { arrayList.add("android.permission.ACTIVITY_RECOGNITION"); } return arrayList; case 21: if (hasPermissionInManifest(context, arrayList, "android.permission.BLUETOOTH")) { arrayList.add("android.permission.BLUETOOTH"); } return arrayList; case 22: if (Build.VERSION.SDK_INT >= 30 && hasPermissionInManifest(context, arrayList, "android.permission.MANAGE_EXTERNAL_STORAGE")) { arrayList.add("android.permission.MANAGE_EXTERNAL_STORAGE"); } return arrayList; case 23: if (hasPermissionInManifest(context, arrayList, "android.permission.SYSTEM_ALERT_WINDOW")) { arrayList.add("android.permission.SYSTEM_ALERT_WINDOW"); } return arrayList; case 24: if (hasPermissionInManifest(context, arrayList, "android.permission.REQUEST_INSTALL_PACKAGES")) { arrayList.add("android.permission.REQUEST_INSTALL_PACKAGES"); } return arrayList; case 27: if (hasPermissionInManifest(context, arrayList, "android.permission.ACCESS_NOTIFICATION_POLICY")) { arrayList.add("android.permission.ACCESS_NOTIFICATION_POLICY"); } return arrayList; case 28: String determineBluetoothPermission = determineBluetoothPermission(context, "android.permission.BLUETOOTH_SCAN"); if (determineBluetoothPermission != null) { arrayList.add(determineBluetoothPermission); } return arrayList; case 29: String determineBluetoothPermission2 = determineBluetoothPermission(context, "android.permission.BLUETOOTH_ADVERTISE"); if (determineBluetoothPermission2 != null) { arrayList.add(determineBluetoothPermission2); } return arrayList; case 30: String determineBluetoothPermission3 = determineBluetoothPermission(context, "android.permission.BLUETOOTH_CONNECT"); if (determineBluetoothPermission3 != null) { arrayList.add(determineBluetoothPermission3); } return arrayList; case 31: if (Build.VERSION.SDK_INT >= 33 && hasPermissionInManifest(context, arrayList, "android.permission.NEARBY_WIFI_DEVICES")) { arrayList.add("android.permission.NEARBY_WIFI_DEVICES"); } return arrayList; case 32: if (Build.VERSION.SDK_INT >= 33 && hasPermissionInManifest(context, arrayList, "android.permission.READ_MEDIA_VIDEO")) { arrayList.add("android.permission.READ_MEDIA_VIDEO"); } return arrayList; case 33: if (Build.VERSION.SDK_INT >= 33 && hasPermissionInManifest(context, arrayList, "android.permission.READ_MEDIA_AUDIO")) { arrayList.add("android.permission.READ_MEDIA_AUDIO"); } return arrayList; case 34: if (Build.VERSION.SDK_INT >= 31 && hasPermissionInManifest(context, arrayList, "android.permission.SCHEDULE_EXACT_ALARM")) { arrayList.add("android.permission.SCHEDULE_EXACT_ALARM"); } return arrayList; case 35: if (Build.VERSION.SDK_INT >= 33 && hasPermissionInManifest(context, arrayList, "android.permission.BODY_SENSORS_BACKGROUND")) { arrayList.add("android.permission.BODY_SENSORS_BACKGROUND"); } return arrayList; } } private static boolean hasPermissionInManifest(Context context, ArrayList arrayList, String str) { PackageInfo packageInfo; if (arrayList != null) { try { Iterator it = arrayList.iterator(); while (it.hasNext()) { if (it.next().equals(str)) { return true; } } } catch (Exception unused) { } } if (context == null || (packageInfo = getPackageInfo(context)) == null) { return false; } Iterator it2 = new ArrayList(Arrays.asList(packageInfo.requestedPermissions)).iterator(); while (it2.hasNext()) { if (((String) it2.next()).equals(str)) { return true; } } return false; } /* JADX INFO: Access modifiers changed from: package-private */ public static int toPermissionStatus(Activity activity, String str, int i) { boolean z = true; if (i != -1) { return 1; } boolean wasPermissionDeniedBefore = wasPermissionDeniedBefore(activity, str); boolean z2 = !isNeverAskAgainSelected(activity, str); if (!wasPermissionDeniedBefore) { z = z2; } else if (z2) { z = false; } if (!wasPermissionDeniedBefore && z) { setPermissionDenied(activity, str); } return (wasPermissionDeniedBefore && z) ? 4 : 0; } /* JADX INFO: Access modifiers changed from: package-private */ public static void updatePermissionShouldShowStatus(Activity activity, int i) { List manifestNames; if (activity == null || (manifestNames = getManifestNames(activity, i)) == null) { return; } manifestNames.isEmpty(); } static boolean isNeverAskAgainSelected(Activity activity, String str) { if (activity == null) { return false; } return !ActivityCompat.lP_(activity, str); } private static String determineBluetoothPermission(Context context, String str) { if (Build.VERSION.SDK_INT >= 31 && hasPermissionInManifest(context, null, str)) { return str; } if (Build.VERSION.SDK_INT < 29) { if (hasPermissionInManifest(context, null, "android.permission.ACCESS_FINE_LOCATION")) { return "android.permission.ACCESS_FINE_LOCATION"; } if (hasPermissionInManifest(context, null, "android.permission.ACCESS_COARSE_LOCATION")) { return "android.permission.ACCESS_COARSE_LOCATION"; } return null; } if (Build.VERSION.SDK_INT < 29 || !hasPermissionInManifest(context, null, "android.permission.ACCESS_FINE_LOCATION")) { return null; } return "android.permission.ACCESS_FINE_LOCATION"; } private static PackageInfo getPackageInfo(Context context) throws PackageManager.NameNotFoundException { PackageManager packageManager = context.getPackageManager(); if (Build.VERSION.SDK_INT >= 33) { return packageManager.getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(4096L)); } return packageManager.getPackageInfo(context.getPackageName(), 4096); } private static boolean wasPermissionDeniedBefore(Context context, String str) { return context.getSharedPreferences(str, 0).getBoolean(SHARED_PREFERENCES_PERMISSION_WAS_DENIED_BEFORE_KEY, false); } private static void setPermissionDenied(Context context, String str) { context.getSharedPreferences(str, 0).edit().putBoolean(SHARED_PREFERENCES_PERMISSION_WAS_DENIED_BEFORE_KEY, true).apply(); } }