TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c

以下内容为反编译后的 MediaApiPlugin.java 源代码,内容仅作参考


package com.tencent.mobileqq.jsp;

import NS_MOBILE_FEEDS.e_attribute;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import com.tencent.av.camera.QavCameraUsage;
import com.tencent.av.camera.config.CameraConfigParser;
import com.tencent.av.ui.GetIsLTUserActivity;
import com.tencent.biz.troop.TroopMemberApiClient;
import com.tencent.biz.webviewbase.AbsBaseWebViewActivity;
import com.tencent.common.app.AppInterface;
import com.tencent.common.app.BaseApplicationImpl;
import com.tencent.common.config.AppSetting;
import com.tencent.image.JpegExifReader;
import com.tencent.mobileqq.activity.aio.SessionInfo;
import com.tencent.mobileqq.activity.photo.MimeHelper;
import com.tencent.mobileqq.activity.photo.PhotoListActivity;
import com.tencent.mobileqq.activity.richmedia.FlowCameraConstant;
import com.tencent.mobileqq.activity.richmedia.FlowComponentInterface;
import com.tencent.mobileqq.activity.richmedia.view.EmoWindow;
import com.tencent.mobileqq.activity.shortvideo.ShortVideoPreviewActivity;
import com.tencent.mobileqq.app.AppConstants;
import com.tencent.mobileqq.app.DeviceProfileManager;
import com.tencent.mobileqq.app.ThreadManager;
import com.tencent.mobileqq.business.sougou.DictFileUtil;
import com.tencent.mobileqq.earlydownload.EarlyDownloadManager;
import com.tencent.mobileqq.earlydownload.handler.QQShortVideoHandler;
import com.tencent.mobileqq.filemanager.data.FMConstants;
import com.tencent.mobileqq.pic.CompressInfo;
import com.tencent.mobileqq.pic.compress.CompressOperator;
import com.tencent.mobileqq.pluginsdk.BasePluginActivity;
import com.tencent.mobileqq.remind.Remind;
import com.tencent.mobileqq.shortvideo.ShortVideoConstants;
import com.tencent.mobileqq.shortvideo.ShortVideoUtils;
import com.tencent.mobileqq.shortvideo.VideoEnvironment;
import com.tencent.mobileqq.troop.activity.VideoRecordActivity;
import com.tencent.mobileqq.troop.utils.TroopRewardUtil;
import com.tencent.mobileqq.troop.utils.TroopUtils;
import com.tencent.mobileqq.utils.Base64Util;
import com.tencent.mobileqq.utils.NetworkUtil;
import com.tencent.mobileqq.webview.swift.JsBridgeListener;
import com.tencent.mobileqq.webview.swift.WebViewPlugin;
import com.tencent.mobileqq.webviewplugin.WebUiUtils;
import com.tencent.mobileqq.widget.QQProgressDialog;
import com.tencent.mobileqq.widget.QQToast;
import com.tencent.qphone.base.util.BaseApplication;
import com.tencent.qphone.base.util.QLog;
import com.tencent.tim.R;
import com.tencent.util.IOUtils;
import com.tencent.widget.XPanelContainer;
import cooperation.peak.PeakConstants;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import wns_proxy.HttpRsp;
public class MediaApiPlugin extends WebViewPlugin implements TroopMemberApiClient.Callback, QQProgressDialog.Callback {
    public static final String A = "videoSizeLimit";
    public static final String B = "videoDurationLimit";
    public static final String C = "media";
    static final byte f90028a = 1;
    static final String f24514a = UiApiPlugin.class.getSimpleName();
    static final byte f90029b = 2;
    static final String f24515b = "getMediaParam";
    static final byte f90030c = 3;
    static final String f24516c = "callback";
    static final byte d = 4;
    static final String f24517d = "calledFromOpenApi";
    static final byte e = 5;
    static final String f24518e = "match";
    static final String f = "data";
    public static final String g = "thumbData";
    static final String h = "mediaType";
    static final String i = "imageID";
    public static final String j = "videoID";
    public static final String k = "videoSize";
    public static final String l = "videoDuration";
    static final String m = "retCode";
    static final String n = "msg";
    static final String o = "statusCode";
    static final String p = "scaleMode";
    static final String q = "getPicture";
    static final String r = "getPictureV2";
    static final String s = "getLocalImageV2";
    static final String t = "takeRewardVideo";
    static final String u = "previewLocalVideo";
    static final String v = "getIsLTUser";
    protected static final String w = "saveImage";
    public static final String x = "maxProportion";
    public static final String y = "minProportion";
    public static final String z = "imageSizeLimit";
    TroopMemberApiClient f24519a;
    public QQProgressDialog f24520a;
    private Thread f24521a;

    public MediaApiPlugin() {
        this.mPluginNameSpace = C;
    }

