调研通 v3.0.3版本的 MD5 值为:fe075d21227d488bdb9f6aa09d3b3f35

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


package com.yyt.common.plugin;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.view.WindowManager;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.BuglyStrategy;
import com.xiaomi.mipush.sdk.Constants;
import com.yyt.common.acticity.SetFontSizeActivity;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.eclipse.paho.client.mqttv3.MqttTopic;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@SuppressLint({"NewApi"})
public class Utils extends CordovaPlugin {

    private static final String f11253a = "Utils";

    class a implements Runnable {

        final String f11254a;

        final String f11255b;

        final CallbackContext f11256c;

        a(String str, String str2, CallbackContext callbackContext) {
            this.f11254a = str;
            this.f11255b = str2;
            this.f11256c = callbackContext;
        }

        @Override
        public void run() {
            try {
                HttpResponse execute = new DefaultHttpClient().execute(new HttpGet("https://api.weibo.com/2/short_url/shorten.json?source=" + this.f11254a + "&url_long=" + this.f11255b));
                if (execute.getStatusLine().getStatusCode() == 200) {
                    String entityUtils = EntityUtils.toString(execute.getEntity(), "utf-8");
                    new JSONObject(entityUtils);
                    this.f11256c.success(entityUtils);
                }
            } catch (Exception unused) {
                this.f11256c.success();
            }
        }
    }

    private boolean a(String str, CallbackContext callbackContext) {
        if ("result:error".equals(str)) {
            callbackContext.error(PluginResult.Status.ERROR.name());
            return true;
        }
        callbackContext.success(str);
        return true;
    }

