141 lines
4.4 KiB
Java
141 lines
4.4 KiB
Java
package com.yanzhenjie.permission.runtime;
|
|
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
import com.yanzhenjie.permission.Action;
|
|
import com.yanzhenjie.permission.PermissionActivity;
|
|
import com.yanzhenjie.permission.Rationale;
|
|
import com.yanzhenjie.permission.RequestExecutor;
|
|
import com.yanzhenjie.permission.checker.DoubleChecker;
|
|
import com.yanzhenjie.permission.checker.PermissionChecker;
|
|
import com.yanzhenjie.permission.checker.StandardChecker;
|
|
import com.yanzhenjie.permission.source.Source;
|
|
import com.yanzhenjie.permission.util.MainExecutor;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
class MRequest implements PermissionRequest, RequestExecutor, PermissionActivity.RequestListener {
|
|
private static final MainExecutor g = new MainExecutor();
|
|
private static final PermissionChecker h = new StandardChecker();
|
|
private static final PermissionChecker i = new DoubleChecker();
|
|
private Source a;
|
|
private String[] b;
|
|
private Rationale<List<String>> c = new Rationale<List<String>>(this) { // from class: com.yanzhenjie.permission.runtime.MRequest.1
|
|
@Override // com.yanzhenjie.permission.Rationale
|
|
public void a(Context context, List<String> list, RequestExecutor requestExecutor) {
|
|
requestExecutor.execute();
|
|
}
|
|
};
|
|
private Action<List<String>> d;
|
|
private Action<List<String>> e;
|
|
private String[] f;
|
|
|
|
MRequest(Source source) {
|
|
this.a = source;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void c() {
|
|
List<String> a = a(i, this.a, this.b);
|
|
if (a.isEmpty()) {
|
|
b();
|
|
} else {
|
|
a(a);
|
|
}
|
|
}
|
|
|
|
@Override // com.yanzhenjie.permission.runtime.PermissionRequest
|
|
public PermissionRequest b(Action<List<String>> action) {
|
|
this.e = action;
|
|
return this;
|
|
}
|
|
|
|
@Override // com.yanzhenjie.permission.RequestExecutor
|
|
public void execute() {
|
|
PermissionActivity.a(this.a.a(), this.f, this);
|
|
}
|
|
|
|
@Override // com.yanzhenjie.permission.runtime.PermissionRequest
|
|
public void start() {
|
|
List<String> a = a(h, this.a, this.b);
|
|
this.f = (String[]) a.toArray(new String[a.size()]);
|
|
String[] strArr = this.f;
|
|
if (strArr.length <= 0) {
|
|
c();
|
|
return;
|
|
}
|
|
List<String> a2 = a(this.a, strArr);
|
|
if (a2.size() > 0) {
|
|
this.c.a(this.a.a(), a2, this);
|
|
} else {
|
|
execute();
|
|
}
|
|
}
|
|
|
|
private void b() {
|
|
if (this.d != null) {
|
|
List<String> asList = Arrays.asList(this.b);
|
|
try {
|
|
this.d.a(asList);
|
|
} catch (Exception e) {
|
|
Log.e("AndPermission", "Please check the onGranted() method body for bugs.", e);
|
|
Action<List<String>> action = this.e;
|
|
if (action != null) {
|
|
action.a(asList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.yanzhenjie.permission.runtime.PermissionRequest
|
|
public PermissionRequest a(String... strArr) {
|
|
this.b = strArr;
|
|
return this;
|
|
}
|
|
|
|
@Override // com.yanzhenjie.permission.runtime.PermissionRequest
|
|
public PermissionRequest a(Action<List<String>> action) {
|
|
this.d = action;
|
|
return this;
|
|
}
|
|
|
|
@Override // com.yanzhenjie.permission.PermissionActivity.RequestListener
|
|
public void a() {
|
|
g.a(new Runnable() { // from class: com.yanzhenjie.permission.runtime.MRequest.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
MRequest.this.c();
|
|
}
|
|
}, 100L);
|
|
}
|
|
|
|
private void a(List<String> list) {
|
|
Action<List<String>> action = this.e;
|
|
if (action != null) {
|
|
action.a(list);
|
|
}
|
|
}
|
|
|
|
private static List<String> a(PermissionChecker permissionChecker, Source source, String... strArr) {
|
|
ArrayList arrayList = new ArrayList(1);
|
|
for (String str : strArr) {
|
|
if (!permissionChecker.a(source.a(), str)) {
|
|
arrayList.add(str);
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
private static List<String> a(Source source, String... strArr) {
|
|
ArrayList arrayList = new ArrayList(1);
|
|
for (String str : strArr) {
|
|
if (source.a(str)) {
|
|
arrayList.add(str);
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
}
|