    @Override
    public boolean handleJsRequest(JsBridgeListener jsBridgeListener, String str, String str2, String str3, String... strArr) {
        if (C.equals(str2)) {
            boolean z2 = jsBridgeListener != null && jsBridgeListener.f34580a;
            addOpenApiListenerIfNeeded(str3, jsBridgeListener);
            if ((q.equals(str3) || r.equals(str3)) && strArr.length == 1) {
                try {
                    JSONObject jSONObject = new JSONObject(strArr[0]);
                    jSONObject.put(Remind.RemindColumns.f27009c, str3);
                    String optString = jSONObject.optString("callback");
                    if (TextUtils.isEmpty(optString) && !z2) {
                        return true;
                    }
                    int optInt = jSONObject.optInt("source", 0);
                    BaseApplication context = BaseApplicationImpl.getContext();
                    if (optInt == 0) {
                        int optInt2 = jSONObject.optInt(h, 0);
                        double optDouble = jSONObject.optDouble(x, 2.0d);
                        double optDouble2 = jSONObject.optDouble(y, 0.6d);
                        int optInt3 = jSONObject.optInt(z, 8192) * 1024;
                        long optLong = jSONObject.optLong(A, 512000L) * 1024;
                        long optLong2 = jSONObject.optLong(B, 120L);
                        Activity a2 = this.mRuntime.a();
                        String account = this.mRuntime.m9632a().getAccount();
                        boolean z3 = a2 instanceof AbsBaseWebViewActivity;
                        boolean z4 = a2 instanceof WebUiUtils.MediaApiPluginInterface;
                        if (z3 || z4 || this.mRuntime.m9633a() != null) {
                            Intent intent = new Intent();
                            if (z4 && ((WebUiUtils.MediaApiPluginInterface) a2).m9722a()) {
                                intent.setClass(a(), PhotoListActivity.class);
                                intent.putExtra("PhotoConst.IS_CALL_IN_PLUGIN", true);
                                intent.putExtra("PhotoConst.PLUGIN_APK", ((WebUiUtils.MediaApiPluginInterface) a2).d());
                                intent.putExtra("PhotoConst.PLUGIN_NAME", ((WebUiUtils.MediaApiPluginInterface) a2).a());
                                intent.putExtra("PhotoConst.UIN", this.mRuntime.m9632a().getCurrentAccountUin());
                            } else {
                                intent.setClass(a2, PhotoListActivity.class);
                            }
                            intent.putExtra("PhotoConst.INIT_ACTIVITY_CLASS_NAME", a2.getClass().getName());
                            intent.putExtra("PhotoConst.INIT_ACTIVITY_PACKAGE_NAME", "com.tencent.tim");
                            if (optInt2 == 0) {
                                int optInt4 = jSONObject.optInt("max", 1);
                                intent.putExtra("PhotoConst.MAXUM_SELECTED_NUM", optInt4);
                                if (optInt4 == 1) {
                                    intent.putExtra("PhotoConst.IS_SINGLE_MODE", true);
                                }
                                if (z3) {
                                    ((AbsBaseWebViewActivity) a2).a(this, intent, (byte) 2);
                                } else if (z4) {
                                    ((WebUiUtils.MediaApiPluginInterface) a2).a(this, intent, (byte) 2);
                                } else {
                                    this.mRuntime.m9633a().a(this, intent, (byte) 2);
                                }
                            } else if (optInt2 == 1) {
                                intent.putExtra("PhotoConst.IS_SINGLE_MODE", true);
                                intent.putExtra(PeakConstants.f69365E, 2);
                                intent.putExtra(PeakConstants.f69369I, 2);
                                if (z3) {
                                    ((AbsBaseWebViewActivity) a2).a(this, intent, (byte) 3);
                                } else {
                                    ((WebUiUtils.MediaApiPluginInterface) a2).a(this, intent, (byte) 3);
                                }
                            } else if (optInt2 == 2) {
                                intent.putExtra("uin", account);
                                intent.putExtra("PhotoConst.IS_SINGLE_MODE", true);
                                intent.putExtra(PeakConstants.f69384X, true);
                                intent.putExtra(x, optDouble);
                                intent.putExtra(y, optDouble2);
                                intent.putExtra(z, optInt3);
                                intent.putExtra(PeakConstants.f69369I, 1000 * optLong2);
                                intent.putExtra(PeakConstants.f69365E, 0);
                                intent.putExtra(PeakConstants.f69368H, optLong);
                                if (z3) {
                                    ((AbsBaseWebViewActivity) a2).a(this, intent, (byte) 3);
                                } else {
                                    ((WebUiUtils.MediaApiPluginInterface) a2).a(this, intent, (byte) 3);
                                }
                            }
                            PreferenceManager.getDefaultSharedPreferences(context).edit().putString(f24515b, jSONObject.toString()).putBoolean(f24517d, z2).commit();
                        } else {
                            if (z2) {
                                callJs4OpenApiIfNeeded(str3, 0, "[]");
                            } else {
                                callJs(optString, "2", "[]");
                            }
                            return true;
                        }
                    } else if (optInt == 1) {
                        if (QavCameraUsage.b(BaseApplicationImpl.getContext())) {
                            return true;
                        }
                        File file = new File(AppConstants.bC + "photo/");
                        if (!file.exists() && !file.mkdirs()) {
                            QQToast.a(context, (int) R.string.f64207name_res_0x7f0a16ae, 0).m9833a();
                            if (z2) {
                                callJs4OpenApiIfNeeded(str3, 0, "[]");
                            } else {
                                callJs(optString, "2", "[]");
                            }
                            return true;
                        }
                        String str4 = AppConstants.bC + "photo/" + System.currentTimeMillis() + ".jpg";
                        Uri fromFile = Uri.fromFile(new File(str4));
                        Intent intent2 = new Intent("android.media.action.IMAGE_CAPTURE");
                        intent2.putExtra("output", fromFile);
                        intent2.putExtra("android.intent.extra.videoQuality", 100);
                        if (jSONObject.optBoolean(CameraConfigParser.j, false)) {
                            intent2.putExtra("android.intent.extras.CAMERA_FACING", 1);
                        }
                        try {
                            startActivityForResult(intent2, (byte) 1);
                            PreferenceManager.getDefaultSharedPreferences(context).edit().putString(AppConstants.Preferences.aU, str4).putString(f24515b, jSONObject.toString()).putBoolean(f24517d, z2).commit();
                        } catch (Exception e2) {
                            e2.printStackTrace();
                            QQToast.a(context, (int) R.string.f64211name_res_0x7f0a16b2, 0).m9833a();
                        }
                    }
                } catch (JSONException e3) {
                    e3.printStackTrace();
                }
            } else if (("getLocalImage".equals(str3) || s.equals(str3)) && strArr.length == 1) {
                try {
                    JSONObject jSONObject2 = new JSONObject(strArr[0]);
                    String optString2 = jSONObject2.optString("callback");
                    String optString3 = jSONObject2.optString(i);
                    if (TextUtils.isEmpty(optString2) || TextUtils.isEmpty(optString3)) {
                        return true;
                    }
                    if (this.f24520a == null) {
                        Activity a3 = this.mRuntime.a();
                        this.f24520a = new QQProgressDialog(a3, a3.getResources().getDimensionPixelSize(R.dimen.f39450title_bar_height));
                        this.f24520a.b(R.string.f64560name_res_0x7f0a180f);
                        this.f24520a.a(this);
                    }
                    if (!this.f24520a.isShowing()) {
                        this.f24520a.show();
                    }
                    if (s.equals(str3)) {
                        ThreadManager.a(new seg(this, optString2, jSONObject2.optInt(p, 0), optString3), 5, null, true);
                    } else {
                        ThreadManager.a(new sef(this, optString2, jSONObject2.optInt("outMaxWidth", 1280), jSONObject2.optInt("outMaxHeight", 1280), jSONObject2.optInt("inMinWidth", 1), jSONObject2.optInt("inMinHeight", 1), optString3), 5, null, true);
                    }
                } catch (JSONException e4) {
                    e4.printStackTrace();
                }
            } else if (w.equals(str3) && strArr.length == 1) {
                AtomicBoolean atomicBoolean = new AtomicBoolean(false);
                try {
                    JSONObject jSONObject3 = new JSONObject(strArr[0]);
                    String optString4 = jSONObject3.optString("callback");
                    String string = jSONObject3.getString("content");
                    if (string.startsWith("http://") || string.startsWith("https://")) {
                        if (this.f24520a == null) {
                            Activity a4 = this.mRuntime.a();
                            this.f24520a = new QQProgressDialog(a4, a4.getResources().getDimensionPixelSize(R.dimen.f39450title_bar_height));
                            this.f24520a.b(R.string.f64560name_res_0x7f0a180f);
                            this.f24520a.a(this);
                        }
                        if (!this.f24520a.isShowing()) {
                            this.f24520a.show();
                        }
                        ThreadManager.a(new seb(this, string, optString4, atomicBoolean), 5, null, true);
                    } else {
                        ThreadManager.m4814b().post(new sec(this, string, optString4, atomicBoolean));
                    }
                } catch (OutOfMemoryError e5) {
                    if (QLog.isDevelopLevel()) {
                        QLog.d(f24514a, 4, "saveImage failed:" + e5);
                    }
                    if (!TextUtils.isEmpty(null) && atomicBoolean.compareAndSet(false, true)) {
                        JSONObject jSONObject4 = new JSONObject();
                        try {
                            jSONObject4.put(m, -1);
                            jSONObject4.put("msg", BaseApplicationImpl.getContext().getString(R.string.f61178name_res_0x7f0a0ad7));
                        } catch (JSONException e6) {
                        }
                        if (z2) {
                            callJs(null, jSONObject4.toString());
                        } else {
                            callJs4OpenApiIfNeeded(w, 0, jSONObject4.toString());
                        }
                    }
                } catch (JSONException e7) {
                    if (QLog.isDevelopLevel()) {
                        QLog.d(f24514a, 4, "saveImage failed:" + e7);
                    }
                }
            } else if (t.equals(str3) && strArr.length == 1) {
                try {
                    JSONObject jSONObject5 = new JSONObject(strArr[0]);
                    if (QLog.isColorLevel()) {
                        QLog.d(".troop.troop_reward.video", 2, "takeRewardVideo:" + strArr[0]);
                    }
                    int optInt5 = jSONObject5.optInt(B, 120);
                    AppInterface m9632a = this.mRuntime.m9632a();
                    BaseApplication context2 = BaseApplicationImpl.getContext();
                    ShortVideoUtils.f28518a = ShortVideoUtils.m7871b();
                    if (ShortVideoUtils.f28518a && VideoEnvironment.c(m9632a)) {
                        ShortVideoUtils.a(m9632a);
                        if (!ShortVideoUtils.m7861a()) {
                            if (!NetworkUtil.h(context2)) {
                                QQToast.a(context2, (int) R.string.f63174name_res_0x7f0a12a3, 0).m9833a();
                                return true;
                            }
                            QQShortVideoHandler qQShortVideoHandler = (QQShortVideoHandler) ((EarlyDownloadManager) m9632a.getManager(76)).a(QQShortVideoHandler.f88989b);
                            if (qQShortVideoHandler != null) {
                                qQShortVideoHandler.a(true);
                                if (QLog.isColorLevel()) {
                                    QLog.d(".troop.troop_reward.video", 2, "takeRewardVideo, download so lib:" + qQShortVideoHandler.f88990c);
                                }
                                if (qQShortVideoHandler.f88990c > 0) {
                                    QQToast.a(context2, context2.getString(R.string.f61014name_res_0x7f0a0a33, Integer.valueOf(qQShortVideoHandler.f88990c)), 0).m9833a();
                                } else {
                                    QQToast.a(context2, (int) R.string.f61015name_res_0x7f0a0a34, 0).m9833a();
                                }
                            } else if (QLog.isColorLevel()) {
                                QLog.d(".troop.troop_reward.video", 2, "takeRewardVideo, QQShortVideoHandler==null");
                            }
                            return true;
                        } else if (QavCameraUsage.b(BaseApplicationImpl.getContext())) {
                            QQToast.a(context2, (int) R.string.f59806name_res_0x7f0a057a, 0).m9833a();
                            if (QLog.isColorLevel()) {
                                QLog.d(".troop.troop_reward.video", 2, "takeRewardVideo, AVCameraUsed return");
                            }
                            return true;
                        } else {
                            Intent intent3 = new Intent(context2, VideoRecordActivity.class);
                            intent3.putExtra(FlowCameraConstant.f15531a, XPanelContainer.f97471c);
                            intent3.putExtra(VideoEnvironment.f28553b, DeviceProfileManager.m4227a().a(DeviceProfileManager.DpcNames.SV658Cfg.name(), (String) null));
                            intent3.putExtra(VideoEnvironment.f28558c, DeviceProfileManager.m4227a().m4234a(DeviceProfileManager.AccountDpcManager.DpcAccountNames.picpredownload_whitelist.name()));
                            intent3.putExtra(FlowCameraConstant.i, true);
                            intent3.putExtra("PhotoConst.INIT_ACTIVITY_PACKAGE_NAME", "com.tencent.tim");
                            intent3.putExtra(VideoRecordActivity.e, optInt5 * 1000);
                            intent3.putExtra(VideoRecordActivity.g, 1);
                            intent3.putExtra(FlowComponentInterface.j, true);
                            intent3.putExtra(PeakConstants.bu, new SessionInfo());
                            startActivityForResult(intent3, (byte) 4);
                        }
                    } else {
                        QQToast.a(context2, (int) R.string.f61016name_res_0x7f0a0a35, 0).m9833a();
                        if (QLog.isColorLevel()) {
                            QLog.w(".troop.troop_reward.video", 2, "takeRewardVideo, cann't support shortVideo");
                        }
                    }
                    PreferenceManager.getDefaultSharedPreferences(context2).edit().putString(f24515b, jSONObject5.toString()).putBoolean(f24517d, z2).commit();
                } catch (JSONException e8) {
                    e8.printStackTrace();
                }
            } else if (u.equals(str3) && strArr.length == 1) {
                try {
                    JSONObject jSONObject6 = new JSONObject(strArr[0]);
                    if (QLog.isColorLevel()) {
                        QLog.d("MediaApiPlugin", 2, "previewLocalVideo:" + jSONObject6);
                    }
                    a(this.mRuntime.a(), jSONObject6.optString("path"), jSONObject6.optLong("videoSize"), jSONObject6.optLong("videoDuration"));
                } catch (Exception e9) {
                    if (QLog.isColorLevel()) {
                        QLog.w("MediaApiPlugin", 2, "previewLocalVideo exp", e9);
                    }
                }
            } else if (v.equals(str3) && strArr.length >= 1) {
                try {
                    JSONObject jSONObject7 = new JSONObject(strArr[0]);
                    String optString5 = jSONObject7.optString("callback");
                    BaseApplication context3 = BaseApplicationImpl.getContext();
                    startActivityForResult(new Intent(context3, GetIsLTUserActivity.class), (byte) 5);
                    PreferenceManager.getDefaultSharedPreferences(context3).edit().putString(f24515b, jSONObject7.toString()).putBoolean(f24517d, z2).commit();
                    if (QLog.isColorLevel()) {
                        QLog.w("MediaApiPlugin", 2, "WL_DEBUG GetIsLTUser args[0] = " + strArr[0] + "callback = " + optString5);
                    }
                } catch (Exception e10) {
                    if (QLog.isColorLevel()) {
                        QLog.w("MediaApiPlugin", 2, "WL_DEBUG GetIsLTUser e = " + e10);
                    }
                }
            }
            return true;
        }
        return false;
    }

