310 lines
14 KiB
Java
310 lines
14 KiB
Java
|
package com.baseflow.permissionhandler;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.app.AlarmManager;
|
||
|
import android.app.NotificationManager;
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.net.Uri;
|
||
|
import android.os.Build;
|
||
|
import android.os.Environment;
|
||
|
import android.os.PowerManager;
|
||
|
import androidx.core.app.ActivityCompat;
|
||
|
import com.google.android.gms.dynamite.descriptors.com.google.android.gms.tagmanager.ModuleDescriptor;
|
||
|
import io.flutter.plugin.common.PluginRegistry;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
import java.util.Objects;
|
||
|
import o.nMh;
|
||
|
import o.vco;
|
||
|
import org.bouncycastle.math.Primes;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
final class PermissionManager implements PluginRegistry.ActivityResultListener, PluginRegistry.RequestPermissionsResultListener {
|
||
|
private Activity activity;
|
||
|
private int pendingRequestCount;
|
||
|
private Map<Integer, Integer> requestResults;
|
||
|
private RequestPermissionsSuccessCallback successCallback;
|
||
|
|
||
|
@FunctionalInterface
|
||
|
/* loaded from: classes.dex */
|
||
|
interface CheckPermissionsSuccessCallback {
|
||
|
void onSuccess(int i);
|
||
|
}
|
||
|
|
||
|
@FunctionalInterface
|
||
|
/* loaded from: classes.dex */
|
||
|
interface RequestPermissionsSuccessCallback {
|
||
|
void onSuccess(Map<Integer, Integer> map);
|
||
|
}
|
||
|
|
||
|
@FunctionalInterface
|
||
|
/* loaded from: classes.dex */
|
||
|
interface ShouldShowRequestPermissionRationaleSuccessCallback {
|
||
|
void onSuccess(boolean z);
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // io.flutter.plugin.common.PluginRegistry.ActivityResultListener
|
||
|
public final boolean onActivityResult(int i, int i2, Intent intent) {
|
||
|
int i3;
|
||
|
int i4;
|
||
|
if (i != 209 && i != 210 && i != 211 && i != 212 && i != 213 && i != 214) {
|
||
|
return false;
|
||
|
}
|
||
|
boolean z = i2 == -1;
|
||
|
if (i == 209) {
|
||
|
i3 = 16;
|
||
|
i4 = z;
|
||
|
} else if (i == 210) {
|
||
|
if (Build.VERSION.SDK_INT < 30) {
|
||
|
return false;
|
||
|
}
|
||
|
i3 = 22;
|
||
|
i4 = Environment.isExternalStorageManager();
|
||
|
} else if (i == 211) {
|
||
|
try {
|
||
|
i3 = 23;
|
||
|
i4 = ((Boolean) Class.forName("android.provider.Settings").getMethod("canDrawOverlays", Context.class).invoke(null, this.activity)).booleanValue();
|
||
|
} catch (Throwable th) {
|
||
|
Throwable cause = th.getCause();
|
||
|
if (cause != null) {
|
||
|
throw cause;
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
} else if (i == 212) {
|
||
|
i3 = 24;
|
||
|
i4 = this.activity.getPackageManager().canRequestPackageInstalls();
|
||
|
} else if (i == 213) {
|
||
|
i3 = 27;
|
||
|
i4 = ((NotificationManager) this.activity.getSystemService("notification")).isNotificationPolicyAccessGranted();
|
||
|
} else {
|
||
|
if (i != 214 || Build.VERSION.SDK_INT < 31) {
|
||
|
return false;
|
||
|
}
|
||
|
i3 = 34;
|
||
|
i4 = ((AlarmManager) this.activity.getSystemService("alarm")).canScheduleExactAlarms();
|
||
|
}
|
||
|
this.requestResults.put(Integer.valueOf(i3), Integer.valueOf(i4));
|
||
|
int i5 = this.pendingRequestCount - 1;
|
||
|
this.pendingRequestCount = i5;
|
||
|
if (i5 == 0) {
|
||
|
this.successCallback.onSuccess(this.requestResults);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener
|
||
|
public final boolean onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
|
||
|
if (i != 24) {
|
||
|
this.pendingRequestCount = 0;
|
||
|
return false;
|
||
|
}
|
||
|
if (this.requestResults == null) {
|
||
|
return false;
|
||
|
}
|
||
|
for (int i2 = 0; i2 < strArr.length; i2++) {
|
||
|
String str = strArr[i2];
|
||
|
int parseManifestName = PermissionUtils.parseManifestName(str);
|
||
|
if (parseManifestName != 20) {
|
||
|
int i3 = iArr[i2];
|
||
|
if (parseManifestName == 7) {
|
||
|
if (!this.requestResults.containsKey(7)) {
|
||
|
this.requestResults.put(7, Integer.valueOf(PermissionUtils.toPermissionStatus(this.activity, str, i3)));
|
||
|
}
|
||
|
if (!this.requestResults.containsKey(14)) {
|
||
|
this.requestResults.put(14, Integer.valueOf(PermissionUtils.toPermissionStatus(this.activity, str, i3)));
|
||
|
}
|
||
|
} else if (parseManifestName == 4) {
|
||
|
int permissionStatus = PermissionUtils.toPermissionStatus(this.activity, str, i3);
|
||
|
if (!this.requestResults.containsKey(4)) {
|
||
|
this.requestResults.put(4, Integer.valueOf(permissionStatus));
|
||
|
}
|
||
|
} else if (parseManifestName == 3) {
|
||
|
int permissionStatus2 = PermissionUtils.toPermissionStatus(this.activity, str, i3);
|
||
|
if (Build.VERSION.SDK_INT < 29 && !this.requestResults.containsKey(4)) {
|
||
|
this.requestResults.put(4, Integer.valueOf(permissionStatus2));
|
||
|
}
|
||
|
if (!this.requestResults.containsKey(5)) {
|
||
|
this.requestResults.put(5, Integer.valueOf(permissionStatus2));
|
||
|
}
|
||
|
this.requestResults.put(Integer.valueOf(parseManifestName), Integer.valueOf(permissionStatus2));
|
||
|
} else if (!this.requestResults.containsKey(Integer.valueOf(parseManifestName))) {
|
||
|
this.requestResults.put(Integer.valueOf(parseManifestName), Integer.valueOf(PermissionUtils.toPermissionStatus(this.activity, str, i3)));
|
||
|
}
|
||
|
PermissionUtils.updatePermissionShouldShowStatus(this.activity, parseManifestName);
|
||
|
}
|
||
|
}
|
||
|
int length = this.pendingRequestCount - iArr.length;
|
||
|
this.pendingRequestCount = length;
|
||
|
if (length != 0) {
|
||
|
return true;
|
||
|
}
|
||
|
this.successCallback.onSuccess(this.requestResults);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void checkPermissionStatus(int i, Context context, CheckPermissionsSuccessCallback checkPermissionsSuccessCallback) {
|
||
|
checkPermissionsSuccessCallback.onSuccess(determinePermissionStatus(i, context));
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void requestPermissions(List<Integer> list, Activity activity, RequestPermissionsSuccessCallback requestPermissionsSuccessCallback, ErrorCallback errorCallback) {
|
||
|
if (this.pendingRequestCount > 0) {
|
||
|
errorCallback.onError("PermissionHandler.PermissionManager", "A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time).");
|
||
|
return;
|
||
|
}
|
||
|
if (activity == null) {
|
||
|
errorCallback.onError("PermissionHandler.PermissionManager", "Unable to detect current Android Activity.");
|
||
|
return;
|
||
|
}
|
||
|
this.successCallback = requestPermissionsSuccessCallback;
|
||
|
this.activity = activity;
|
||
|
this.requestResults = new HashMap();
|
||
|
this.pendingRequestCount = 0;
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
for (Integer num : list) {
|
||
|
if (determinePermissionStatus(num.intValue(), activity) == 1) {
|
||
|
if (!this.requestResults.containsKey(num)) {
|
||
|
this.requestResults.put(num, 1);
|
||
|
}
|
||
|
} else {
|
||
|
List<String> manifestNames = PermissionUtils.getManifestNames(activity, num.intValue());
|
||
|
if (manifestNames == null || manifestNames.isEmpty()) {
|
||
|
if (!this.requestResults.containsKey(num)) {
|
||
|
this.requestResults.put(num, 0);
|
||
|
if (num.intValue() == 22 && Build.VERSION.SDK_INT < 30) {
|
||
|
this.requestResults.put(num, 2);
|
||
|
} else {
|
||
|
this.requestResults.put(num, 0);
|
||
|
}
|
||
|
}
|
||
|
} else if (num.intValue() == 16) {
|
||
|
launchSpecialPermission("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", 209);
|
||
|
} else if (Build.VERSION.SDK_INT >= 30 && num.intValue() == 22) {
|
||
|
launchSpecialPermission("android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", 210);
|
||
|
} else if (num.intValue() == 23) {
|
||
|
launchSpecialPermission("android.settings.action.MANAGE_OVERLAY_PERMISSION", Primes.SMALL_FACTOR_LIMIT);
|
||
|
} else if (num.intValue() == 24) {
|
||
|
launchSpecialPermission("android.settings.MANAGE_UNKNOWN_APP_SOURCES", 212);
|
||
|
} else if (num.intValue() == 27) {
|
||
|
launchSpecialPermission("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS", 213);
|
||
|
} else if (Build.VERSION.SDK_INT >= 31 && num.intValue() == 34) {
|
||
|
launchSpecialPermission("android.settings.REQUEST_SCHEDULE_EXACT_ALARM", ModuleDescriptor.MODULE_VERSION);
|
||
|
} else {
|
||
|
arrayList.addAll(manifestNames);
|
||
|
this.pendingRequestCount += manifestNames.size();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (arrayList.size() > 0) {
|
||
|
ActivityCompat.lM_(activity, (String[]) arrayList.toArray(new String[0]), 24);
|
||
|
}
|
||
|
if (this.pendingRequestCount == 0) {
|
||
|
this.successCallback.onSuccess(this.requestResults);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
private int determinePermissionStatus(int i, Context context) {
|
||
|
if (i == 17) {
|
||
|
return checkNotificationPermissionStatus(context);
|
||
|
}
|
||
|
if (i == 21) {
|
||
|
return checkBluetoothPermissionStatus(context);
|
||
|
}
|
||
|
if ((i == 30 || i == 28 || i == 29) && Build.VERSION.SDK_INT < 31) {
|
||
|
return checkBluetoothPermissionStatus(context);
|
||
|
}
|
||
|
List<String> manifestNames = PermissionUtils.getManifestNames(context, i);
|
||
|
if (manifestNames == null) {
|
||
|
return 1;
|
||
|
}
|
||
|
if (manifestNames.size() == 0) {
|
||
|
Objects.toString(manifestNames);
|
||
|
return (i != 22 || Build.VERSION.SDK_INT >= 30) ? 0 : 2;
|
||
|
}
|
||
|
Object[] objArr = context.getApplicationInfo().targetSdkVersion >= 23;
|
||
|
for (String str : manifestNames) {
|
||
|
if (objArr != false) {
|
||
|
if (i == 16) {
|
||
|
String packageName = context.getPackageName();
|
||
|
PowerManager powerManager = (PowerManager) context.getSystemService("power");
|
||
|
return (powerManager == null || !powerManager.isIgnoringBatteryOptimizations(packageName)) ? 0 : 1;
|
||
|
}
|
||
|
if (i == 22) {
|
||
|
if (Build.VERSION.SDK_INT < 30) {
|
||
|
return 2;
|
||
|
}
|
||
|
return Environment.isExternalStorageManager() ? 1 : 0;
|
||
|
}
|
||
|
if (i == 23) {
|
||
|
try {
|
||
|
return ((Boolean) Class.forName("android.provider.Settings").getMethod("canDrawOverlays", Context.class).invoke(null, context)).booleanValue() ? 1 : 0;
|
||
|
} catch (Throwable th) {
|
||
|
Throwable cause = th.getCause();
|
||
|
if (cause != null) {
|
||
|
throw cause;
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
if (i == 24) {
|
||
|
return context.getPackageManager().canRequestPackageInstalls() ? 1 : 0;
|
||
|
}
|
||
|
if (i == 27) {
|
||
|
return ((NotificationManager) context.getSystemService("notification")).isNotificationPolicyAccessGranted() ? 1 : 0;
|
||
|
}
|
||
|
if (i == 34) {
|
||
|
if (Build.VERSION.SDK_INT >= 31) {
|
||
|
return ((AlarmManager) context.getSystemService("alarm")).canScheduleExactAlarms() ? 1 : 0;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
if (nMh.checkSelfPermission(context, str) != 0) {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
private void launchSpecialPermission(String str, int i) {
|
||
|
Intent intent = new Intent(str);
|
||
|
if (!str.equals("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS")) {
|
||
|
intent.setData(Uri.parse("package:".concat(String.valueOf(this.activity.getPackageName()))));
|
||
|
}
|
||
|
this.activity.startActivityForResult(intent, i);
|
||
|
this.pendingRequestCount++;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void shouldShowRequestPermissionRationale(int i, Activity activity, ShouldShowRequestPermissionRationaleSuccessCallback shouldShowRequestPermissionRationaleSuccessCallback, ErrorCallback errorCallback) {
|
||
|
if (activity == null) {
|
||
|
errorCallback.onError("PermissionHandler.PermissionManager", "Unable to detect current Android Activity.");
|
||
|
return;
|
||
|
}
|
||
|
List<String> manifestNames = PermissionUtils.getManifestNames(activity, i);
|
||
|
if (manifestNames == null) {
|
||
|
shouldShowRequestPermissionRationaleSuccessCallback.onSuccess(false);
|
||
|
} else if (manifestNames.isEmpty()) {
|
||
|
shouldShowRequestPermissionRationaleSuccessCallback.onSuccess(false);
|
||
|
} else {
|
||
|
shouldShowRequestPermissionRationaleSuccessCallback.onSuccess(ActivityCompat.lP_(activity, manifestNames.get(0)));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private int checkNotificationPermissionStatus(Context context) {
|
||
|
return Build.VERSION.SDK_INT < 33 ? vco.e(context).b() ? 1 : 0 : context.checkSelfPermission("android.permission.POST_NOTIFICATIONS") != 0 ? 0 : 1;
|
||
|
}
|
||
|
|
||
|
private int checkBluetoothPermissionStatus(Context context) {
|
||
|
List<String> manifestNames = PermissionUtils.getManifestNames(context, 21);
|
||
|
return (manifestNames == null || manifestNames.isEmpty()) ? 0 : 1;
|
||
|
}
|
||
|
}
|