imToken v2.9.3版本的 MD5 值为:42af1a08a3f01f69d2f3782d81007b3c

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


package org.consenlabs.imtoken;

import android.app.Application;
import android.content.Context;
import android.database.CursorWindow;
import android.os.Build;
import android.webkit.WebView;
import androidx.multidex.MultiDex;
import cl.json.ShareApplication;
import cn.jiguang.plugins.push.JPushModule;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.modules.storage.ReactDatabaseSupplier;
import com.facebook.soloader.SoLoader;
import com.google.protobuf.Any;
import com.microsoft.codepush.react.CodePush;
import com.sensorsdata.analytics.android.sdk.SAConfigOptions;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import io.sentry.Sentry;
import io.sentry.SentryOptions;
import io.sentry.android.core.SentryAndroid;
import io.sentry.android.core.SentryAndroidOptions;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.consenlabs.imtoken.dappbrowser.DAppBrowserPackage;
import org.consenlabs.imtoken.httpcache.HttpCachePackage;
import org.consenlabs.imtoken.walletapi.HardWalletAPI;
import org.consenlabs.imtoken.walletapi.ImkeyApi;
import org.consenlabs.imtoken.walletapi.ImkeyCoreXJna;
import org.consenlabs.imtoken.walletapi.TcxApiStruct;
import org.consenlabs.imtoken.walletapi.TokenCoreXJna;
import org.consenlabs.imtoken.walletapi.Util;
import org.consenlabs.tokencore.foundation.utils.NumericUtil;
import org.consenlabs.tokencore.wallet.KeystoreStorage;
import org.consenlabs.tokencore.wallet.WalletManager;
import org.consenlabs.tokencore.wallet.keystore.HDMnemonicKeystore;

public class MainApplication extends Application implements ReactApplication, ShareApplication, KeystoreStorage {
    static final String SA_SERVER_URL_DEBUG = "https://imtoken.datasink.sensorsdata.cn/sa?project=default&token=27d69b3e7fd25949";
    static final String SA_SERVER_URL_RELEASE = "https://imtoken.datasink.sensorsdata/sa?project=production&token=27d69b3e7fd25949";
    private static MainApplication sInstance;
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected String getJSMainModuleName() {
            return "index";
        }

        @Override
        public boolean getUseDeveloperSupport() {
            return false;
        }

        @Override
        public String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

        @Override
        protected List<ReactPackage> getPackages() {
            ArrayList<ReactPackage> packages = new PackageList(this).getPackages();
            packages.add(new TokenPackage());
            packages.add(new DAppBrowserPackage());
            packages.add(new HttpCachePackage());
            return packages;
        }
    };

    private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
    }

    @Override
    public String getFileProviderAuthority() {
        return "fim.ftoken.fapp.provider";
    }

    static {
        System.loadLibrary("connector");
    }

    public static MainApplication getsInstance() {
        return sInstance;
    }

    @Override
    public ReactNativeHost getReactNativeHost() {
        return this.mReactNativeHost;
    }

    static File getDefaultKeyDirectory() {
        File file = new File(getsInstance().getKeystoreDir(), "wallets");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
        SentryAndroid.init(getApplicationContext(), new Sentry.OptionsConfiguration() {
            @Override
            public final void configure(SentryOptions sentryOptions) {
                ((SentryAndroidOptions) sentryOptions).setDsn("https://e7adfaae647e4438813db82e877ecbd7@o55920.ingest.sentry.io/621773");
            }
        });
        initSensorsDataSDK();
        HDMnemonicKeystore.XPubCommonKey128 = "4A2B655485ABBAB54BD30298BB0A5B55";
        HDMnemonicKeystore.XPubCommonIv = "73518399CB98DCD114D873E06EBF4BCC";
        Util.XPubCommonKey128 = "4A2B655485ABBAB54BD30298BB0A5B55";
        Util.XPubCommonIv = "73518399CB98DCD114D873E06EBF4BCC";
        WalletManager.storage = this;
        WalletManager.scanWallets();
        TokenCoreXJna.INSTANCE.call_tcx_api(NumericUtil.bytesToHex(TcxApiStruct.TcxAction.newBuilder().setMethod("init_token_core_x").setParam(Any.newBuilder().setTypeUrl("imtoken.init_token_core_x").setValue(TcxApiStruct.InitTokenCoreXParam.newBuilder().setFileDir(getDefaultKeyDirectory().getAbsolutePath()).setXpubCommonKey(HDMnemonicKeystore.XPubCommonKey128).setXpubCommonIv(HDMnemonicKeystore.XPubCommonIv).setIsDebug(false).build().toByteString()).build()).build().toByteArray()));
        ImkeyCoreXJna.INSTANCE.call_imkey_api(NumericUtil.bytesToHex(ImkeyApi.ImkeyAction.newBuilder().setMethod("init_imkey_core_x").setParam(Any.newBuilder().setTypeUrl("imtoken.init_imkey_core_x").setValue(ImkeyApi.InitImKeyCoreXParam.newBuilder().setFileDir(getFilesDir().getAbsolutePath()).setXpubCommonKey(HDMnemonicKeystore.XPubCommonKey128).setXpubCommonIv(HDMnemonicKeystore.XPubCommonIv).setIsDebug(false).setSystem("Android").build().toByteString()).build()).build().toByteArray()));
        SoLoader.init((Context) this, false);
        initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
        setCursorWindowSize();
        JPushModule.registerActivityLifecycle(this);
        if (Build.VERSION.SDK_INT < 19 || (getApplicationInfo().flags & 2) == 0) {
            return;
        }
        WebView.setWebContentsDebuggingEnabled(true);
    }

    private void setCursorWindowSize() {
        try {
            Field declaredField = CursorWindow.class.getDeclaredField("sCursorWindowSize");
            declaredField.setAccessible(true);
            declaredField.set(null, 10485760);
        } catch (Exception unused) {
        }
        try {
            ReactDatabaseSupplier.getInstance(getApplicationContext()).setMaximumSize(20971520L);
        } catch (Exception unused2) {
        }
    }

    @Override
    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        if (Build.VERSION.SDK_INT < 21) {
            MultiDex.install(this);
        }
    }

    @Override
    public File getKeystoreDir() {
        return getFilesDir();
    }

    @Override
    public void onTerminate() {
        HardWalletAPI.getInstance().disconnectAllDevices();
        super.onTerminate();
    }

    private void initSensorsDataSDK() {
        try {
            SAConfigOptions sAConfigOptions = new SAConfigOptions("https://imtoken.datasink.sensorsdata.cn/sa?project=production&token=27d69b3e7fd25949");
            sAConfigOptions.enableLog(isDebugMode(this)).setAutoTrackEventType(3).enableTrackAppCrash();
            SensorsDataAPI.startWithConfigOptions(this, sAConfigOptions);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean isDebugMode(Context context) {
        try {
            return (context.getApplicationInfo().flags & 2) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}