    @Override
    public void onActivityResult(Intent intent, byte b2, int i2) {
        String[] strArr;
        super.onActivityResult(intent, b2, i2);
        BaseApplication context = BaseApplicationImpl.getContext();
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        String string = defaultSharedPreferences.getString(AppConstants.Preferences.aU, "");
        String string2 = defaultSharedPreferences.getString(f24515b, "");
        boolean z2 = defaultSharedPreferences.getBoolean(f24517d, false);
        PreferenceManager.getDefaultSharedPreferences(context).edit().remove(AppConstants.Preferences.aU).remove(f24515b).remove(f24517d).commit();
        if (!TextUtils.isEmpty(string2) || z2) {
            try {
                JSONObject jSONObject = new JSONObject(string2);
                String optString = jSONObject.optString(Remind.RemindColumns.f27009c);
                String optString2 = jSONObject.optString("callback");
                if (!TextUtils.isEmpty(optString2) || z2) {
                    if (b2 == 1 || b2 == 2) {
                        if (i2 == -1) {
                            if (b2 == 1) {
                                strArr = new String[]{string};
                            } else {
                                ArrayList<String> stringArrayListExtra = intent != null ? intent.getStringArrayListExtra("PhotoConst.PHOTO_PATHS") : null;
                                if (stringArrayListExtra == null || stringArrayListExtra.size() == 0) {
                                    if (z2) {
                                        callJs4OpenApiIfNeeded(optString, 0, "[]");
                                        return;
                                    } else {
                                        callJs(optString2, "2", "[]");
                                        return;
                                    }
                                }
                                strArr = (String[]) stringArrayListExtra.toArray(new String[stringArrayListExtra.size()]);
                            }
                            if (jSONObject.optBoolean("urlOnly", false)) {
                                try {
                                    JSONArray jSONArray = new JSONArray();
                                    for (String str : strArr) {
                                        JSONObject jSONObject2 = new JSONObject();
                                        jSONObject2.put("data", "");
                                        jSONObject2.put(i, str);
                                        jSONObject2.put(f24518e, 0);
                                        jSONArray.put(jSONObject2);
                                    }
                                    if (z2) {
                                        callJs4OpenApiIfNeeded(optString, 0, jSONArray.toString());
                                        return;
                                    } else {
                                        callJs(optString2, "0", jSONArray.toString());
                                        return;
                                    }
                                } catch (JSONException e2) {
                                    if (z2) {
                                        callJs4OpenApiIfNeeded(optString, 0, "[]");
                                        return;
                                    } else {
                                        callJs(optString2, "2", "[]");
                                        return;
                                    }
                                }
                            }
                            if (this.f24520a == null) {
                                Activity a2 = this.mRuntime.a();
                                this.f24520a = new QQProgressDialog(a2, a2.getResources().getDimensionPixelSize(R.dimen.f39450title_bar_height));
                                this.f24520a.b(R.string.f64560name_res_0x7f0a180f);
                                this.f24520a.a(this);
                            }
                            if (this.f24521a != null) {
                                this.f24521a.interrupt();
                            }
                            if (!this.f24520a.isShowing()) {
                                this.f24520a.show();
                            }
                            if (r.equals(optString)) {
                                this.f24521a = new see(this, optString2, jSONObject.optInt(p, 0), strArr);
                            } else {
                                this.f24521a = new sed(this, optString2, z2, optString, jSONObject.optInt("outMaxWidth", 1280), jSONObject.optInt("outMaxHeight", 1280), jSONObject.optInt("inMinWidth", 1), jSONObject.optInt("inMinHeight", 1), strArr);
                            }
                            ThreadManager.a(this.f24521a, 5, null, true);
                        } else if (z2) {
                            callJs4OpenApiIfNeeded(optString, 0, "[]");
                        } else {
                            callJs(optString2, "1", "[]");
                        }
                    } else if (b2 == 3) {
                        if (i2 == -1) {
                            String stringExtra = intent != null ? intent.getStringExtra("PhotoConst.SINGLE_PHOTO_PATH") : null;
                            boolean z3 = intent != null && intent.getBooleanExtra(PeakConstants.bv, false);
                            long longExtra = intent != null ? intent.getLongExtra(PeakConstants.bx, 0L) : 0L;
                            long longExtra2 = intent != null ? intent.getLongExtra(ShortVideoConstants.f, 0L) : 0L;
                            if (stringExtra == null) {
                            }
                            if (z3) {
                                JSONArray jSONArray2 = new JSONArray();
                                JSONObject a3 = a(stringExtra);
                                try {
                                    a3.put("videoDuration", longExtra2 / 1000);
                                    a3.put("videoSize", longExtra / 1024);
                                    a3.put(h, 1);
                                } catch (JSONException e3) {
                                    e3.printStackTrace();
                                }
                                jSONArray2.put(a3);
                                callJs(optString2, "0", jSONArray2.toString());
                                return;
                            }
                            this.f24521a = new sed(this, optString2, z2, optString, jSONObject.optInt("outMaxWidth", 2000), jSONObject.optInt("outMaxHeight", 3000), jSONObject.optInt("inMinWidth", 0), jSONObject.optInt("inMinHeight", 0), new String[]{stringExtra});
                            ThreadManager.a(this.f24521a, 5, null, true);
                        }
                    } else if (b2 == 4) {
                        String stringExtra2 = intent != null ? intent.getStringExtra("video_path") : null;
                        if (stringExtra2 != null) {
                            long j2 = 0;
                            if (Build.VERSION.SDK_INT >= 10) {
                                MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
                                mediaMetadataRetriever.setDataSource(stringExtra2);
                                j2 = Long.parseLong(mediaMetadataRetriever.extractMetadata(9));
                            }
                            long length = new File(stringExtra2).length();
                            JSONObject a4 = a(stringExtra2);
                            try {
                                a4.put("videoDuration", j2 / 1000);
                                a4.put("videoSize", length / 1024);
                            } catch (JSONException e4) {
                                e4.printStackTrace();
                            }
                            callJs(optString2, "0", a4.toString());
                        }
                    } else if (b2 == 5) {
                        int intExtra = intent.getIntExtra("pstnGrayFlag", 0);
                        boolean booleanExtra = intent.getBooleanExtra("isBindingContact", false);
                        boolean z4 = intExtra != 0;
                        int i3 = 0;
                        if (z4 && booleanExtra) {
                            i3 = 1;
                        } else if (z4 && !booleanExtra) {
                            i3 = 2;
                        }
                        callJs(optString2, String.valueOf(i3));
                        if (QLog.isColorLevel()) {
                            QLog.w("MediaApiPlugin", 2, "GetIsLTUser pstnGrayFlag = " + intExtra + "|" + booleanExtra + "|" + z4 + "|" + i3);
                        }
                    }
                }
            } catch (JSONException e5) {
                e5.printStackTrace();
            }
        }
    }

