use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.
the class BundlePackageManager method queryIntentActivities.
public static List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
List<Bundle> bundles = Atlas.getInstance().getBundles();
for (Bundle bundle : bundles) {
BundleImpl impl = (BundleImpl) bundle;
if (impl.isUpdated() && impl.getPackageManager() != null) {
ResolveInfo info = impl.getPackageManager().wrapperActivityIntentIfNeed(intent);
if (info != null) {
List<ResolveInfo> rf = new ArrayList<ResolveInfo>(1);
rf.add(info);
return rf;
}
}
}
return null;
}
use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.
the class BundleLifecycleHandler method loaded.
private void loaded(Bundle bundle) {
long time = System.currentTimeMillis();
BundleImpl b = (BundleImpl) bundle;
try {
// DelegateResources.newDelegateResources(RuntimeVariables.androidApplication,
// RuntimeVariables.delegateResources, b.getArchive().getArchiveFile().getAbsolutePath());
DelegateResources.addBundleResources(b.getArchive().getArchiveFile().getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
// if (DelegateComponent.getPackage(bundle.getLocation()) == null) {
// PackageLite pkg = parseByBundleInfoList(bundle.getLocation());
// if (pkg == null){
// AtlasMonitor.getInstance().trace(AtlasMonitor.BUNDLE_INSTALL_FAIL, bundle.getLocation(),
// AtlasMonitor.PACKAGE_LITE_NULL_FROM_BUNDLEINFOLIST, FileUtils.getDataAvailableSpace());
// File archiveFile = b.getArchive().getArchiveFile();
// pkg = PackageLite.parse(archiveFile);
// }
// if (pkg!=null){
// log.info("Bundle installation info " + bundle.getLocation() + ":" + pkg.components);
// DelegateComponent.putPackage(bundle.getLocation(), pkg);
// } else {
// AtlasMonitor.getInstance().trace(AtlasMonitor.BUNDLE_INSTALL_FAIL, bundle.getLocation(),
// AtlasMonitor.PACKAGE_LITE_NULL_FROM_SYSTEM_METHOD, FileUtils.getDataAvailableSpace());
// log.error( "" + bundle.getLocation() + "packageLite null even after get from packageLite method");
// }
// }
//
// final long timediff = System.currentTimeMillis() - time;
// log.info("loaded()" + bundle.getLocation() + " spend " + timediff + " milliseconds");
}
use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.
the class BundleLifecycleHandler method started.
private void started(Bundle bundle) {
BundleImpl b = (BundleImpl) bundle;
if (b.getClassLoader() == null || !((BundleClassLoader) b.getClassLoader()).validateClasses()) {
return;
}
long time = System.currentTimeMillis();
// load application from AndroidManifest.xml
// PackageLite packageLite = DelegateComponent.getPackage(b.getLocation());
BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(b.getLocation());
if (info != null) {
String appClassName = info.getApplicationName();
if (StringUtils.isNotEmpty(appClassName)) {
try {
Log.e("BundleLifeCycle", "start " + appClassName);
Application app = newApplication(appClassName, b.getClassLoader());
app.onCreate();
Log.e("BundleLifeCycle", "start finish" + appClassName);
((BundleImpl) bundle).setActive();
} catch (ApplicationInitException e) {
if (b.getArchive() != null && b.getArchive().isDexOpted()) {
throw new RuntimeException(e);
}
AtlasMonitor.getInstance().trace(AtlasMonitor.BUNDLE_APPLICATION_FAIL, bundle.getLocation(), e.getMessage(), FileUtils.getAvailableDisk());
Log.e("BundleLifeCycle", "started application crash | " + (Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId()));
}
} else {
((BundleImpl) bundle).setActive();
Log.e("BundleLifeCycle", "started with no application");
}
}
}
use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.
the class FrameworkLifecycleHandler method started.
private void started() {
RuntimeVariables.androidApplication.registerActivityLifecycleCallbacks(new ActivityLifeCycleObserver());
RuntimeVariables.androidApplication.registerComponentCallbacks(new ComponentCallbacks() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (RuntimeVariables.delegateResources != null) {
RuntimeVariables.delegateResources.updateConfiguration(newConfig, RuntimeVariables.delegateResources.getDisplayMetrics());
}
}
@Override
public void onLowMemory() {
}
});
if (RuntimeVariables.getProcessName(RuntimeVariables.androidApplication).equals(RuntimeVariables.androidApplication.getPackageName())) {
String autoStartBundle = (String) RuntimeVariables.getFrameworkProperty("autoStartBundles");
if (autoStartBundle != null) {
String[] bundles = autoStartBundle.split(",");
if (bundles.length > 0) {
for (int x = 0; x < bundles.length; x++) {
final String bundleName = bundles[0];
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
if (impl == null) {
BundleInstaller.startDelayInstall(bundleName, new BundleInstaller.InstallListener() {
@Override
public void onFinished() {
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
if (impl != null) {
try {
impl.start();
} catch (BundleException e) {
e.printStackTrace();
}
}
}
});
} else {
try {
impl.start();
} catch (BundleException e) {
e.printStackTrace();
}
}
}
}
}
}
}
use of android.taobao.atlas.framework.BundleImpl in project atlas by alibaba.
the class InstrumentationHook method callActivityOnCreate.
@Override
public void callActivityOnCreate(Activity activity, Bundle icicle) {
if (!RuntimeVariables.androidApplication.getPackageName().equals(activity.getPackageName())) {
mBase.callActivityOnCreate(activity, icicle);
return;
}
ContextImplHook hook = new ContextImplHook(activity.getBaseContext(), activity.getClass().getClassLoader());
if (activity.getBaseContext().getResources() != RuntimeVariables.delegateResources) {
if (Build.VERSION.SDK_INT < 21) {
try {
AtlasHacks.ContextImpl_mResources.set(activity.getBaseContext(), RuntimeVariables.delegateResources);
} catch (Throwable e) {
}
}
}
if (AtlasHacks.ContextThemeWrapper_mBase != null && AtlasHacks.ContextThemeWrapper_mBase.getField() != null) {
//AtlasHacks.ContextThemeWrapper_mBase.on(activity).set(hook);
AtlasHacks.ContextThemeWrapper_mBase.set(activity, hook);
}
AtlasHacks.ContextWrapper_mBase.set(activity, hook);
String Location = null;
if (activity.getClass().getClassLoader() instanceof BundleClassLoader) {
BundleClassLoader bundleClassLoader = (BundleClassLoader) activity.getClass().getClassLoader();
BundleImpl bundle = bundleClassLoader.getBundle();
bundle.startBundle();
} else if ((Location = AtlasBundleInfoManager.instance().getBundleForComponet(activity.getClass().getName())) != null) {
//yunos, get the bundle from bundleInfoList and Frameworks
BundleImpl bundle = (BundleImpl) Framework.getBundle(Location);
if (bundle != null)
bundle.startBundle();
}
String welcomeClassName = Framework.getProperty("android.taobao.atlas.welcome", "com.taobao.tao.welcome.Welcome");
if (TextUtils.isEmpty(welcomeClassName)) {
welcomeClassName = "com.taobao.tao.welcome.Welcome";
}
if (activity.getIntent() != null) {
activity.getIntent().setExtrasClassLoader(RuntimeVariables.delegateClassLoader);
}
// ensureResourcesInjected(activity);
if (activity.getClass().getName().equals(welcomeClassName)) {
mBase.callActivityOnCreate(activity, null);
} else {
try {
if (isAppFirstStartAfterUpdated()) {
mBase.callActivityOnCreate(activity, null);
} else {
mBase.callActivityOnCreate(activity, icicle);
}
} catch (RuntimeException e) {
if ((e.toString().contains("android.content.res.Resources") || e.toString().contains("Error inflating class") || e.toString().contains("java.lang.ArrayIndexOutOfBoundsException")) && !e.toString().contains("OutOfMemoryError")) {
HandleResourceNotFound(activity, icicle, e);
} else {
throw e;
}
}
}
}
Aggregations