Search in sources :

Example 1 with AtlasPreLauncher

use of android.taobao.atlas.runtime.AtlasPreLauncher in project atlas by alibaba.

the class BridgeApplicationDelegate method attachBaseContext.

public void attachBaseContext() {
    AtlasHacks.defineAndVerify();
    RuntimeVariables.androidApplication = mRawApplication;
    RuntimeVariables.originalResources = mRawApplication.getResources();
    RuntimeVariables.sCurrentProcessName = mCurrentProcessname;
    RuntimeVariables.sInstalledVersionCode = mInstalledVersionCode;
    RuntimeVariables.sAppLastUpdateTime = mLastUpdateTime;
    RuntimeVariables.sApkPath = mApkPath;
    RuntimeVariables.delegateResources = mRawApplication.getResources();
    RuntimeVariables.sDexLoadBooster = mdexLoadBooster;
    Log.e("BridgeApplication", "length =" + new File(mRawApplication.getApplicationInfo().sourceDir).length());
    if (!TextUtils.isEmpty(mInstalledVersionName)) {
        RuntimeVariables.sInstalledVersionName = mInstalledVersionName;
    }
    System.out.print(SoLoader.class.getName());
    try {
        String preLaunchStr = (String) RuntimeVariables.getFrameworkProperty("preLaunch");
        if (!TextUtils.isEmpty(preLaunchStr)) {
            AtlasPreLauncher launcher = (AtlasPreLauncher) Class.forName(preLaunchStr).newInstance();
            if (launcher != null) {
                launcher.initBeforeAtlas(mRawApplication.getBaseContext());
            }
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    // *2 init atlas use reflect
    boolean multidexEnable = false;
    try {
        ApplicationInfo appInfo = mRawApplication.getPackageManager().getApplicationInfo(mRawApplication.getPackageName(), PackageManager.GET_META_DATA);
        mRealApplicationName = appInfo.metaData.getString("REAL_APPLICATION");
        multidexEnable = appInfo.metaData.getBoolean("multidex_enable");
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException(e);
    }
    if (multidexEnable) {
        MultiDex.install(mRawApplication);
    }
    mRealApplicationName = TextUtils.isEmpty(mRealApplicationName) ? "android.app.Application" : mRealApplicationName;
    if (mRealApplicationName.startsWith(".")) {
        mRealApplicationName = mRawApplication.getPackageName() + mRealApplicationName;
    }
    RuntimeVariables.sRealApplicationName = mRealApplicationName;
    try {
        Atlas.getInstance().init(mRawApplication, mIsUpdated);
    } catch (Throwable e) {
        File storageDir = new File(mRawApplication.getFilesDir(), "storage");
        Framework.deleteDirectory(storageDir);
        KernalVersionManager.instance().removeBaseLineInfo();
        android.os.Process.killProcess(Process.myPid());
    // throw new RuntimeException("atlas initialization fail--->" + e.getMessage());
    }
    // ////////////////////////////////////////launchTime////////////////////
    try {
        Class BuildConfig = Class.forName(mRawApplication.getPackageName() + ".BuildConfig");
        Field launchTimeField = BuildConfig.getDeclaredField("launchTime");
        launchTimeField.setAccessible(true);
        launchTimeField.set(BuildConfig, System.currentTimeMillis());
    } catch (Throwable e) {
    }
    // *3 remove providerinfo for so installcontentprovider is delayed
    try {
        Object activityThread = AndroidHack.getActivityThread();
        Object mBoundApplication = AtlasHacks.ActivityThread_mBoundApplication.get(activityThread);
        mBoundApplication_provider = AtlasHacks.ActivityThread$AppBindData_providers.get(mBoundApplication);
        if (mBoundApplication_provider != null && mBoundApplication_provider.size() > 0) {
            AtlasHacks.ActivityThread$AppBindData_providers.set(mBoundApplication, null);
        } else if (Build.VERSION.SDK_INT >= 24 && mCurrentProcessname != null && mCurrentProcessname.equals(mRawApplication.getPackageName())) {
            mBoundApplication_provider = new ArrayList<>();
            ProviderInfo providerInfo = mRawApplication.getPackageManager().resolveContentProvider(mRawApplication.getPackageName() + ".update.provider", 0);
            if (providerInfo != null) {
                providerInfo.exported = false;
                providerInfo.grantUriPermissions = true;
                mBoundApplication_provider.add(providerInfo);
            }
        }
    } catch (Exception e) {
        if (e instanceof InvocationTargetException) {
            throw new RuntimeException(((InvocationTargetException) e).getTargetException());
        } else {
            throw new RuntimeException(e);
        }
    }
}
Also used : SoLoader(android.taobao.atlas.util.SoLoader) AtlasPreLauncher(android.taobao.atlas.runtime.AtlasPreLauncher) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) PackageManager(android.content.pm.PackageManager) ProviderInfo(android.content.pm.ProviderInfo) DexFile(dalvik.system.DexFile) File(java.io.File)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 ProviderInfo (android.content.pm.ProviderInfo)1 AtlasPreLauncher (android.taobao.atlas.runtime.AtlasPreLauncher)1 SoLoader (android.taobao.atlas.util.SoLoader)1 DexFile (dalvik.system.DexFile)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1