use of android.app.Application in project platform_frameworks_base by android.
the class WebViewFactory method getProviderClass.
private static Class<WebViewFactoryProvider> getProviderClass() {
Context webViewContext = null;
Application initialApplication = AppGlobals.getInitialApplication();
try {
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getWebViewContextAndSetProvider()");
try {
webViewContext = getWebViewContextAndSetProvider();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
Log.i(LOGTAG, "Loading " + sPackageInfo.packageName + " version " + sPackageInfo.versionName + " (code " + sPackageInfo.versionCode + ")");
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getChromiumProviderClass()");
try {
initialApplication.getAssets().addAssetPathAsSharedLibrary(webViewContext.getApplicationInfo().sourceDir);
ClassLoader clazzLoader = webViewContext.getClassLoader();
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
loadNativeLibrary(clazzLoader);
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
try {
return (Class<WebViewFactoryProvider>) Class.forName(CHROMIUM_WEBVIEW_FACTORY, true, clazzLoader);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (ClassNotFoundException e) {
Log.e(LOGTAG, "error loading provider", e);
throw new AndroidRuntimeException(e);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (MissingWebViewPackageException e) {
// original exception.
try {
return (Class<WebViewFactoryProvider>) Class.forName(NULL_WEBVIEW_FACTORY);
} catch (ClassNotFoundException e2) {
// Ignore.
}
Log.e(LOGTAG, "Chromium WebView package does not exist", e);
throw new AndroidRuntimeException(e);
}
}
use of android.app.Application in project freeline by alibaba.
the class MonkeyPatcher method monkeyPatchApplication.
// Lots of conversions with generic types
@SuppressWarnings("unchecked")
public static void monkeyPatchApplication(Context context, Application bootstrap, Application realApplication, String externalResourceFile) {
// Application class.
try {
// Find the ActivityThread instance for the current thread
Class<?> activityThread = Class.forName("android.app.ActivityThread");
Object currentActivityThread = getActivityThread(context, activityThread);
// Find the mInitialApplication field of the ActivityThread to the real application
Field mInitialApplication = activityThread.getDeclaredField("mInitialApplication");
mInitialApplication.setAccessible(true);
Application initialApplication = (Application) mInitialApplication.get(currentActivityThread);
if (realApplication != null && initialApplication == bootstrap) {
mInitialApplication.set(currentActivityThread, realApplication);
}
// real one
if (realApplication != null) {
Field mAllApplications = activityThread.getDeclaredField("mAllApplications");
mAllApplications.setAccessible(true);
List<Application> allApplications = (List<Application>) mAllApplications.get(currentActivityThread);
for (int i = 0; i < allApplications.size(); i++) {
if (allApplications.get(i) == bootstrap) {
allApplications.set(i, realApplication);
}
}
}
// Figure out how loaded APKs are stored.
// API version 8 has PackageInfo, 10 has LoadedApk. 9, I don't know.
Class<?> loadedApkClass;
try {
loadedApkClass = Class.forName("android.app.LoadedApk");
} catch (ClassNotFoundException e) {
loadedApkClass = Class.forName("android.app.ActivityThread$PackageInfo");
}
Field mApplication = loadedApkClass.getDeclaredField("mApplication");
mApplication.setAccessible(true);
Field mResDir = loadedApkClass.getDeclaredField("mResDir");
mResDir.setAccessible(true);
// 10 doesn't have this field, 14 does. Fortunately, there are not many Honeycomb devices
// floating around.
Field mLoadedApk = null;
try {
mLoadedApk = Application.class.getDeclaredField("mLoadedApk");
} catch (NoSuchFieldException e) {
// According to testing, it's okay to ignore this.
}
// - Set Application#mLoadedApk to the found LoadedApk instance
for (String fieldName : new String[] { "mPackages", "mResourcePackages" }) {
Field field = activityThread.getDeclaredField(fieldName);
field.setAccessible(true);
Object value = field.get(currentActivityThread);
for (Map.Entry<String, WeakReference<?>> entry : ((Map<String, WeakReference<?>>) value).entrySet()) {
Object loadedApk = entry.getValue().get();
if (loadedApk == null) {
continue;
}
if (mApplication.get(loadedApk) == bootstrap) {
if (realApplication != null) {
mApplication.set(loadedApk, realApplication);
}
if (externalResourceFile != null) {
mResDir.set(loadedApk, externalResourceFile);
}
if (realApplication != null && mLoadedApk != null) {
mLoadedApk.set(realApplication, loadedApk);
}
}
}
}
} catch (Throwable e) {
throw new IllegalStateException(e);
}
}
use of android.app.Application in project atlas by alibaba.
the class BundleLifecycleHandler method newApplication.
protected static Application newApplication(String applicationClassName, ClassLoader cl) throws ApplicationInitException {
try {
final Class<?> applicationClass = cl.loadClass(applicationClassName);
if (applicationClass == null) {
throw new ApplicationInitException(String.format("can not find class: %s", applicationClassName));
}
Application app = (Application) applicationClass.newInstance();
AtlasHacks.Application_attach.invoke(app, RuntimeVariables.androidApplication);
return app;
} catch (ClassNotFoundException e) {
throw new ApplicationInitException(e);
} catch (IllegalAccessException e2) {
throw new ApplicationInitException(e2);
} catch (InvocationTargetException e3) {
throw new ApplicationInitException(e3);
} catch (InstantiationException e4) {
throw new ApplicationInitException(e4);
}
}
use of android.app.Application 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.app.Application in project atlas by alibaba.
the class FrameworkLifecycleHandler method starting.
private void starting() {
if (RuntimeVariables.safeMode) {
return;
}
long time = System.currentTimeMillis();
android.os.Bundle metaData = null;
try {
ApplicationInfo applicationInfo = RuntimeVariables.androidApplication.getPackageManager().getApplicationInfo(RuntimeVariables.androidApplication.getPackageName(), PackageManager.GET_META_DATA);
metaData = applicationInfo.metaData;
} catch (NameNotFoundException e1) {
e1.printStackTrace();
}
if (metaData != null) {
String strApps = metaData.getString("application");
if (StringUtils.isNotEmpty(strApps)) {
String[] appClassNames = StringUtils.split(strApps, ",");
if (appClassNames == null || appClassNames.length == 0) {
appClassNames = new String[] { strApps };
}
for (String appClassName : appClassNames) {
try {
Application app = BundleLifecycleHandler.newApplication(appClassName, Framework.getSystemClassLoader());
app.onCreate();
// DelegateComponent.apkApplications.put("system:" + appClassName, app);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
final long timediff = System.currentTimeMillis() - time;
}
Aggregations