71 lines
2.2 KiB
Java
71 lines
2.2 KiB
Java
package com.yanzhenjie.permission.runtime;
|
|
|
|
import android.content.Context;
|
|
import android.content.pm.PackageManager;
|
|
import android.os.Build;
|
|
import com.ubt.jimu.base.util.FileUtil;
|
|
import com.yanzhenjie.permission.Setting;
|
|
import com.yanzhenjie.permission.runtime.setting.RuntimeSetting;
|
|
import com.yanzhenjie.permission.source.Source;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class Runtime {
|
|
private static final PermissionRequestFactory b;
|
|
private static List<String> c;
|
|
private Source a;
|
|
|
|
public interface PermissionRequestFactory {
|
|
PermissionRequest a(Source source);
|
|
}
|
|
|
|
static {
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
b = new MRequestFactory();
|
|
} else {
|
|
b = new LRequestFactory();
|
|
}
|
|
}
|
|
|
|
public Runtime(Source source) {
|
|
this.a = source;
|
|
}
|
|
|
|
private void b(String... strArr) {
|
|
if (c == null) {
|
|
c = a(this.a.a());
|
|
}
|
|
if (strArr == null || strArr.length == 0) {
|
|
throw new IllegalArgumentException("Please enter at least one permission.");
|
|
}
|
|
for (String str : strArr) {
|
|
if (!c.contains(str)) {
|
|
throw new IllegalStateException(String.format("The permission %1$s is not registered in manifest.xml", str));
|
|
}
|
|
}
|
|
}
|
|
|
|
public PermissionRequest a(String... strArr) {
|
|
b(strArr);
|
|
return b.a(this.a).a(strArr);
|
|
}
|
|
|
|
public Setting a() {
|
|
return new RuntimeSetting(this.a);
|
|
}
|
|
|
|
private static List<String> a(Context context) {
|
|
try {
|
|
String[] strArr = context.getPackageManager().getPackageInfo(context.getPackageName(), FileUtil.ZIP_BUFFER_SIZE).requestedPermissions;
|
|
if (strArr != null && strArr.length != 0) {
|
|
return Collections.unmodifiableList(Arrays.asList(strArr));
|
|
}
|
|
throw new IllegalStateException("You did not register any permissions in the manifest.xml.");
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
throw new AssertionError("Package name cannot be found.");
|
|
}
|
|
}
|
|
}
|