MCPcopy Create free account
hub / github.com/FeJQ/AUPK / attach

Method attach

frameworks/base/core/java/android/app/ActivityThread.java:5984–6074  ·  view source on GitHub ↗
(boolean system)

Source from the content-addressed store, hash-verified

5982 }
5983
5984 private void attach(boolean system) {
5985 sCurrentActivityThread = this;
5986 mSystemThread = system;
5987 if (!system) {
5988 ViewRootImpl.addFirstDrawHandler(new Runnable() {
5989 @Override
5990 public void run() {
5991 ensureJitEnabled();
5992 }
5993 });
5994 android.ddm.DdmHandleAppName.setAppName("<pre-initialized>",
5995 UserHandle.myUserId());
5996 RuntimeInit.setApplicationObject(mAppThread.asBinder());
5997 final IActivityManager mgr = ActivityManagerNative.getDefault();
5998 try {
5999 mgr.attachApplication(mAppThread);
6000 } catch (RemoteException ex) {
6001 throw ex.rethrowFromSystemServer();
6002 }
6003 // Watch for getting close to heap limit.
6004 BinderInternal.addGcWatcher(new Runnable() {
6005 @Override public void run() {
6006 if (!mSomeActivitiesChanged) {
6007 return;
6008 }
6009 Runtime runtime = Runtime.getRuntime();
6010 long dalvikMax = runtime.maxMemory();
6011 long dalvikUsed = runtime.totalMemory() - runtime.freeMemory();
6012 if (dalvikUsed > ((3*dalvikMax)/4)) {
6013 if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024)
6014 + " total=" + (runtime.totalMemory()/1024)
6015 + " used=" + (dalvikUsed/1024));
6016 mSomeActivitiesChanged = false;
6017 try {
6018 mgr.releaseSomeActivities(mAppThread);
6019 } catch (RemoteException e) {
6020 throw e.rethrowFromSystemServer();
6021 }
6022 }
6023 }
6024 });
6025 } else {
6026 // Don't set application object here -- if the system crashes,
6027 // we can't display an alert, we just want to die die die.
6028 android.ddm.DdmHandleAppName.setAppName("system_process",
6029 UserHandle.myUserId());
6030 try {
6031 mInstrumentation = new Instrumentation();
6032 ContextImpl context = ContextImpl.createAppContext(
6033 this, getSystemContext().mPackageInfo);
6034 mInitialApplication = context.mPackageInfo.makeApplication(true, null);
6035 mInitialApplication.onCreate();
6036 } catch (Exception e) {
6037 throw new RuntimeException(
6038 "Unable to instantiate Application():" + e.toString(), e);
6039 }
6040 }
6041

Callers 5

systemMainMethod · 0.95
mainMethod · 0.95
performLaunchActivityMethod · 0.80
handleCreateServiceMethod · 0.80

Calls 2

getSystemContextMethod · 0.95
toStringMethod · 0.45

Tested by

no test coverage detected