val pm = context.applicationContext.packageManager val installedApplications = pm.getInstalledApplications(0) installedApplications.forEach {info -> //handle info }
privatevoidattach(boolean system, long startSeq) { sCurrentActivityThread = this; mConfigurationController = newConfigurationController(this); mSystemThread = system; if (!system) { android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", UserHandle.myUserId()); RuntimeInit.setApplicationObject(mAppThread.asBinder()); finalIActivityManagermgr= ActivityManager.getService(); try { mgr.attachApplication(mAppThread, startSeq); // } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } // Watch for getting close to heap limit. BinderInternal.addGcWatcher(newRunnable() { @Overridepublicvoidrun() { if (!mSomeActivitiesChanged) { return; } Runtimeruntime= Runtime.getRuntime(); longdalvikMax= runtime.maxMemory(); longdalvikUsed= runtime.totalMemory() - runtime.freeMemory(); if (dalvikUsed > ((3*dalvikMax)/4)) { if (DEBUG_MEMORY_TRIM) Slog.d(TAG, "Dalvik max=" + (dalvikMax/1024) + " total=" + (runtime.totalMemory()/1024) + " used=" + (dalvikUsed/1024)); mSomeActivitiesChanged = false; try { ActivityTaskManager.getService().releaseSomeActivities(mAppThread); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } }); } else { // Don't set application object here -- if the system crashes, // we can't display an alert, we just want to die die die. android.ddm.DdmHandleAppName.setAppName("system_process", UserHandle.myUserId()); try { mInstrumentation = newInstrumentation(); mInstrumentation.basicInit(this); ContextImplcontext= ContextImpl.createAppContext( this, getSystemContext().mPackageInfo); mInitialApplication = context.mPackageInfo.makeApplication(true, null); mInitialApplication.onCreate(); } catch (Exception e) { thrownewRuntimeException( "Unable to instantiate Application():" + e.toString(), e); } }
ViewRootImpl.ConfigChangedCallbackconfigChangedCallback= (Configuration globalConfig) -> { synchronized (mResourcesManager) { // TODO (b/135719017): Temporary log for debugging IME service. if (Build.IS_DEBUGGABLE && mHasImeComponent) { Log.d(TAG, "ViewRootImpl.ConfigChangedCallback for IME, " + "config=" + globalConfig); }
// We need to apply this change to the resources immediately, because upon returning // the view hierarchy will be informed about it. if (mResourcesManager.applyConfigurationToResources(globalConfig, null/* compat */, mInitialApplication.getResources().getDisplayAdjustments())) { mConfigurationController.updateLocaleListFromAppContext( mInitialApplication.getApplicationContext());
// This actually changed the resources! Tell everyone about it. finalConfigurationupdatedConfig= mConfigurationController.updatePendingConfiguration(globalConfig); if (updatedConfig != null) { sendMessage(H.CONFIGURATION_CHANGED, globalConfig); mPendingConfiguration = updatedConfig; } } } }; ViewRootImpl.addConfigCallback(configChangedCallback); }