package o; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.MediaStore; import android.text.TextUtils; import android.webkit.MimeTypeMap; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; /* renamed from: o.Djv, reason: case insensitive filesystem */ /* loaded from: classes.dex */ public final class C0294Djv implements FlutterPlugin, MethodChannel.MethodCallHandler { private MethodChannel a; private Context b; /* renamed from: o.Djv$RVV */ /* loaded from: classes.dex */ public static final class RVV { private RVV() { } public /* synthetic */ RVV(byte b) { this(); } } @Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler public final void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { Integer num; C14957gcv.e(methodCall, ""); C14957gcv.e(result, ""); if (C14957gcv.b((Object) methodCall.method, (Object) "saveImageToGallery")) { byte[] bArr = (byte[]) methodCall.argument("imageBytes"); if (bArr == null || (num = (Integer) methodCall.argument("quality")) == null) { return; } int intValue = num.intValue(); String str = (String) methodCall.argument("name"); Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length); C14957gcv.c(decodeByteArray, ""); result.success(Gg_(decodeByteArray, intValue, str)); return; } if (C14957gcv.b((Object) methodCall.method, (Object) "saveFileToGallery")) { String str2 = (String) methodCall.argument("file"); if (str2 == null) { return; } result.success(a(str2, (String) methodCall.argument("name"))); return; } result.notImplemented(); } private final Uri Gf_(String str, String str2) { String str3; ContentResolver contentResolver; if (str2 == null) { str2 = String.valueOf(System.currentTimeMillis()); } if (Build.VERSION.SDK_INT >= 29) { Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentValues contentValues = new ContentValues(); contentValues.put("_display_name", str2); contentValues.put("relative_path", Environment.DIRECTORY_PICTURES); Uri uri2 = null; if (TextUtils.isEmpty(str)) { str3 = null; } else { MimeTypeMap singleton = MimeTypeMap.getSingleton(); if (str == null) { throw new NullPointerException("null cannot be cast to non-null type java.lang.String"); } String lowerCase = str.toLowerCase(); C14957gcv.c((Object) lowerCase, ""); str3 = singleton.getMimeTypeFromExtension(lowerCase); } if (!TextUtils.isEmpty(str3)) { contentValues.put("mime_type", str3); C14957gcv.e(str3); if (gdZ.e(str3, "video", false)) { uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; contentValues.put("relative_path", Environment.DIRECTORY_MOVIES); } } Context context = this.b; if (context != null && (contentResolver = context.getContentResolver()) != null) { uri2 = contentResolver.insert(uri, contentValues); } C14957gcv.e(uri2); return uri2; } StringBuilder sb = new StringBuilder(); sb.append(Environment.getExternalStorageDirectory().getAbsolutePath()); sb.append(File.separator); sb.append(Environment.DIRECTORY_PICTURES); File file = new File(sb.toString()); if (!file.exists()) { file.mkdir(); } if (str.length() > 0) { StringBuilder sb2 = new StringBuilder(); sb2.append(str2); sb2.append('.'); sb2.append(str); str2 = sb2.toString(); } Uri fromFile = Uri.fromFile(new File(file, str2)); C14957gcv.c(fromFile, ""); return fromFile; } /* JADX WARN: Removed duplicated region for block: B:15:0x0060 */ /* JADX WARN: Removed duplicated region for block: B:6:0x005e */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private final java.util.HashMap Gg_(android.graphics.Bitmap r7, int r8, java.lang.String r9) { /* r6 = this; android.content.Context r0 = r6.b java.lang.String r1 = "jpg" android.net.Uri r9 = r6.Gf_(r1, r9) r1 = 0 r2 = 0 if (r0 == 0) goto L19 android.content.ContentResolver r3 = r0.getContentResolver() // Catch: java.io.IOException -> L17 if (r3 == 0) goto L19 java.io.OutputStream r3 = r3.openOutputStream(r9) // Catch: java.io.IOException -> L17 goto L1a L17: r7 = move-exception goto L6d L19: r3 = r2 L1a: o.C14957gcv.e(r3) // Catch: java.io.IOException -> L17 java.lang.StringBuilder r4 = new java.lang.StringBuilder // Catch: java.io.IOException -> L17 java.lang.String r5 = "ImageGallerySaverPlugin " r4.(r5) // Catch: java.io.IOException -> L17 r4.append(r8) // Catch: java.io.IOException -> L17 java.lang.String r4 = r4.toString() // Catch: java.io.IOException -> L17 java.io.PrintStream r5 = java.lang.System.out // Catch: java.io.IOException -> L17 r5.println(r4) // Catch: java.io.IOException -> L17 android.graphics.Bitmap$CompressFormat r4 = android.graphics.Bitmap.CompressFormat.JPEG // Catch: java.io.IOException -> L17 r7.compress(r4, r8, r3) // Catch: java.io.IOException -> L17 r3.flush() // Catch: java.io.IOException -> L17 r3.close() // Catch: java.io.IOException -> L17 o.C14957gcv.e(r0) // Catch: java.io.IOException -> L17 android.content.Intent r8 = new android.content.Intent // Catch: java.io.IOException -> L17 java.lang.String r3 = "android.intent.action.MEDIA_SCANNER_SCAN_FILE" r8.(r3, r9) // Catch: java.io.IOException -> L17 r0.sendBroadcast(r8) // Catch: java.io.IOException -> L17 r7.recycle() // Catch: java.io.IOException -> L17 o.fBC r7 = new o.fBC // Catch: java.io.IOException -> L17 java.lang.String r8 = r9.toString() // Catch: java.io.IOException -> L17 java.lang.String r0 = "" o.C14957gcv.c(r8, r0) // Catch: java.io.IOException -> L17 java.lang.CharSequence r8 = (java.lang.CharSequence) r8 // Catch: java.io.IOException -> L17 int r8 = r8.length() // Catch: java.io.IOException -> L17 if (r8 <= 0) goto L60 r8 = 1 goto L61 L60: r8 = r1 L61: java.lang.String r9 = r9.toString() // Catch: java.io.IOException -> L17 r7.(r8, r9, r2) // Catch: java.io.IOException -> L17 java.util.HashMap r7 = r7.a() // Catch: java.io.IOException -> L17 goto L7a L6d: o.fBC r8 = new o.fBC java.lang.String r7 = r7.toString() r8.(r1, r2, r7) java.util.HashMap r7 = r8.a() L7a: return r7 */ throw new UnsupportedOperationException("Method not decompiled: o.C0294Djv.Gg_(android.graphics.Bitmap, int, java.lang.String):java.util.HashMap"); } private final HashMap a(String str, String str2) { ContentResolver contentResolver; Context context = this.b; try { File file = new File(str); C14957gcv.e(file, ""); String name = file.getName(); C14957gcv.c((Object) name, ""); Uri Gf_ = Gf_(gdZ.c(name, ""), str2); OutputStream openOutputStream = (context == null || (contentResolver = context.getContentResolver()) == null) ? null : contentResolver.openOutputStream(Gf_); C14957gcv.e(openOutputStream); FileInputStream fileInputStream = new FileInputStream(file); byte[] bArr = new byte[10240]; while (true) { int read = fileInputStream.read(bArr); if (read <= 0) { break; } openOutputStream.write(bArr, 0, read); } openOutputStream.flush(); openOutputStream.close(); fileInputStream.close(); C14957gcv.e(context); context.sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Gf_)); String obj = Gf_.toString(); C14957gcv.c((Object) obj, ""); return new fBC(obj.length() > 0, Gf_.toString(), null).a(); } catch (IOException e) { return new fBC(false, null, e.toString()).a(); } } @Override // io.flutter.embedding.engine.plugins.FlutterPlugin public final void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) { C14957gcv.e(flutterPluginBinding, ""); Context applicationContext = flutterPluginBinding.getApplicationContext(); C14957gcv.c(applicationContext, ""); BinaryMessenger binaryMessenger = flutterPluginBinding.getBinaryMessenger(); C14957gcv.c(binaryMessenger, ""); this.b = applicationContext; MethodChannel methodChannel = new MethodChannel(binaryMessenger, "image_gallery_saver"); this.a = methodChannel; C14957gcv.e(methodChannel); methodChannel.setMethodCallHandler(this); } @Override // io.flutter.embedding.engine.plugins.FlutterPlugin public final void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) { C14957gcv.e(flutterPluginBinding, ""); this.b = null; MethodChannel methodChannel = this.a; C14957gcv.e(methodChannel); methodChannel.setMethodCallHandler(null); this.a = null; } static { new RVV((byte) 0); } }