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);
}
}
}
Aggregations