同程有借 v1.0.0版本的 MD5 值为:e33397cdbab33543d0c134ec96d77fb8
以下内容为反编译后的 PhotoJavascriptInterface.java 源代码,内容仅作参考
package com.moture.plugin.photo;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.webkit.JavascriptInterface;
import androidx.annotation.NonNull;
import anet.channel.util.HttpConstant;
import com.bonree.sdk.agent.engine.external.BitmapFactoryInstrumentation;
import com.bonree.sdk.agent.engine.external.GsonInstrumentation;
import com.bonree.sdk.agent.engine.external.HttpInstrumentation;
import com.bonree.sdk.agent.engine.external.Instrumented;
import com.google.gson.Gson;
import com.moture.lib.core.app.AppMain;
import com.moture.lib.core.misc.json.JsonHelper;
import com.moture.lib.core.misc.logger.LogModuleType;
import com.moture.lib.core.misc.logger.Logger;
import com.moture.lib.core.permission.AppPermission;
import com.moture.lib.core.permission.PermissionConfig;
import com.moture.plugin.core.BaseJavascriptInterface;
import com.moture.plugin.core.BridgeHelper;
import com.moture.plugin.core.BridgeWebView;
import com.moture.plugin.core.ErrorType;
import com.moture.plugin.core.FabricCallBackData;
import com.moture.plugin.core.WebActivities;
import com.moture.plugin.photo.impl.PhotoPermissionRationale;
import com.moture.plugin.photo.request.FabricChooseImageOptions;
import com.moture.plugin.photo.request.FabricPhotoSaveImageToPhotosAlbumOptions;
import com.moture.plugin.photo.request.FabricPreviewImageOptions;
import com.moture.plugin.photo.response.FabricPhotoSaveToAlbumCallbackData;
import com.xiaomi.mipush.sdk.Constants;
import j6.b;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import p4.a;
import r6.c;
@Instrumented
public class PhotoJavascriptInterface extends BaseJavascriptInterface {
private Activity mActivity;
public BridgeWebView mBridgeWebView;
public String mChooseImageCallbackId;
public FabricChooseImageOptions mFabricChooseImageOptions;
public FabricPreviewImageOptions mFabricPreviewImageOptions;
public String mPreviewImageCallbackId;
class AnonymousClass3 implements Runnable {
final String val$callbackId;
final FabricPhotoSaveImageToPhotosAlbumOptions val$imageOption;
AnonymousClass3(FabricPhotoSaveImageToPhotosAlbumOptions fabricPhotoSaveImageToPhotosAlbumOptions, String str) {
this.val$imageOption = fabricPhotoSaveImageToPhotosAlbumOptions;
this.val$callbackId = str;
}
@Override
public void run() {
new b(PhotoJavascriptInterface.this.mActivity).l(PermissionConfig.Storage.READ_EXTERNAL_STORAGE, PermissionConfig.Storage.WRITE_EXTERNAL_STORAGE).B(new c<Boolean>() {
@Override
public void accept(final Boolean bool) {
new Thread() {
@Override
public void run() {
FabricCallBackData fabricCallBackData;
FabricPhotoSaveToAlbumCallbackData fabricPhotoSaveToAlbumCallbackData = new FabricPhotoSaveToAlbumCallbackData();
if (bool.booleanValue()) {
if (TextUtils.equals(AnonymousClass3.this.val$imageOption.type, "base64")) {
AnonymousClass3 anonymousClass3 = AnonymousClass3.this;
fabricPhotoSaveToAlbumCallbackData.filePath = PhotoJavascriptInterface.this.savePhoto(AppMain.getApp(), PhotoJavascriptInterface.this.base642Bitmap(anonymousClass3.val$imageOption.filePath));
fabricCallBackData = new FabricCallBackData(fabricPhotoSaveToAlbumCallbackData);
} else if (TextUtils.equals(AnonymousClass3.this.val$imageOption.type, HttpConstant.HTTP)) {
AnonymousClass3 anonymousClass32 = AnonymousClass3.this;
fabricPhotoSaveToAlbumCallbackData.filePath = PhotoJavascriptInterface.this.savePhoto(AppMain.getApp(), PhotoJavascriptInterface.this.getBitmap(anonymousClass32.val$imageOption.filePath));
fabricCallBackData = new FabricCallBackData(fabricPhotoSaveToAlbumCallbackData);
} else {
fabricCallBackData = new FabricCallBackData("");
fabricCallBackData.code = "-1";
}
} else {
fabricCallBackData = new FabricCallBackData("");
fabricCallBackData.code = "-1";
}
((BaseJavascriptInterface) PhotoJavascriptInterface.this).mWebView.mBridgeHelper.sendResponse(fabricCallBackData, AnonymousClass3.this.val$callbackId, true);
}
}.start();
}
});
}
}
public PhotoJavascriptInterface(Activity activity, @NonNull BridgeWebView bridgeWebView) {
super(bridgeWebView);
this.mChooseImageCallbackId = "";
this.mPreviewImageCallbackId = "";
this.mActivity = activity;
this.mBridgeWebView = bridgeWebView;
}
public void sendExceptionResponse(String str, String str2) {
String str3 = this.mChooseImageCallbackId;
FabricCallBackData fabricCallBackData = new FabricCallBackData("");
fabricCallBackData.code = str;
if (!TextUtils.isEmpty(str2)) {
fabricCallBackData.message = str2;
}
this.mBridgeWebView.mBridgeHelper.sendResponse(fabricCallBackData, str3, true);
}
public Bitmap base642Bitmap(String str) {
if (str.startsWith("data:image") && str.contains(Constants.ACCEPT_TIME_SEPARATOR_SP)) {
str = str.split(Constants.ACCEPT_TIME_SEPARATOR_SP)[1];
}
byte[] decode = Base64.decode(str, 0);
return BitmapFactoryInstrumentation.decodeByteArray(decode, 0, decode.length);
}
@JavascriptInterface
public void chooseImage(String str, String str2) {
Log.i("skone", "chooseimage = " + str);
this.mFabricChooseImageOptions = (FabricChooseImageOptions) GsonInstrumentation.fromJson(new Gson(), str, (Class<Object>) FabricChooseImageOptions.class);
this.mChooseImageCallbackId = str2;
this.mBridgeWebView.post(new Runnable() {
@Override
public void run() {
PhotoPermissionRationale photoPermissionRationale = new PhotoPermissionRationale();
photoPermissionRationale.setShowListener(new PhotoPermissionRationale.ShowListener() {
@Override
public void onShow() {
PhotoJavascriptInterface.this.sendExceptionResponse(ErrorType.ntv_permission_reject, "相机权限被拒绝");
a aVar = new a();
aVar.i(((BaseJavascriptInterface) PhotoJavascriptInterface.this).mWebView.getUrl());
p4.b bVar = new p4.b();
bVar.d(LogModuleType.Permission);
bVar.f("相机权限被拒绝 [chooseImage]");
bVar.e(aVar);
Logger.i(LogModuleType.LOG_MSG_EXT_CONTEXT, JsonHelper.getInstance().toJson(bVar));
}
});
if (PhotoJavascriptInterface.this.mFabricChooseImageOptions.sourceType.equals("album")) {
AppPermission.requestPermissions(PhotoJavascriptInterface.this.mActivity, 9, photoPermissionRationale, PermissionConfig.Storage.WRITE_EXTERNAL_STORAGE, PermissionConfig.Storage.READ_EXTERNAL_STORAGE, PermissionConfig.Camera.CAMERA);
} else if (PhotoJavascriptInterface.this.mFabricChooseImageOptions.sourceType.equals("camera")) {
AppPermission.requestPermissions(PhotoJavascriptInterface.this.mActivity, 10, photoPermissionRationale, PermissionConfig.Storage.WRITE_EXTERNAL_STORAGE, PermissionConfig.Storage.READ_EXTERNAL_STORAGE, PermissionConfig.Camera.CAMERA);
} else if (PhotoJavascriptInterface.this.mFabricChooseImageOptions.sourceType.equals("all")) {
if (Build.VERSION.SDK_INT >= 30) {
AppPermission.requestPermissions(PhotoJavascriptInterface.this.mActivity, 10, photoPermissionRationale, PermissionConfig.Storage.WRITE_EXTERNAL_STORAGE, PermissionConfig.Storage.READ_EXTERNAL_STORAGE, PermissionConfig.Camera.CAMERA);
return;
}
if (!TextUtils.isEmpty(PhotoJavascriptInterface.this.mFabricChooseImageOptions.sizeType) && !TextUtils.equals("compressed", PhotoJavascriptInterface.this.mFabricChooseImageOptions.sizeType) && !TextUtils.equals("original", PhotoJavascriptInterface.this.mFabricChooseImageOptions.sizeType) && PhotoJavascriptInterface.this.mFabricChooseImageOptions.sizeType.startsWith("0.")) {
UploadManager.sizeType = PhotoJavascriptInterface.this.mFabricChooseImageOptions.sizeType;
}
UploadManager.instance().checkPermission();
}
}
});
}
@JavascriptInterface
public void closePreviewImage(String str, String str2) {
int size = WebActivities.getActivityStack().size();
int i9 = 0;
while (true) {
if (i9 >= size) {
break;
}
Activity activity = WebActivities.getActivityStack().get(i9);
if (activity instanceof ImagePreviewActivity) {
activity.finish();
break;
}
i9++;
}
this.mBridgeWebView.mBridgeHelper.sendResponse(new FabricCallBackData(""), str2, true);
}
public Bitmap getBitmap(String str) {
URL url;
Bitmap bitmap = null;
try {
url = new URL(str);
} catch (MalformedURLException e9) {
e9.printStackTrace();
url = null;
}
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) HttpInstrumentation.openConnection(url.openConnection());
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
bitmap = BitmapFactoryInstrumentation.decodeStream(inputStream);
inputStream.close();
return bitmap;
} catch (IOException e10) {
e10.printStackTrace();
return bitmap;
}
}
@JavascriptInterface
public void previewImage(String str, String str2) {
this.mPreviewImageCallbackId = str2;
this.mFabricPreviewImageOptions = (FabricPreviewImageOptions) GsonInstrumentation.fromJson(new Gson(), str, (Class<Object>) FabricPreviewImageOptions.class);
this.mBridgeWebView.post(new Runnable() {
@Override
public void run() {
ImagePreviewActivity.launchJFWebviewActivity(PhotoJavascriptInterface.this.mActivity, PhotoJavascriptInterface.this.mFabricPreviewImageOptions, 11);
}
});
}
@JavascriptInterface
public void saveImageToPhotosAlbum(String str, String str2) {
this.mBridgeWebView.post(new AnonymousClass3((FabricPhotoSaveImageToPhotosAlbumOptions) GsonInstrumentation.fromJson(new Gson(), str, (Class<Object>) FabricPhotoSaveImageToPhotosAlbumOptions.class), str2));
}
public String savePhoto(Context context, Bitmap bitmap) {
File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String str = externalStoragePublicDirectory.getAbsolutePath() + "/" + System.currentTimeMillis() + ".jpg";
File file = new File(str);
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e9) {
e9.printStackTrace();
}
context.sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(file)));
return str;
}
public PhotoJavascriptInterface(BridgeHelper bridgeHelper) {
super(bridgeHelper);
this.mChooseImageCallbackId = "";
this.mPreviewImageCallbackId = "";
}
}