    private JSONObject a(String str) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
        Bitmap a2 = ShortVideoUtils.a((Context) null, str);
        StringBuilder sb = new StringBuilder("data:image/jpeg;base64,");
        if (a2 != null) {
            a2.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream);
            a2.recycle();
        }
        sb.append(Base64Util.encodeToString(byteArrayOutputStream.toByteArray(), 2));
        JSONObject jSONObject = new JSONObject();
        try {
            try {
                jSONObject.put(g, sb);
                jSONObject.put(j, str);
                if (byteArrayOutputStream != null) {
                    try {
                        byteArrayOutputStream.flush();
                        byteArrayOutputStream.close();
                    } catch (IOException e2) {
                        e2.printStackTrace();
                    }
                }
            } catch (JSONException e3) {
                e3.printStackTrace();
                if (byteArrayOutputStream != null) {
                    try {
                        byteArrayOutputStream.flush();
                        byteArrayOutputStream.close();
                    } catch (IOException e4) {
                        e4.printStackTrace();
                    }
                }
            }
            return jSONObject;
        } catch (Throwable th) {
            if (byteArrayOutputStream != null) {
                try {
                    byteArrayOutputStream.flush();
                    byteArrayOutputStream.close();
                } catch (IOException e5) {
                    e5.printStackTrace();
                }
            }
            throw th;
        }
    }

    @Override
    public void onDestroy() {
        if (this.f24521a != null) {
            this.f24521a.interrupt();
        }
        if (this.f24520a != null && this.f24520a.isShowing()) {
            this.f24520a.dismiss();
        }
        if (this.f24519a != null) {
            this.f24519a.b();
        }
        super.onDestroy();
    }

    @Override
    public void mo6800a() {
        if (this.f24521a != null) {
            this.f24521a.interrupt();
        }
    }

    @Override
    public void a(Bundle bundle) {
        if (bundle == null) {
        }
    }

    public static final String a(String str, String str2, String str3, TroopRewardUtil.OnUploadImageListener onUploadImageListener) {
        HttpURLConnection httpURLConnection;
        String str4;
        String str5;
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return null;
        }
        String a2 = a(str3, 0);
        if (TextUtils.isEmpty(a2)) {
            if (QLog.isColorLevel()) {
                QLog.d(f24514a, 2, "compressUploadImage failed: path = " + str3);
            }
            onUploadImageListener.a((String) null);
            return null;
        }
        HttpURLConnection httpURLConnection2 = null;
        String uuid = UUID.randomUUID().toString();
        try {
            try {
                httpURLConnection = (HttpURLConnection) new URL("http://pay.qun.qq.com/cgi-bin/group_pay/reward/upload_img").openConnection();
                try {
                    try {
                        httpURLConnection.setConnectTimeout(5000);
                        httpURLConnection.setReadTimeout(30000);
                        httpURLConnection.setDoOutput(true);
                        httpURLConnection.setDoInput(true);
                        httpURLConnection.setUseCaches(false);
                        httpURLConnection.setRequestMethod("POST");
                        httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
                        httpURLConnection.setRequestProperty("User-Agent", "android_" + Build.VERSION.SDK + "_" + Build.DEVICE + "_" + Build.VERSION.RELEASE + "_" + AppSetting.g);
                        httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + uuid);
                        httpURLConnection.setRequestProperty("Cookie", "uin=" + str + ";skey=" + str2);
                        DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
                        File file = new File(a2);
                        String name = file.getName();
                        String str6 = null;
                        if (name.endsWith(".png")) {
                            str6 = "image/png";
                        } else if (name.endsWith(".jpeg") || name.endsWith(".jpg")) {
                            str6 = "image/jpg";
                        } else if (name.endsWith(".bmp")) {
                            str6 = "image/bmp";
                        } else if (name.endsWith(EmoWindow.f86769c)) {
                            str6 = MimeHelper.f86338c;
                        }
                        str6 = (str6 == null || str6.equals("")) ? "application/octet-stream" : "application/octet-stream";
                        StringBuffer stringBuffer = new StringBuffer();
                        stringBuffer.append(IOUtils.LINE_SEPARATOR_WINDOWS).append("--").append(uuid).append(IOUtils.LINE_SEPARATOR_WINDOWS);
                        stringBuffer.append("Content-Disposition: form-data; name=\"pic_up\"; filename=\"" + name + "\"\r\n");
                        stringBuffer.append("Content-Type:" + str6 + HttpRsp.HTTP_HEADER_END);
                        dataOutputStream.write(stringBuffer.toString().getBytes());
                        FileInputStream fileInputStream = new FileInputStream(file);
                        long length = file.length();
                        int min = Math.min(fileInputStream.available(), 262144);
                        int i2 = 0;
                        byte[] bArr = new byte[min];
                        try {
                            try {
                                int read = fileInputStream.read(bArr, 0, min);
                                while (read > 0) {
                                    dataOutputStream.write(bArr, 0, min);
                                    i2 += min;
                                    onUploadImageListener.a((int) ((i2 * 100) / length));
                                    min = Math.min(fileInputStream.available(), 262144);
                                    read = fileInputStream.read(bArr, 0, min);
                                }
                                fileInputStream.close();
                                dataOutputStream.write(("\r\n--" + uuid + IOUtils.LINE_SEPARATOR_WINDOWS).getBytes());
                                dataOutputStream.write(("Content-Disposition: form-data; name=\"bkn\"\r\n\r\n" + TroopUtils.b(str2)).getBytes());
                                dataOutputStream.write(("\r\n--" + uuid + "--\r\n").getBytes());
                                dataOutputStream.flush();
                                dataOutputStream.close();
                                StringBuffer stringBuffer2 = new StringBuffer();
                                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
                                while (true) {
                                    String readLine = bufferedReader.readLine();
                                    if (readLine == null) {
                                        break;
                                    }
                                    stringBuffer2.append(readLine).append("\n");
                                }
                                str4 = stringBuffer2.toString();
                                try {
                                    bufferedReader.close();
                                } catch (Exception e2) {
                                    QLog.d("qqshare", 2, "发送POST请求出错。http://pay.qun.qq.com/cgi-bin/group_pay/reward/upload_img");
                                    if (httpURLConnection != null) {
                                        httpURLConnection.disconnect();
                                        str5 = str4;
                                        if (onUploadImageListener != null) {
                                        }
                                    }
                                    str5 = str4;
                                    if (onUploadImageListener != null) {
                                    }
                                }
                            } catch (Throwable th) {
                                httpURLConnection2 = httpURLConnection;
                                th = th;
                                try {
                                    fileInputStream.close();
                                    throw th;
                                } catch (Exception e3) {
                                    httpURLConnection = httpURLConnection2;
                                    str4 = null;
                                    QLog.d("qqshare", 2, "发送POST请求出错。http://pay.qun.qq.com/cgi-bin/group_pay/reward/upload_img");
                                    if (httpURLConnection != null) {
                                    }
                                    str5 = str4;
                                    if (onUploadImageListener != null) {
                                    }
                                }
                            }
                        } catch (OutOfMemoryError e4) {
                            QLog.e("troopreward", 2, "uploadImage OOM: fileSize = " + file.length() + ", name = " + file.getAbsolutePath());
                            dataOutputStream.flush();
                            dataOutputStream.close();
                            httpURLConnection.disconnect();
                            httpURLConnection2 = null;
                            try {
                                onUploadImageListener.a((String) null);
                                fileInputStream.close();
                                if (0 != 0) {
                                    httpURLConnection2.disconnect();
                                    return null;
                                }
                                return null;
                            } catch (Throwable th2) {
                                th = th2;
                                fileInputStream.close();
                                throw th;
                            }
                        }
                    } catch (Throwable th3) {
                        httpURLConnection2 = httpURLConnection;
                        th = th3;
                        if (httpURLConnection2 != null) {
                        }
                        throw th;
                    }
                } catch (Exception e5) {
                    str4 = null;
                }
            } catch (Throwable th4) {
                th = th4;
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                throw th;
            }
        } catch (Exception e6) {
            httpURLConnection = httpURLConnection2;
            str4 = null;
        }
        if (httpURLConnection != null) {
            httpURLConnection.disconnect();
            str5 = str4;
            if (onUploadImageListener != null) {
                onUploadImageListener.a(str5);
                return str5;
            }
            return str5;
        }
        str5 = str4;
        if (onUploadImageListener != null) {
        }
    }

    public static JSONObject a(String str, int i2, int i3, int i4, int i5) {
        float height;
        StringBuilder sb;
        FileInputStream fileInputStream;
        StringBuilder sb2;
        JSONObject jSONObject = new JSONObject();
        File file = new File(str);
        if (file.length() < 3) {
            throw new IOException();
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(str, options);
        int i6 = options.outWidth;
        int i7 = options.outHeight;
        if (i6 < 0 || i7 < 0) {
            throw new IOException();
        }
        if (i6 < i2 || i7 < i3) {
            jSONObject.put(f24518e, 1);
        } else if (i6 <= i4 && i7 <= i5) {
            try {
                fileInputStream = new FileInputStream(file);
                try {
                    int read = fileInputStream.read();
                    int read2 = fileInputStream.read();
                    int read3 = fileInputStream.read();
                    if (read == 255 && read2 == 216) {
                        sb2 = new StringBuilder("data:image/jpeg;base64,");
                    } else if (read == 66 && read2 == 77) {
                        sb2 = new StringBuilder("data:image/bmp;base64,");
                    } else if (read == 137 && read2 == 80) {
                        sb2 = new StringBuilder("data:image/png;base64,");
                    } else if (read == 71 && read2 == 73) {
                        sb2 = new StringBuilder("data:image/gif;base64,");
                    } else {
                        sb2 = new StringBuilder("data:base64,");
                    }
                    sb2.append(Base64Util.encodeToString(new byte[]{(byte) read, (byte) read2, (byte) read3}, 2));
                    byte[] bArr = new byte[DictFileUtil.f88383b];
                    while (true) {
                        int read4 = fileInputStream.read(bArr);
                        if (read4 != -1) {
                            if (Thread.currentThread().isInterrupted()) {
                                throw new InterruptedException();
                            }
                            if (read4 < 30720) {
                                byte[] bArr2 = new byte[read4];
                                System.arraycopy(bArr, 0, bArr2, 0, read4);
                                sb2.append(Base64Util.encodeToString(bArr2, 2));
                            } else {
                                sb2.append(Base64Util.encodeToString(bArr, 2));
                            }
                        } else {
                            jSONObject.put(f24518e, 0);
                            jSONObject.put("data", sb2);
                            jSONObject.put(i, str);
                            if (fileInputStream != null) {
                                fileInputStream.close();
                            }
                        }
                    }
                } catch (Throwable th) {
                    th = th;
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
                fileInputStream = null;
            }
        } else {
            int max = Math.max(i6 / i4, i7 / i5);
            options.inJustDecodeBounds = false;
            int i8 = max | (max >>> 1);
            int i9 = i8 | (i8 >>> 2);
            int i10 = i9 | (i9 >>> 4);
            int i11 = i10 | (i10 >>> 8);
            options.inSampleSize = ((i11 | (i11 >>> 16)) + 1) >>> 1;
            Bitmap bitmap = null;
            try {
                bitmap = BitmapFactory.decodeFile(str, options);
            } catch (OutOfMemoryError e2) {
            }
            if (bitmap == null) {
                return jSONObject;
            }
            if (i6 * i5 > i7 * i4) {
                height = i4 / bitmap.getWidth();
            } else {
                height = i5 / bitmap.getHeight();
            }
            Matrix matrix = new Matrix();
            switch (JpegExifReader.readOrientation(str)) {
                case 2:
                    matrix.setScale(-height, height);
                    break;
                case 3:
                    matrix.setScale(height, height);
                    matrix.postRotate(180.0f);
                    break;
                case 4:
                    matrix.setScale(height, -height);
                    break;
                case 5:
                    matrix.setScale(height, -height);
                    matrix.postRotate(90.0f);
                    break;
                case 6:
                    matrix.setScale(height, height);
                    matrix.postRotate(90.0f);
                    break;
                case 7:
                    matrix.setScale(-height, height);
                    matrix.postRotate(90.0f);
                    break;
                case 8:
                    matrix.setScale(height, height);
                    matrix.postRotate(270.0f);
                    break;
                default:
                    matrix.setScale(height, height);
                    break;
            }
            Bitmap createBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            if (bitmap != createBitmap) {
                bitmap.recycle();
            }
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
            String str2 = options.outMimeType;
            if ("image/png".equalsIgnoreCase(str2) || MimeHelper.f86338c.equals(str2) || "image/bmp".equals(str2)) {
                sb = new StringBuilder("data:image/png;base64,");
                createBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
            } else {
                sb = new StringBuilder("data:image/jpeg;base64,");
                createBitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream);
            }
            createBitmap.recycle();
            sb.append(Base64Util.encodeToString(byteArrayOutputStream.toByteArray(), 2));
            jSONObject.put(f24518e, 0);
            jSONObject.put("data", sb);
            jSONObject.put(i, str);
        }
        return jSONObject;
    }

    public String a(byte[] bArr) {
        String str;
        String str2;
        boolean z2;
        FileOutputStream fileOutputStream;
        FileOutputStream fileOutputStream2 = null;
        File file = new File(AppConstants.bH);
        file.mkdirs();
        if (!file.canWrite()) {
            throw new IOException("dir can not write");
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
        if (options.outWidth <= 0 || options.outHeight <= 0) {
            throw new IllegalArgumentException("not image data");
        }
        if ("image/jpeg".equals(options.outMimeType)) {
            str = ".jpg";
        } else if ("image/bmp".equals(options.outMimeType)) {
            str = ".bmp";
        } else if ("image/png".equals(options.outMimeType)) {
            str = ".png";
        } else {
            str = MimeHelper.f86338c.equals(options.outMimeType) ? EmoWindow.f86769c : null;
        }
        if (str != null) {
            str2 = AppConstants.bH + "wv_" + System.currentTimeMillis() + str;
            File file2 = new File(str2);
            try {
                fileOutputStream = new FileOutputStream(file2);
                try {
                    fileOutputStream.write(bArr);
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e2) {
                        }
                    }
                    z2 = true;
                } catch (Throwable th) {
                    th = th;
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e3) {
                        }
                    }
                    if (file2.exists()) {
                        file2.delete();
                    }
                    if (QLog.isColorLevel()) {
                        QLog.d(f24514a, 2, "exception occur while writing file in saveImage");
                    }
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
                fileOutputStream = null;
            }
        } else {
            str2 = AppConstants.bH + "wv_" + System.currentTimeMillis() + ".jpg";
            File file3 = new File(str2);
            try {
                FileOutputStream fileOutputStream3 = new FileOutputStream(file3);
                try {
                    boolean compress = BitmapFactory.decodeByteArray(bArr, 0, bArr.length).compress(Bitmap.CompressFormat.JPEG, 75, fileOutputStream3);
                    if (fileOutputStream3 != null) {
                        try {
                            fileOutputStream3.close();
                        } catch (IOException e4) {
                        }
                    }
                    if (!compress) {
                        if (file3.exists()) {
                            file3.delete();
                        }
                        if (QLog.isColorLevel()) {
                            QLog.d(f24514a, 2, "exception occur while compressing bmp in saveImage");
                            z2 = compress;
                        }
                    }
                    z2 = compress;
                } catch (Throwable th3) {
                    th = th3;
                    fileOutputStream2 = fileOutputStream3;
                    if (fileOutputStream2 != null) {
                        try {
                            fileOutputStream2.close();
                        } catch (IOException e5) {
                        }
                    }
                    if (file3.exists()) {
                        file3.delete();
                    }
                    if (QLog.isColorLevel()) {
                        QLog.d(f24514a, 2, "exception occur while compressing bmp in saveImage");
                    }
                    throw th;
                }
            } catch (Throwable th4) {
                th = th4;
            }
        }
        if (z2) {
            Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
            intent.setData(Uri.parse(FMConstants.f23377aY + str2));
            BaseApplicationImpl.getContext().sendBroadcast(intent);
            return str2;
        }
        throw new IOException();
    }

    public static JSONObject m6799a(String str, int i2) {
        StringBuilder sb;
        long currentTimeMillis = System.currentTimeMillis();
        JSONObject jSONObject = new JSONObject();
        File file = new File(str);
        if (file.length() < 3) {
            throw new IOException();
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(str, options);
        int i3 = options.outWidth;
        int i4 = options.outHeight;
        if (QLog.isColorLevel()) {
            QLog.d(f24514a, 2, "packImageObjectV2 realWidth: " + i3 + ", realHeight: " + i4 + ", realSize: " + file.length());
        }
        if (i3 < 0 || i4 < 0) {
            throw new IOException();
        }
        String a2 = a(str, i2);
        BitmapFactory.Options options2 = new BitmapFactory.Options();
        options2.inJustDecodeBounds = false;
        try {
            Bitmap decodeFile = BitmapFactory.decodeFile(a2, options2);
            if (QLog.isColorLevel()) {
                QLog.d(f24514a, 2, "packImageObjectV2 curWidth: " + options2.outWidth + ", curHeight: " + options2.outHeight + ", realSize: " + new File(a2).length());
            }
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
            String str2 = options2.outMimeType;
            if ("image/png".equalsIgnoreCase(str2) || MimeHelper.f86338c.equals(str2) || "image/bmp".equals(str2)) {
                sb = new StringBuilder("data:image/png;base64,");
                decodeFile.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
            } else {
                sb = new StringBuilder("data:image/jpeg;base64,");
                decodeFile.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream);
            }
            decodeFile.recycle();
            sb.append(Base64Util.encodeToString(byteArrayOutputStream.toByteArray(), 2));
            jSONObject.put(f24518e, 0);
            jSONObject.put("data", sb);
            jSONObject.put(i, str);
            if (QLog.isColorLevel()) {
                QLog.d(f24514a, 2, "packImageObjectV2 time: " + (System.currentTimeMillis() - currentTimeMillis));
            }
        } catch (Exception e2) {
            QLog.d(f24514a, 2, e2.toString());
        }
        return jSONObject;
    }

    public static String a(String str, int i2) {
        CompressInfo compressInfo = new CompressInfo(str, i2, 1035);
        CompressOperator.m7313a(compressInfo);
        return compressInfo.f26043e;
    }

    public static void a(Context context, String str, long j2, long j3) {
        Intent intent = new Intent(context, ShortVideoPreviewActivity.class);
        intent.putExtra("file_send_path", str);
        intent.putExtra(ShortVideoConstants.f28456d, j2);
        intent.putExtra(ShortVideoConstants.f, j3);
        intent.putExtra("PhotoConst.INIT_ACTIVITY_CLASS_NAME", context.getClass().getName());
        intent.putExtra("PhotoConst.INIT_ACTIVITY_PACKAGE_NAME", "com.tencent.tim");
        intent.putExtra(ShortVideoPreviewActivity.f16821h, true);
        if (!(context instanceof Activity)) {
            intent.addFlags(e_attribute._IsFrdCommentFamousFeed);
        }
        context.startActivity(intent);
    }

    private Context a() {
        Activity a2 = this.mRuntime.a();
        while (a2 != null && (a2 instanceof BasePluginActivity)) {
            a2 = ((BasePluginActivity) a2).getOutActivity();
        }
        return a2;
    }
}