正在查看: aeroLINE CREW v5.0.1 应用的 RNCWebViewModule.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: aeroLINE CREW v5.0.1 应用的 RNCWebViewModule.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.reactnativecommunity.webview;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Parcelable;
import android.util.Log;
import android.webkit.MimeTypeMap;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.util.Pair;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;
import com.oblador.keychain.KeychainModuleBuilder;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicReference;
import kotlin.io.ConstantsKt;
@ReactModule(name = RNCWebViewModule.MODULE_NAME)
public class RNCWebViewModule extends ReactContextBaseJavaModule implements ActivityEventListener {
private static final int FILE_DOWNLOAD_PERMISSION_REQUEST = 1;
public static final String MODULE_NAME = "RNCWebView";
private static final int PICKER = 1;
private static final int PICKER_LEGACY = 3;
protected static final ShouldOverrideUrlLoadingLock shouldOverrideUrlLoadingLock = new ShouldOverrideUrlLoadingLock();
private DownloadManager.Request downloadRequest;
private ValueCallback<Uri[]> filePathCallback;
private ValueCallback<Uri> filePathCallbackLegacy;
private File outputImage;
private File outputVideo;
public String getName() {
return MODULE_NAME;
}
public void onNewIntent(Intent intent) {
}
protected static class ShouldOverrideUrlLoadingLock {
private int nextLockIdentifier = 1;
private final HashMap<Integer, AtomicReference<ShouldOverrideCallbackState>> shouldOverrideLocks = new HashMap<>();
protected enum ShouldOverrideCallbackState {
UNDECIDED,
SHOULD_OVERRIDE,
DO_NOT_OVERRIDE
}
protected ShouldOverrideUrlLoadingLock() {
}
public synchronized Pair<Integer, AtomicReference<ShouldOverrideCallbackState>> getNewLock() {
int i;
AtomicReference<ShouldOverrideCallbackState> atomicReference;
i = this.nextLockIdentifier;
this.nextLockIdentifier = i + 1;
atomicReference = new AtomicReference<>(ShouldOverrideCallbackState.UNDECIDED);
this.shouldOverrideLocks.put(Integer.valueOf(i), atomicReference);
return new Pair<>(Integer.valueOf(i), atomicReference);
}
public synchronized AtomicReference<ShouldOverrideCallbackState> getLock(Integer num) {
return this.shouldOverrideLocks.get(num);
}
public synchronized void removeLock(Integer num) {
this.shouldOverrideLocks.remove(num);
}
}
private enum MimeType {
DEFAULT("*/*"),
IMAGE("image"),
VIDEO("video");
private final String value;
MimeType(String str) {
this.value = str;
}
}
private PermissionListener getWebviewFileDownloaderPermissionListener(final String str, final String str2) {
return new PermissionListener() {
public boolean onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
if (i != 1) {
return false;
}
if (iArr.length <= 0 || iArr[0] != 0) {
Toast.makeText(RNCWebViewModule.this.getCurrentActivity().getApplicationContext(), str2, 1).show();
} else if (RNCWebViewModule.this.downloadRequest != null) {
RNCWebViewModule.this.downloadFile(str);
}
return true;
}
};
}
public RNCWebViewModule(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
reactApplicationContext.addActivityEventListener(this);
}
@ReactMethod
public void isFileUploadSupported(Promise promise) {
int i = Build.VERSION.SDK_INT;
promise.resolve((i < 16 || i > 18) ? i >= 21 ? r2 : false : true);
}
@ReactMethod(isBlockingSynchronousMethod = KeychainModuleBuilder.DEFAULT_USE_WARM_UP)
public void onShouldStartLoadWithRequestCallback(boolean z, int i) {
AtomicReference<ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState> lock = shouldOverrideUrlLoadingLock.getLock(Integer.valueOf(i));
if (lock != null) {
synchronized (lock) {
lock.set(z ? ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.DO_NOT_OVERRIDE : ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.SHOULD_OVERRIDE);
lock.notify();
}
}
}
public void onActivityResult(Activity activity, int i, int i2, Intent intent) {
if (this.filePathCallback == null && this.filePathCallbackLegacy == null) {
return;
}
File file = this.outputImage;
boolean z = file != null && file.length() > 0;
File file2 = this.outputVideo;
boolean z2 = file2 != null && file2.length() > 0;
if (i != 1) {
if (i == 3) {
if (i2 != -1) {
this.filePathCallbackLegacy.onReceiveValue(null);
} else if (z) {
this.filePathCallbackLegacy.onReceiveValue(getOutputUri(this.outputImage));
} else if (z2) {
this.filePathCallbackLegacy.onReceiveValue(getOutputUri(this.outputVideo));
} else {
this.filePathCallbackLegacy.onReceiveValue(intent.getData());
}
}
} else if (i2 != -1) {
ValueCallback<Uri[]> valueCallback = this.filePathCallback;
if (valueCallback != null) {
valueCallback.onReceiveValue(null);
}
} else if (z) {
this.filePathCallback.onReceiveValue(new Uri[]{getOutputUri(this.outputImage)});
} else if (z2) {
this.filePathCallback.onReceiveValue(new Uri[]{getOutputUri(this.outputVideo)});
} else {
this.filePathCallback.onReceiveValue(getSelectedFiles(intent, i2));
}
File file3 = this.outputImage;
if (file3 != null && !z) {
file3.delete();
}
File file4 = this.outputVideo;
if (file4 != null && !z2) {
file4.delete();
}
this.filePathCallback = null;
this.filePathCallbackLegacy = null;
this.outputImage = null;
this.outputVideo = null;
}
private Uri[] getSelectedFiles(Intent intent, int i) {
if (intent == null) {
return null;
}
if (intent.getClipData() != null) {
int itemCount = intent.getClipData().getItemCount();
Uri[] uriArr = new Uri[itemCount];
for (int i2 = 0; i2 < itemCount; i2++) {
uriArr[i2] = intent.getClipData().getItemAt(i2).getUri();
}
return uriArr;
}
if (intent.getData() == null || i != -1 || Build.VERSION.SDK_INT < 21) {
return null;
}
return WebChromeClient.FileChooserParams.parseResult(i, intent);
}
public void startPhotoPickerIntent(ValueCallback<Uri> valueCallback, String str) {
Intent videoIntent;
Intent photoIntent;
this.filePathCallbackLegacy = valueCallback;
Intent createChooser = Intent.createChooser(getFileChooserIntent(str), "");
ArrayList arrayList = new ArrayList();
if (acceptsImages(str).booleanValue() && (photoIntent = getPhotoIntent()) != null) {
arrayList.add(photoIntent);
}
if (acceptsVideo(str).booleanValue() && (videoIntent = getVideoIntent()) != null) {
arrayList.add(videoIntent);
}
createChooser.putExtra("android.intent.extra.INITIAL_INTENTS", (Parcelable[]) arrayList.toArray(new Parcelable[0]));
if (createChooser.resolveActivity(getCurrentActivity().getPackageManager()) != null) {
getCurrentActivity().startActivityForResult(createChooser, 3);
} else {
Log.w("RNCWebViewModule", "there is no Activity to handle this Intent");
}
}
public boolean startPhotoPickerIntent(ValueCallback<Uri[]> valueCallback, String[] strArr, boolean z) {
Intent videoIntent;
Intent photoIntent;
this.filePathCallback = valueCallback;
ArrayList arrayList = new ArrayList();
if (!needsCameraPermission()) {
if (acceptsImages(strArr).booleanValue() && (photoIntent = getPhotoIntent()) != null) {
arrayList.add(photoIntent);
}
if (acceptsVideo(strArr).booleanValue() && (videoIntent = getVideoIntent()) != null) {
arrayList.add(videoIntent);
}
}
Intent fileChooserIntent = getFileChooserIntent(strArr, z);
Intent intent = new Intent("android.intent.action.CHOOSER");
intent.putExtra("android.intent.extra.INTENT", fileChooserIntent);
intent.putExtra("android.intent.extra.INITIAL_INTENTS", (Parcelable[]) arrayList.toArray(new Parcelable[0]));
if (intent.resolveActivity(getCurrentActivity().getPackageManager()) != null) {
getCurrentActivity().startActivityForResult(intent, 1);
} else {
Log.w("RNCWebViewModule", "there is no Activity to handle this Intent");
}
return true;
}
public void setDownloadRequest(DownloadManager.Request request) {
this.downloadRequest = request;
}
public void downloadFile(String str) {
try {
((DownloadManager) getCurrentActivity().getBaseContext().getSystemService("download")).enqueue(this.downloadRequest);
Toast.makeText(getCurrentActivity().getApplicationContext(), str, 1).show();
} catch (IllegalArgumentException e) {
Log.w("RNCWebViewModule", "Unsupported URI, aborting download", e);
}
}
public boolean grantFileDownloaderPermissions(String str, String str2) {
if (Build.VERSION.SDK_INT > 28) {
return true;
}
boolean z = ContextCompat.checkSelfPermission(getCurrentActivity(), "android.permission.WRITE_EXTERNAL_STORAGE") == 0;
if (!z && Build.VERSION.SDK_INT >= 23) {
getPermissionAwareActivity().requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 1, getWebviewFileDownloaderPermissionListener(str, str2));
}
return z;
}
protected boolean needsCameraPermission() {
try {
if (Arrays.asList(getCurrentActivity().getPackageManager().getPackageInfo(getReactApplicationContext().getPackageName(), ConstantsKt.DEFAULT_BLOCK_SIZE).requestedPermissions).contains("android.permission.CAMERA")) {
if (ContextCompat.checkSelfPermission(getCurrentActivity(), "android.permission.CAMERA") != 0) {
return true;
}
}
return false;
} catch (PackageManager.NameNotFoundException unused) {
return true;
}
}
private Intent getPhotoIntent() {
Intent intent;
Exception e;
Uri outputUri;
try {
File capturedFile = getCapturedFile(MimeType.IMAGE);
this.outputImage = capturedFile;
outputUri = getOutputUri(capturedFile);
intent = new Intent("android.media.action.IMAGE_CAPTURE");
} catch (IOException | IllegalArgumentException e2) {
intent = null;
e = e2;
}
try {
intent.putExtra("output", outputUri);
} catch (IOException e3) {
e = e3;
Log.e("CREATE FILE", "Error occurred while creating the File", e);
e.printStackTrace();
return intent;
} catch (IllegalArgumentException e4) {
e = e4;
Log.e("CREATE FILE", "Error occurred while creating the File", e);
e.printStackTrace();
return intent;
}
return intent;
}
private Intent getVideoIntent() {
Intent intent;
Exception e;
Uri outputUri;
try {
File capturedFile = getCapturedFile(MimeType.VIDEO);
this.outputVideo = capturedFile;
outputUri = getOutputUri(capturedFile);
intent = new Intent("android.media.action.VIDEO_CAPTURE");
} catch (IOException | IllegalArgumentException e2) {
intent = null;
e = e2;
}
try {
intent.putExtra("output", outputUri);
} catch (IOException e3) {
e = e3;
Log.e("CREATE FILE", "Error occurred while creating the File", e);
e.printStackTrace();
return intent;
} catch (IllegalArgumentException e4) {
e = e4;
Log.e("CREATE FILE", "Error occurred while creating the File", e);
e.printStackTrace();
return intent;
}
return intent;
}
private Intent getFileChooserIntent(String str) {
String str2 = str.isEmpty() ? MimeType.DEFAULT.value : str;
if (str.matches("\\.\\w+")) {
str2 = getMimeTypeFromExtension(str.replace(".", ""));
}
Intent intent = new Intent("android.intent.action.GET_CONTENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType(str2);
return intent;
}
private Intent getFileChooserIntent(String[] strArr, boolean z) {
Intent intent = new Intent("android.intent.action.GET_CONTENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType(MimeType.DEFAULT.value);
intent.putExtra("android.intent.extra.MIME_TYPES", getAcceptedMimeType(strArr));
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", z);
return intent;
}
private Boolean acceptsImages(String str) {
if (str.matches("\\.\\w+")) {
str = getMimeTypeFromExtension(str.replace(".", ""));
}
return Boolean.valueOf(str.isEmpty() || str.toLowerCase().contains(MimeType.IMAGE.value));
}
private Boolean acceptsImages(String[] strArr) {
String[] acceptedMimeType = getAcceptedMimeType(strArr);
return Boolean.valueOf(arrayContainsString(acceptedMimeType, MimeType.DEFAULT.value).booleanValue() || arrayContainsString(acceptedMimeType, MimeType.IMAGE.value).booleanValue());
}
private Boolean acceptsVideo(String str) {
if (Build.VERSION.SDK_INT < 23) {
return false;
}
if (str.matches("\\.\\w+")) {
str = getMimeTypeFromExtension(str.replace(".", ""));
}
return Boolean.valueOf(str.isEmpty() || str.toLowerCase().contains(MimeType.VIDEO.value));
}
private Boolean acceptsVideo(String[] strArr) {
if (Build.VERSION.SDK_INT < 23) {
return false;
}
String[] acceptedMimeType = getAcceptedMimeType(strArr);
return Boolean.valueOf(arrayContainsString(acceptedMimeType, MimeType.DEFAULT.value).booleanValue() || arrayContainsString(acceptedMimeType, MimeType.VIDEO.value).booleanValue());
}
private Boolean arrayContainsString(String[] strArr, String str) {
for (String str2 : strArr) {
if (str2.contains(str)) {
return true;
}
}
return false;
}
private String[] getAcceptedMimeType(String[] strArr) {
if (noAcceptTypesSet(strArr).booleanValue()) {
return new String[]{MimeType.DEFAULT.value};
}
String[] strArr2 = new String[strArr.length];
for (int i = 0; i < strArr.length; i++) {
String str = strArr[i];
if (str.matches("\\.\\w+")) {
String mimeTypeFromExtension = getMimeTypeFromExtension(str.replace(".", ""));
if (mimeTypeFromExtension != null) {
strArr2[i] = mimeTypeFromExtension;
} else {
strArr2[i] = str;
}
} else {
strArr2[i] = str;
}
}
return strArr2;
}
private String getMimeTypeFromExtension(String str) {
if (str != null) {
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(str);
}
return null;
}
private Uri getOutputUri(File file) {
if (Build.VERSION.SDK_INT < 23) {
return Uri.fromFile(file);
}
String packageName = getReactApplicationContext().getPackageName();
return FileProvider.getUriForFile(getReactApplicationContext(), packageName + ".fileprovider", file);
}
static class AnonymousClass2 {
static final int[] $SwitchMap$com$reactnativecommunity$webview$RNCWebViewModule$MimeType;
static {
int[] iArr = new int[MimeType.values().length];
$SwitchMap$com$reactnativecommunity$webview$RNCWebViewModule$MimeType = iArr;
try {
iArr[MimeType.IMAGE.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$reactnativecommunity$webview$RNCWebViewModule$MimeType[MimeType.VIDEO.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
private java.io.File getCapturedFile(com.reactnativecommunity.webview.RNCWebViewModule.MimeType r7) throws java.io.IOException {
throw new UnsupportedOperationException("Method not decompiled: com.reactnativecommunity.webview.RNCWebViewModule.getCapturedFile(com.reactnativecommunity.webview.RNCWebViewModule$MimeType):java.io.File");
}
private Boolean noAcceptTypesSet(String[] strArr) {
boolean z = true;
if (strArr.length != 0 && (strArr.length != 1 || strArr[0] == null || strArr[0].length() != 0)) {
z = false;
}
return Boolean.valueOf(z);
}
private PermissionAwareActivity getPermissionAwareActivity() {
PermissionAwareActivity currentActivity = getCurrentActivity();
if (currentActivity == null) {
throw new IllegalStateException("Tried to use permissions API while not attached to an Activity.");
}
if (!(currentActivity instanceof PermissionAwareActivity)) {
throw new IllegalStateException("Tried to use permissions API but the host Activity doesn't implement PermissionAwareActivity.");
}
return currentActivity;
}
}