    private void b() {
        Log.i(f11253a, "切换主和备用地址。");
        String i = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.f10953a);
        String i2 = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.f10954b);
        if (com.yyt.common.o.r.p(i) || com.yyt.common.o.r.p(i2)) {
            return;
        }
        com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.f10953a, i2);
        com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.f10954b, i);
    }

    private void c(CallbackContext callbackContext) {
        JSONObject jSONObject = new JSONObject();
        String i = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.j);
        String str = Bugly.SDK_IS_DEV;
        if (i == null || i.equals(Bugly.SDK_IS_DEV)) {
            str = "true";
        }
        com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.j, str);
        try {
            jSONObject.put("isDebug", str);
        } catch (JSONException e2) {
            Log.e("MobilePortal", e2.getMessage());
        }
        callbackContext.success(jSONObject);
    }

    private Boolean d(String str, int i) {
        try {
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setInstanceFollowRedirects(false);
            httpURLConnection.setConnectTimeout(i);
            httpURLConnection.setReadTimeout(i);
            httpURLConnection.connect();
            int responseCode = httpURLConnection.getResponseCode();
            if (responseCode >= 100 && responseCode < 400) {
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        } catch (Exception unused) {
            return Boolean.FALSE;
        }
    }

    @Deprecated
    private void e(JSONArray jSONArray, CallbackContext callbackContext) throws Exception {
        if (com.yyt.common.o.r.p(com.yyt.common.o.s.i(this.cordova.getActivity(), "loginResourcesVersion"))) {
            com.yyt.common.o.r.g(new File(this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/www"));
            com.yyt.common.resources.plugin.q.e(this.cordova.getActivity(), false);
        } else {
            com.yyt.common.resources.plugin.g.c(new File(this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/www/default/preset"), new File(this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/tempPreset"));
            com.yyt.common.resources.plugin.q.e(this.cordova.getActivity(), false);
            com.yyt.common.resources.plugin.a.a(this.cordova.getActivity().getAssets(), "www/default", this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/www/default");
            com.yyt.common.resources.plugin.g.c(new File(this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/tempPreset"), new File(this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/www/default/preset"));
            com.yyt.common.resources.plugin.q.e(this.cordova.getActivity(), true);
        }
        com.yyt.common.o.s.j(this.cordova.getActivity(), "commonResourcesVersion");
        callbackContext.success();
    }

    @Deprecated
    private void f(JSONArray jSONArray, CallbackContext callbackContext) throws Exception {
        if (com.yyt.common.o.r.p(com.yyt.common.o.s.i(this.cordova.getActivity(), "commonResourcesVersion"))) {
            com.yyt.common.o.r.g(new File(this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/www"));
            com.yyt.common.resources.plugin.q.e(this.cordova.getActivity(), false);
        } else {
            com.yyt.common.resources.plugin.q.e(this.cordova.getActivity(), false);
            com.yyt.common.resources.plugin.a.a(this.cordova.getActivity().getAssets(), "www/default/preset", this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/www/default/preset");
            com.yyt.common.resources.plugin.q.e(this.cordova.getActivity(), true);
        }
        com.yyt.common.o.s.j(this.cordova.getActivity(), "loginResourcesVersion");
        callbackContext.success();
    }

    private void g(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException, IOException {
        File file = new File(jSONArray.getString(0));
        if (file.exists()) {
            FileInputStream fileInputStream = new FileInputStream(file);
            int available = fileInputStream.available();
            byte[] bArr = new byte[available];
            fileInputStream.read(bArr);
            JSONObject jSONObject = new JSONObject();
            String str = "";
            for (int i = 0; i < available; i++) {
                str = str + String.format("%02X", Byte.valueOf(bArr[i]));
            }
            jSONObject.put("hexStr", str);
        }
    }

    private String h() {
        this.cordova.getActivity().moveTaskToBack(true);
        return PluginResult.Status.OK.name();
    }

    private JSONObject i(JSONArray jSONArray) throws JSONException {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("serverURL", com.yyt.common.o.s.g(this.cordova.getActivity(), com.yyt.common.d.f10955c));
        jSONObject.put("nativeVersionUrl", com.yyt.common.o.s.g(this.cordova.getActivity(), com.yyt.common.d.f10958f));
        jSONObject.put("resourcesManifestUrl", com.yyt.common.o.s.g(this.cordova.getActivity(), com.yyt.common.d.f10957e));
        return jSONObject;
    }

    @Deprecated
    private void j(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException {
        String i = com.yyt.common.o.s.i(this.cordova.getActivity(), "commonResourcesVersion");
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("version", i);
        callbackContext.success(jSONObject);
    }

    private void k(CallbackContext callbackContext) {
        JSONObject jSONObject = new JSONObject();
        String i = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.j);
        if (i == null) {
            i = Bugly.SDK_IS_DEV;
        }
        try {
            jSONObject.put("isDebug", i);
        } catch (JSONException e2) {
            Log.e(f11253a, e2.getMessage());
        }
        callbackContext.success(jSONObject);
    }

    private JSONObject l(JSONArray jSONArray) throws JSONException {
        if (jSONArray == null || jSONArray.length() == 0) {
            return null;
        }
        JSONObject jSONObject = new JSONObject();
        String[] split = jSONArray.getString(0).split(Constants.ACCEPT_TIME_SEPARATOR_SP);
        for (int i = 0; i < split.length; i++) {
            jSONObject.put(split[i], com.yyt.common.o.s.i(this.cordova.getActivity(), split[i].trim()));
        }
        return jSONObject;
    }

    @Deprecated
    private void m(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException {
        String i = com.yyt.common.o.s.i(this.cordova.getActivity(), "loginResourcesVersion");
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("version", i);
        callbackContext.success(jSONObject);
    }

    private JSONObject n() throws JSONException {
        Point point = new Point();
        ((WindowManager) this.cordova.getActivity().getSystemService("window")).getDefaultDisplay().getSize(point);
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("height", point.y);
        jSONObject.put("width", point.x);
        return jSONObject;
    }

    private String q(String str) {
        Intent intent;
        try {
            if (str.indexOf("market://") > -1) {
                intent = new Intent("android.intent.action.VIEW", Uri.parse(str));
            } else {
                intent = new Intent("android.intent.action.VIEW", Uri.parse(new URL(str).toExternalForm()));
            }
            this.cordova.getActivity().startActivity(intent);
            return PluginResult.Status.OK.name();
        } catch (ActivityNotFoundException unused) {
            if (str.indexOf("market://") > -1) {
                this.cordova.getActivity().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str.replace("market://", "https://market.android.com/"))));
                return PluginResult.Status.OK.name();
            }
            com.yyt.common.plugin.logger.c.b(f11253a, "WL.App.openURL failed to open web page with URL " + str + ", because of incorrect URL format.");
            return "result:error";
        } catch (MalformedURLException unused2) {
            com.yyt.common.plugin.logger.c.b(f11253a, "WL.App.openURL failed to open web page with URL " + str + ", because of incorrect URL format.");
            return "result:error";
        }
    }

    private void r(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException {
        com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.G, jSONArray.getJSONObject(0).toString());
        callbackContext.success();
    }

    @Override
    public boolean execute(String str, JSONArray jSONArray, CallbackContext callbackContext) throws JSONException {
        final Activity activity = this.cordova.getActivity();
        if (str.equals("getServerUrl")) {
            JSONObject jSONObject = new JSONObject();
            Object c2 = com.yyt.common.o.n.c(this.cordova.getActivity(), com.yyt.common.d.f10957e, "");
            Object i = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.h);
            if (i == null || "".equals(i)) {
                i = com.yyt.common.o.n.c(this.cordova.getActivity(), com.yyt.common.d.f10956d, "");
            }
            String i2 = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.f10953a);
            if ((i2 == null || "".equals(i2)) && (i2 = com.yyt.common.o.n.c(this.cordova.getActivity(), com.yyt.common.d.f10955c, "")) != null && !"".equals(i2)) {
                try {
                    URL url = new URL(i2);
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put("innerUrl", "");
                    jSONObject2.put("innerPort", "");
                    jSONObject2.put("outerUrl", url.getPort() == -1 ? i2 : url.getProtocol() + "://" + url.getHost());
                    jSONObject2.put("outerPort", url.getPort() == -1 ? "80" : "" + url.getPort());
                    jSONObject2.put("context", i);
                    com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.i, jSONObject2.toString());
                } catch (Exception unused) {
                }
            }
            if (i2 != null && !"".equals(i2)) {
                jSONObject.put("serverURL", i2);
                String i3 = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.f10954b);
                if (i3 != null && !"".equals(i3)) {
                    i2 = i3;
                }
                jSONObject.put("serverBackupURL", i2);
                jSONObject.put("context", i);
                jSONObject.put("resourcesManifestUrl", c2);
                callbackContext.success(jSONObject);
                return true;
            }
            callbackContext.error("未获取到服务器地址.");
            return true;
        }
        if (str.equals("getServerSetting")) {
            String i4 = com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.i);
            if (i4 != null && !"".equals(i4)) {
                callbackContext.success(new JSONObject(i4));
                return true;
            }
            callbackContext.success();
            return true;
        }
        if (str.equals("saveServerSetting")) {
            com.yyt.common.o.s.i(this.cordova.getActivity(), com.yyt.common.d.f10953a);
            JSONObject jSONObject3 = jSONArray.getJSONObject(0);
            String string = jSONObject3.getString("outerUrl");
            String string2 = jSONObject3.getString("outerPort");
            String string3 = jSONObject3.getString("innerUrl");
            String string4 = jSONObject3.getString("innerPort");
            String string5 = jSONObject3.getString("context");
            JSONObject jSONObject4 = jSONObject3.getJSONObject("extend");
            String str2 = (com.yyt.common.o.r.p(string) || com.yyt.common.o.r.p(string2)) ? "" : string + Constants.COLON_SEPARATOR + string2;
            String str3 = (com.yyt.common.o.r.p(string3) || com.yyt.common.o.r.p(string4)) ? "" : string3 + Constants.COLON_SEPARATOR + string4;
            if (d(str2 + MqttTopic.TOPIC_LEVEL_SEPARATOR + string5, BuglyStrategy.a.MAX_USERDATA_VALUE_LENGTH).booleanValue()) {
                com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.i, jSONObject3.toString());
                com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.f10953a, str2);
                if (!com.yyt.common.o.r.p(str3)) {
                    com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.f10954b, str3);
                }
                com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.h, string5);
                if (jSONObject4 != null) {
                    com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.G, jSONObject4.toString());
                }
                new File(this.cordova.getActivity().getApplicationContext().getFilesDir(), "Documents/LaunchImage/splash.png").delete();
            } else {
                if (d(str3 + MqttTopic.TOPIC_LEVEL_SEPARATOR + string5, BuglyStrategy.a.MAX_USERDATA_VALUE_LENGTH).booleanValue()) {
                    com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.i, jSONObject3.toString());
                    com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.f10953a, str3);
                    if (!com.yyt.common.o.r.p(str2)) {
                        com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.f10954b, str2);
                    }
                    com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.h, string5);
                    if (jSONObject4 != null) {
                        com.yyt.common.o.s.m(this.cordova.getActivity(), com.yyt.common.d.G, jSONObject4.toString());
                    }
                    new File(this.cordova.getActivity().getApplicationContext().getFilesDir(), "Documents/LaunchImage/splash.png").delete();
                } else {
                    callbackContext.error("配置地址不可用.");
                    return true;
                }
            }
            callbackContext.success();
            return true;
        }
        if (str.equals("getWidgetInfo")) {
            String i5 = com.yyt.common.o.s.i(this.cordova.getActivity(), jSONArray.getString(0) + "_" + jSONArray.getInt(1));
            if (i5 != null && !"".equals(i5)) {
                JSONObject jSONObject5 = new JSONObject(i5);
                String str4 = this.cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath() + "/widgets/" + jSONObject5.getString("pk_appregister");
                if (new File(str4).exists()) {
                    String str5 = str4 + "/v" + jSONObject5.getString("vapp_version") + MqttTopic.TOPIC_LEVEL_SEPARATOR;
                    com.yyt.common.o.s.m(this.cordova.getActivity(), jSONObject5.getString("vapp_indexurl").replace("file://", "").replace(str5, "").split(MqttTopic.TOPIC_LEVEL_SEPARATOR)[0], str5);
                    jSONObject5.put("android_max_version", com.yyt.common.o.n.f(this.cordova.getActivity()).versionCode);
                    callbackContext.success(jSONObject5);
                    return true;
                }
            }
            JSONObject jSONObject6 = new JSONObject();
            jSONObject6.put("android_max_version", com.yyt.common.o.n.f(this.cordova.getActivity()).versionCode);
            callbackContext.success(jSONObject6);
            return true;
        }
        if (str.equals("writePref")) {
            com.yyt.common.o.s.m(this.cordova.getActivity(), jSONArray.getString(0), jSONArray.getString(1));
            return a(PluginResult.Status.OK.name(), callbackContext);
        }
        if (str.equals("readPref")) {
            callbackContext.success(com.yyt.common.o.s.i(this.cordova.getActivity(), jSONArray.getString(0)));
            return true;
        }
        if (str.equals("getScreenSize")) {
            callbackContext.success(n());
            return true;
        }
        if (str.equals("openURL")) {
            return a(q(jSONArray.getString(0)), callbackContext);
        }
        if (str.equals("getInitParameters")) {
            callbackContext.success(l(jSONArray));
            return true;
        }
        if (str.equals("getAppSetting")) {
            callbackContext.success(i(jSONArray));
            return true;
        }
        if (str.equals("exitApp")) {
            return a(h(), callbackContext);
        }
        if (str.equals("getSDKVersion")) {
            return a(Integer.toString(Build.VERSION.SDK_INT), callbackContext);
        }
        if (str.equals("changeBackUpUrlAndUrl")) {
            b();
            return a(PluginResult.Status.OK.name(), callbackContext);
        }
        if (str.equals("getDebugMode")) {
            k(callbackContext);
            return true;
        }
        if (str.equals("changeDebugMode")) {
            c(callbackContext);
            return true;
        }
        if (str.equals("getNetworkInfo")) {
            callbackContext.success(com.yyt.common.o.s.e(this.cordova.getActivity()));
            return true;
        }
        if (str.equals("getDeviceUUID")) {
            return a(com.yyt.common.o.s.d(this.cordova.getActivity()), callbackContext);
        }
        if (str.equals("clearWebViewCache")) {
            this.webView.clearCache();
            callbackContext.success();
            return true;
        }
        if (str.equals("setBrightness")) {
            final float parseFloat = Float.parseFloat(jSONArray.getString(0)) * 255.0f;
            activity.runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    com.yyt.common.o.s.k(activity, parseFloat);
                }
            });
            callbackContext.success();
            return true;
        }
        if (str.equals("resetBrightness")) {
            final float parseFloat2 = Float.parseFloat(com.yyt.common.o.s.i(this.cordova.getActivity(), "brightness"));
            activity.runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    com.yyt.common.o.s.k(activity, parseFloat2);
                }
            });
            callbackContext.success();
            return true;
        }
        if (str.equals("convertLongUrlToShortUr")) {
            this.cordova.getThreadPool().execute(new a(this.preferences.getString("weibo_app_id", "").substring(2), jSONArray.getString(0), callbackContext));
            return true;
        }
        if ("updateServerExtend".equals(str)) {
            try {
                r(jSONArray, callbackContext);
                return true;
            } catch (Exception e2) {
                Log.e(f11253a, e2.getMessage(), e2);
                return true;
            }
        }
        if ("getCommonResVersion".equals(str)) {
            j(jSONArray, callbackContext);
            return true;
        }
        if ("getLoginResVersion".equals(str)) {
            m(jSONArray, callbackContext);
            return true;
        }
        if ("clearCommonResources".equals(str)) {
            try {
                e(jSONArray, callbackContext);
                return true;
            } catch (Exception e3) {
                Log.e(f11253a, e3.getMessage(), e3);
                return true;
            }
        }
        if ("clearLoginResources".equals(str)) {
            try {
                f(jSONArray, callbackContext);
                return true;
            } catch (Exception e4) {
                Log.e(f11253a, e4.getMessage(), e4);
                return true;
            }
        }
        if ("data2Hex".equals(str)) {
            try {
                g(jSONArray, callbackContext);
                return true;
            } catch (Exception e5) {
                Log.e(f11253a, e5.getMessage(), e5);
                return true;
            }
        }
        if ("openSystemPermissionSetting".equals(str)) {
            Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
            intent.setData(Uri.fromParts("package", this.cordova.getActivity().getPackageName(), null));
            try {
                this.cordova.getActivity().startActivity(intent);
                return true;
            } catch (Exception e6) {
                com.yyt.common.plugin.logger.c.a(f11253a, e6.getMessage(), e6);
                return true;
            }
        }
        if ("getAppPermissionInfo".equals(str)) {
            try {
                JSONArray jSONArray2 = new JSONArray();
                PackageInfo f2 = com.yyt.common.o.n.f(this.cordova.getActivity());
                PackageManager packageManager = this.cordova.getActivity().getPackageManager();
                String[] strArr = packageManager.getPackageInfo(f2.packageName, 4096).requestedPermissions;
                if (strArr != null) {
                    for (String str6 : strArr) {
                        try {
                            PermissionInfo permissionInfo = packageManager.getPermissionInfo(str6, 0);
                            if ((permissionInfo.protectionLevel & 15) == 1) {
                                boolean z = packageManager.checkPermission(str6, f2.packageName) == 0;
                                JSONObject jSONObject7 = new JSONObject();
                                jSONObject7.put(c.a.f.b.c.f152e, permissionInfo.name);
                                jSONObject7.put("isHasPermission", z);
                                jSONArray2.put(jSONObject7);
                            }
                        } catch (Exception unused2) {
                        }
                    }
                }
                callbackContext.success(jSONArray2);
                return true;
            } catch (Exception e7) {
                Log.e(f11253a, e7.getMessage(), e7);
                return true;
            }
        }
        if (!"openSettingFontSize".equals(str)) {
            return true;
        }
        this.cordova.getActivity().startActivity(new Intent(this.cordova.getActivity(), (Class<?>) SetFontSizeActivity.class));
        callbackContext.success();
        return true;
    }
}