diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-06-24 15:07:24 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-06-24 15:20:48 -0700 |
commit | 01e4cfc47d0a2c7e7ab383d2fb23224ec52c0301 (patch) | |
tree | 1ea8a7e26b691d9d2150e9ddbd19b04be9b8d5d3 | |
parent | 7b5b27ada12d3680dec20274fa655fd7f73f839e (diff) | |
download | frameworks_base-01e4cfc47d0a2c7e7ab383d2fb23224ec52c0301.zip frameworks_base-01e4cfc47d0a2c7e7ab383d2fb23224ec52c0301.tar.gz frameworks_base-01e4cfc47d0a2c7e7ab383d2fb23224ec52c0301.tar.bz2 |
Some ActivityThread/ActivityManager cleanup.
- Move PackageInfo out of ActivityThread, renaming to LoadedApk.
- Rename some of the other PacakgeInfo inner classes to better
represent what they are.
- Rename HistoryRecord to ActivityRecord.
- Introduce AppGlobals, to eventually let ActivityThread become
package scoped.
Change-Id: Ib714c54ceb3cdbb525dce3db9505f31042e88cf0
16 files changed, 1672 insertions, 1570 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 0ce790e..6599096 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.IContentProvider; import android.content.Intent; import android.content.IIntentReceiver; -import android.content.ServiceConnection; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; @@ -74,7 +73,6 @@ import android.view.WindowManagerImpl; import com.android.internal.os.BinderInternal; import com.android.internal.os.RuntimeInit; import com.android.internal.os.SamplingProfilerIntegration; -import com.android.internal.util.ArrayUtils; import org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl; @@ -82,12 +80,9 @@ import java.io.File; import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.PrintWriter; import java.lang.ref.WeakReference; -import java.net.URL; import java.util.ArrayList; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -98,18 +93,6 @@ import java.util.regex.Pattern; import dalvik.system.SamplingProfiler; -final class IntentReceiverLeaked extends AndroidRuntimeException { - public IntentReceiverLeaked(String msg) { - super(msg); - } -} - -final class ServiceConnectionLeaked extends AndroidRuntimeException { - public ServiceConnectionLeaked(String msg) { - super(msg); - } -} - final class SuperNotCalledException extends AndroidRuntimeException { public SuperNotCalledException(String msg) { super(msg); @@ -125,10 +108,10 @@ final class SuperNotCalledException extends AndroidRuntimeException { * {@hide} */ public final class ActivityThread { - private static final String TAG = "ActivityThread"; + static final String TAG = "ActivityThread"; private static final boolean DEBUG = false; - private static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV; - private static final boolean DEBUG_BROADCAST = false; + static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV; + static final boolean DEBUG_BROADCAST = false; private static final boolean DEBUG_RESULTS = false; private static final boolean DEBUG_BACKUP = false; private static final boolean DEBUG_CONFIGURATION = false; @@ -138,1162 +121,65 @@ public final class ActivityThread { private static final int LOG_ON_PAUSE_CALLED = 30021; private static final int LOG_ON_RESUME_CALLED = 30022; + static ContextImpl mSystemContext = null; - public static final ActivityThread currentActivityThread() { - return (ActivityThread)sThreadLocal.get(); - } - - public static final String currentPackageName() - { - ActivityThread am = currentActivityThread(); - return (am != null && am.mBoundApplication != null) - ? am.mBoundApplication.processName : null; - } - - public static IPackageManager getPackageManager() { - if (sPackageManager != null) { - //Slog.v("PackageManager", "returning cur default = " + sPackageManager); - return sPackageManager; - } - IBinder b = ServiceManager.getService("package"); - //Slog.v("PackageManager", "default service binder = " + b); - sPackageManager = IPackageManager.Stub.asInterface(b); - //Slog.v("PackageManager", "default service = " + sPackageManager); - return sPackageManager; - } - - DisplayMetrics getDisplayMetricsLocked(boolean forceUpdate) { - if (mDisplayMetrics != null && !forceUpdate) { - return mDisplayMetrics; - } - if (mDisplay == null) { - WindowManager wm = WindowManagerImpl.getDefault(); - mDisplay = wm.getDefaultDisplay(); - } - DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics(); - mDisplay.getMetrics(metrics); - //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h=" - // + metrics.heightPixels + " den=" + metrics.density - // + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi); - return metrics; - } - - /** - * Creates the top level Resources for applications with the given compatibility info. - * - * @param resDir the resource directory. - * @param compInfo the compability info. It will use the default compatibility info when it's - * null. - */ - Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) { - ResourcesKey key = new ResourcesKey(resDir, compInfo.applicationScale); - Resources r; - synchronized (mPackages) { - // Resources is app scale dependent. - if (false) { - Slog.w(TAG, "getTopLevelResources: " + resDir + " / " - + compInfo.applicationScale); - } - WeakReference<Resources> wr = mActiveResources.get(key); - r = wr != null ? wr.get() : null; - //if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate()); - if (r != null && r.getAssets().isUpToDate()) { - if (false) { - Slog.w(TAG, "Returning cached resources " + r + " " + resDir - + ": appScale=" + r.getCompatibilityInfo().applicationScale); - } - return r; - } - } - - //if (r != null) { - // Slog.w(TAG, "Throwing away out-of-date resources!!!! " - // + r + " " + resDir); - //} - - AssetManager assets = new AssetManager(); - if (assets.addAssetPath(resDir) == 0) { - return null; - } - - //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics); - DisplayMetrics metrics = getDisplayMetricsLocked(false); - r = new Resources(assets, metrics, getConfiguration(), compInfo); - if (false) { - Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " - + r.getConfiguration() + " appScale=" - + r.getCompatibilityInfo().applicationScale); - } - - synchronized (mPackages) { - WeakReference<Resources> wr = mActiveResources.get(key); - Resources existing = wr != null ? wr.get() : null; - if (existing != null && existing.getAssets().isUpToDate()) { - // Someone else already created the resources while we were - // unlocked; go ahead and use theirs. - r.getAssets().close(); - return existing; - } - - // XXX need to remove entries when weak references go away - mActiveResources.put(key, new WeakReference<Resources>(r)); - return r; - } - } - - /** - * Creates the top level resources for the given package. - */ - Resources getTopLevelResources(String resDir, PackageInfo pkgInfo) { - return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo); - } - - final Handler getHandler() { - return mH; - } - - public final static class PackageInfo { - - private final ActivityThread mActivityThread; - private final ApplicationInfo mApplicationInfo; - private final String mPackageName; - private final String mAppDir; - private final String mResDir; - private final String[] mSharedLibraries; - private final String mDataDir; - private final File mDataDirFile; - private final ClassLoader mBaseClassLoader; - private final boolean mSecurityViolation; - private final boolean mIncludeCode; - private Resources mResources; - private ClassLoader mClassLoader; - private Application mApplication; - private CompatibilityInfo mCompatibilityInfo; - - private final HashMap<Context, HashMap<BroadcastReceiver, ReceiverDispatcher>> mReceivers - = new HashMap<Context, HashMap<BroadcastReceiver, ReceiverDispatcher>>(); - private final HashMap<Context, HashMap<BroadcastReceiver, ReceiverDispatcher>> mUnregisteredReceivers - = new HashMap<Context, HashMap<BroadcastReceiver, ReceiverDispatcher>>(); - private final HashMap<Context, HashMap<ServiceConnection, ServiceDispatcher>> mServices - = new HashMap<Context, HashMap<ServiceConnection, ServiceDispatcher>>(); - private final HashMap<Context, HashMap<ServiceConnection, ServiceDispatcher>> mUnboundServices - = new HashMap<Context, HashMap<ServiceConnection, ServiceDispatcher>>(); - - int mClientCount = 0; - - Application getApplication() { - return mApplication; - } - - public PackageInfo(ActivityThread activityThread, ApplicationInfo aInfo, - ActivityThread mainThread, ClassLoader baseLoader, - boolean securityViolation, boolean includeCode) { - mActivityThread = activityThread; - mApplicationInfo = aInfo; - mPackageName = aInfo.packageName; - mAppDir = aInfo.sourceDir; - mResDir = aInfo.uid == Process.myUid() ? aInfo.sourceDir - : aInfo.publicSourceDir; - mSharedLibraries = aInfo.sharedLibraryFiles; - mDataDir = aInfo.dataDir; - mDataDirFile = mDataDir != null ? new File(mDataDir) : null; - mBaseClassLoader = baseLoader; - mSecurityViolation = securityViolation; - mIncludeCode = includeCode; - mCompatibilityInfo = new CompatibilityInfo(aInfo); - - if (mAppDir == null) { - if (mSystemContext == null) { - mSystemContext = - ContextImpl.createSystemContext(mainThread); - mSystemContext.getResources().updateConfiguration( - mainThread.getConfiguration(), - mainThread.getDisplayMetricsLocked(false)); - //Slog.i(TAG, "Created system resources " - // + mSystemContext.getResources() + ": " - // + mSystemContext.getResources().getConfiguration()); - } - mClassLoader = mSystemContext.getClassLoader(); - mResources = mSystemContext.getResources(); - } - } - - public PackageInfo(ActivityThread activityThread, String name, - Context systemContext, ApplicationInfo info) { - mActivityThread = activityThread; - mApplicationInfo = info != null ? info : new ApplicationInfo(); - mApplicationInfo.packageName = name; - mPackageName = name; - mAppDir = null; - mResDir = null; - mSharedLibraries = null; - mDataDir = null; - mDataDirFile = null; - mBaseClassLoader = null; - mSecurityViolation = false; - mIncludeCode = true; - mClassLoader = systemContext.getClassLoader(); - mResources = systemContext.getResources(); - mCompatibilityInfo = new CompatibilityInfo(mApplicationInfo); - } - - public String getPackageName() { - return mPackageName; - } - - public ApplicationInfo getApplicationInfo() { - return mApplicationInfo; - } - - public boolean isSecurityViolation() { - return mSecurityViolation; - } - - /** - * Gets the array of shared libraries that are listed as - * used by the given package. - * - * @param packageName the name of the package (note: not its - * file name) - * @return null-ok; the array of shared libraries, each one - * a fully-qualified path - */ - private static String[] getLibrariesFor(String packageName) { - ApplicationInfo ai = null; - try { - ai = getPackageManager().getApplicationInfo(packageName, - PackageManager.GET_SHARED_LIBRARY_FILES); - } catch (RemoteException e) { - throw new AssertionError(e); - } - - if (ai == null) { - return null; - } - - return ai.sharedLibraryFiles; - } - - /** - * Combines two arrays (of library names) such that they are - * concatenated in order but are devoid of duplicates. The - * result is a single string with the names of the libraries - * separated by colons, or <code>null</code> if both lists - * were <code>null</code> or empty. - * - * @param list1 null-ok; the first list - * @param list2 null-ok; the second list - * @return null-ok; the combination - */ - private static String combineLibs(String[] list1, String[] list2) { - StringBuilder result = new StringBuilder(300); - boolean first = true; - - if (list1 != null) { - for (String s : list1) { - if (first) { - first = false; - } else { - result.append(':'); - } - result.append(s); - } - } - - // Only need to check for duplicates if list1 was non-empty. - boolean dupCheck = !first; - - if (list2 != null) { - for (String s : list2) { - if (dupCheck && ArrayUtils.contains(list1, s)) { - continue; - } - - if (first) { - first = false; - } else { - result.append(':'); - } - result.append(s); - } - } - - return result.toString(); - } - - public ClassLoader getClassLoader() { - synchronized (this) { - if (mClassLoader != null) { - return mClassLoader; - } - - if (mIncludeCode && !mPackageName.equals("android")) { - String zip = mAppDir; - - /* - * The following is a bit of a hack to inject - * instrumentation into the system: If the app - * being started matches one of the instrumentation names, - * then we combine both the "instrumentation" and - * "instrumented" app into the path, along with the - * concatenation of both apps' shared library lists. - */ - - String instrumentationAppDir = - mActivityThread.mInstrumentationAppDir; - String instrumentationAppPackage = - mActivityThread.mInstrumentationAppPackage; - String instrumentedAppDir = - mActivityThread.mInstrumentedAppDir; - String[] instrumentationLibs = null; - - if (mAppDir.equals(instrumentationAppDir) - || mAppDir.equals(instrumentedAppDir)) { - zip = instrumentationAppDir + ":" + instrumentedAppDir; - if (! instrumentedAppDir.equals(instrumentationAppDir)) { - instrumentationLibs = - getLibrariesFor(instrumentationAppPackage); - } - } - - if ((mSharedLibraries != null) || - (instrumentationLibs != null)) { - zip = - combineLibs(mSharedLibraries, instrumentationLibs) - + ':' + zip; - } - - /* - * With all the combination done (if necessary, actually - * create the class loader. - */ - - if (localLOGV) Slog.v(TAG, "Class path: " + zip); - - mClassLoader = - ApplicationLoaders.getDefault().getClassLoader( - zip, mDataDir, mBaseClassLoader); - initializeJavaContextClassLoader(); - } else { - if (mBaseClassLoader == null) { - mClassLoader = ClassLoader.getSystemClassLoader(); - } else { - mClassLoader = mBaseClassLoader; - } - } - return mClassLoader; - } - } - - /** - * Setup value for Thread.getContextClassLoader(). If the - * package will not run in in a VM with other packages, we set - * the Java context ClassLoader to the - * PackageInfo.getClassLoader value. However, if this VM can - * contain multiple packages, we intead set the Java context - * ClassLoader to a proxy that will warn about the use of Java - * context ClassLoaders and then fall through to use the - * system ClassLoader. - * - * <p> Note that this is similar to but not the same as the - * android.content.Context.getClassLoader(). While both - * context class loaders are typically set to the - * PathClassLoader used to load the package archive in the - * single application per VM case, a single Android process - * may contain several Contexts executing on one thread with - * their own logical ClassLoaders while the Java context - * ClassLoader is a thread local. This is why in the case when - * we have multiple packages per VM we do not set the Java - * context ClassLoader to an arbitrary but instead warn the - * user to set their own if we detect that they are using a - * Java library that expects it to be set. - */ - private void initializeJavaContextClassLoader() { - IPackageManager pm = getPackageManager(); - android.content.pm.PackageInfo pi; - try { - pi = pm.getPackageInfo(mPackageName, 0); - } catch (RemoteException e) { - throw new AssertionError(e); - } - /* - * Two possible indications that this package could be - * sharing its virtual machine with other packages: - * - * 1.) the sharedUserId attribute is set in the manifest, - * indicating a request to share a VM with other - * packages with the same sharedUserId. - * - * 2.) the application element of the manifest has an - * attribute specifying a non-default process name, - * indicating the desire to run in another packages VM. - */ - boolean sharedUserIdSet = (pi.sharedUserId != null); - boolean processNameNotDefault = - (pi.applicationInfo != null && - !mPackageName.equals(pi.applicationInfo.processName)); - boolean sharable = (sharedUserIdSet || processNameNotDefault); - ClassLoader contextClassLoader = - (sharable) - ? new WarningContextClassLoader() - : mClassLoader; - Thread.currentThread().setContextClassLoader(contextClassLoader); - } - - private static class WarningContextClassLoader extends ClassLoader { - - private static boolean warned = false; - - private void warn(String methodName) { - if (warned) { - return; - } - warned = true; - Thread.currentThread().setContextClassLoader(getParent()); - Slog.w(TAG, "ClassLoader." + methodName + ": " + - "The class loader returned by " + - "Thread.getContextClassLoader() may fail for processes " + - "that host multiple applications. You should explicitly " + - "specify a context class loader. For example: " + - "Thread.setContextClassLoader(getClass().getClassLoader());"); - } - - @Override public URL getResource(String resName) { - warn("getResource"); - return getParent().getResource(resName); - } - - @Override public Enumeration<URL> getResources(String resName) throws IOException { - warn("getResources"); - return getParent().getResources(resName); - } - - @Override public InputStream getResourceAsStream(String resName) { - warn("getResourceAsStream"); - return getParent().getResourceAsStream(resName); - } - - @Override public Class<?> loadClass(String className) throws ClassNotFoundException { - warn("loadClass"); - return getParent().loadClass(className); - } - - @Override public void setClassAssertionStatus(String cname, boolean enable) { - warn("setClassAssertionStatus"); - getParent().setClassAssertionStatus(cname, enable); - } - - @Override public void setPackageAssertionStatus(String pname, boolean enable) { - warn("setPackageAssertionStatus"); - getParent().setPackageAssertionStatus(pname, enable); - } - - @Override public void setDefaultAssertionStatus(boolean enable) { - warn("setDefaultAssertionStatus"); - getParent().setDefaultAssertionStatus(enable); - } - - @Override public void clearAssertionStatus() { - warn("clearAssertionStatus"); - getParent().clearAssertionStatus(); - } - } - - public String getAppDir() { - return mAppDir; - } - - public String getResDir() { - return mResDir; - } - - public String getDataDir() { - return mDataDir; - } - - public File getDataDirFile() { - return mDataDirFile; - } - - public AssetManager getAssets(ActivityThread mainThread) { - return getResources(mainThread).getAssets(); - } - - public Resources getResources(ActivityThread mainThread) { - if (mResources == null) { - mResources = mainThread.getTopLevelResources(mResDir, this); - } - return mResources; - } - - public Application makeApplication(boolean forceDefaultAppClass, - Instrumentation instrumentation) { - if (mApplication != null) { - return mApplication; - } - - Application app = null; - - String appClass = mApplicationInfo.className; - if (forceDefaultAppClass || (appClass == null)) { - appClass = "android.app.Application"; - } - - try { - java.lang.ClassLoader cl = getClassLoader(); - ContextImpl appContext = new ContextImpl(); - appContext.init(this, null, mActivityThread); - app = mActivityThread.mInstrumentation.newApplication( - cl, appClass, appContext); - appContext.setOuterContext(app); - } catch (Exception e) { - if (!mActivityThread.mInstrumentation.onException(app, e)) { - throw new RuntimeException( - "Unable to instantiate application " + appClass - + ": " + e.toString(), e); - } - } - mActivityThread.mAllApplications.add(app); - mApplication = app; - - if (instrumentation != null) { - try { - instrumentation.callApplicationOnCreate(app); - } catch (Exception e) { - if (!instrumentation.onException(app, e)) { - throw new RuntimeException( - "Unable to create application " + app.getClass().getName() - + ": " + e.toString(), e); - } - } - } - - return app; - } - - public void removeContextRegistrations(Context context, - String who, String what) { - HashMap<BroadcastReceiver, ReceiverDispatcher> rmap = - mReceivers.remove(context); - if (rmap != null) { - Iterator<ReceiverDispatcher> it = rmap.values().iterator(); - while (it.hasNext()) { - ReceiverDispatcher rd = it.next(); - IntentReceiverLeaked leak = new IntentReceiverLeaked( - what + " " + who + " has leaked IntentReceiver " - + rd.getIntentReceiver() + " that was " + - "originally registered here. Are you missing a " + - "call to unregisterReceiver()?"); - leak.setStackTrace(rd.getLocation().getStackTrace()); - Slog.e(TAG, leak.getMessage(), leak); - try { - ActivityManagerNative.getDefault().unregisterReceiver( - rd.getIIntentReceiver()); - } catch (RemoteException e) { - // system crashed, nothing we can do - } - } - } - mUnregisteredReceivers.remove(context); - //Slog.i(TAG, "Receiver registrations: " + mReceivers); - HashMap<ServiceConnection, ServiceDispatcher> smap = - mServices.remove(context); - if (smap != null) { - Iterator<ServiceDispatcher> it = smap.values().iterator(); - while (it.hasNext()) { - ServiceDispatcher sd = it.next(); - ServiceConnectionLeaked leak = new ServiceConnectionLeaked( - what + " " + who + " has leaked ServiceConnection " - + sd.getServiceConnection() + " that was originally bound here"); - leak.setStackTrace(sd.getLocation().getStackTrace()); - Slog.e(TAG, leak.getMessage(), leak); - try { - ActivityManagerNative.getDefault().unbindService( - sd.getIServiceConnection()); - } catch (RemoteException e) { - // system crashed, nothing we can do - } - sd.doForget(); - } - } - mUnboundServices.remove(context); - //Slog.i(TAG, "Service registrations: " + mServices); - } - - public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r, - Context context, Handler handler, - Instrumentation instrumentation, boolean registered) { - synchronized (mReceivers) { - ReceiverDispatcher rd = null; - HashMap<BroadcastReceiver, ReceiverDispatcher> map = null; - if (registered) { - map = mReceivers.get(context); - if (map != null) { - rd = map.get(r); - } - } - if (rd == null) { - rd = new ReceiverDispatcher(r, context, handler, - instrumentation, registered); - if (registered) { - if (map == null) { - map = new HashMap<BroadcastReceiver, ReceiverDispatcher>(); - mReceivers.put(context, map); - } - map.put(r, rd); - } - } else { - rd.validate(context, handler); - } - return rd.getIIntentReceiver(); - } - } - - public IIntentReceiver forgetReceiverDispatcher(Context context, - BroadcastReceiver r) { - synchronized (mReceivers) { - HashMap<BroadcastReceiver, ReceiverDispatcher> map = mReceivers.get(context); - ReceiverDispatcher rd = null; - if (map != null) { - rd = map.get(r); - if (rd != null) { - map.remove(r); - if (map.size() == 0) { - mReceivers.remove(context); - } - if (r.getDebugUnregister()) { - HashMap<BroadcastReceiver, ReceiverDispatcher> holder - = mUnregisteredReceivers.get(context); - if (holder == null) { - holder = new HashMap<BroadcastReceiver, ReceiverDispatcher>(); - mUnregisteredReceivers.put(context, holder); - } - RuntimeException ex = new IllegalArgumentException( - "Originally unregistered here:"); - ex.fillInStackTrace(); - rd.setUnregisterLocation(ex); - holder.put(r, rd); - } - return rd.getIIntentReceiver(); - } - } - HashMap<BroadcastReceiver, ReceiverDispatcher> holder - = mUnregisteredReceivers.get(context); - if (holder != null) { - rd = holder.get(r); - if (rd != null) { - RuntimeException ex = rd.getUnregisterLocation(); - throw new IllegalArgumentException( - "Unregistering Receiver " + r - + " that was already unregistered", ex); - } - } - if (context == null) { - throw new IllegalStateException("Unbinding Receiver " + r - + " from Context that is no longer in use: " + context); - } else { - throw new IllegalArgumentException("Receiver not registered: " + r); - } - - } - } - - static final class ReceiverDispatcher { - - final static class InnerReceiver extends IIntentReceiver.Stub { - final WeakReference<ReceiverDispatcher> mDispatcher; - final ReceiverDispatcher mStrongRef; - - InnerReceiver(ReceiverDispatcher rd, boolean strong) { - mDispatcher = new WeakReference<ReceiverDispatcher>(rd); - mStrongRef = strong ? rd : null; - } - public void performReceive(Intent intent, int resultCode, - String data, Bundle extras, boolean ordered, boolean sticky) { - ReceiverDispatcher rd = mDispatcher.get(); - if (DEBUG_BROADCAST) { - int seq = intent.getIntExtra("seq", -1); - Slog.i(TAG, "Receiving broadcast " + intent.getAction() + " seq=" + seq - + " to " + (rd != null ? rd.mReceiver : null)); - } - if (rd != null) { - rd.performReceive(intent, resultCode, data, extras, - ordered, sticky); - } else { - // The activity manager dispatched a broadcast to a registered - // receiver in this process, but before it could be delivered the - // receiver was unregistered. Acknowledge the broadcast on its - // behalf so that the system's broadcast sequence can continue. - if (DEBUG_BROADCAST) Slog.i(TAG, - "Finishing broadcast to unregistered receiver"); - IActivityManager mgr = ActivityManagerNative.getDefault(); - try { - mgr.finishReceiver(this, resultCode, data, extras, false); - } catch (RemoteException e) { - Slog.w(TAG, "Couldn't finish broadcast to unregistered receiver"); - } - } - } - } - - final IIntentReceiver.Stub mIIntentReceiver; - final BroadcastReceiver mReceiver; - final Context mContext; - final Handler mActivityThread; - final Instrumentation mInstrumentation; - final boolean mRegistered; - final IntentReceiverLeaked mLocation; - RuntimeException mUnregisterLocation; - - final class Args implements Runnable { - private Intent mCurIntent; - private int mCurCode; - private String mCurData; - private Bundle mCurMap; - private boolean mCurOrdered; - private boolean mCurSticky; - - public void run() { - BroadcastReceiver receiver = mReceiver; - if (DEBUG_BROADCAST) { - int seq = mCurIntent.getIntExtra("seq", -1); - Slog.i(TAG, "Dispatching broadcast " + mCurIntent.getAction() - + " seq=" + seq + " to " + mReceiver); - Slog.i(TAG, " mRegistered=" + mRegistered - + " mCurOrdered=" + mCurOrdered); - } - - IActivityManager mgr = ActivityManagerNative.getDefault(); - Intent intent = mCurIntent; - mCurIntent = null; - - if (receiver == null) { - if (mRegistered && mCurOrdered) { - try { - if (DEBUG_BROADCAST) Slog.i(TAG, - "Finishing null broadcast to " + mReceiver); - mgr.finishReceiver(mIIntentReceiver, - mCurCode, mCurData, mCurMap, false); - } catch (RemoteException ex) { - } - } - return; - } - - try { - ClassLoader cl = mReceiver.getClass().getClassLoader(); - intent.setExtrasClassLoader(cl); - if (mCurMap != null) { - mCurMap.setClassLoader(cl); - } - receiver.setOrderedHint(true); - receiver.setResult(mCurCode, mCurData, mCurMap); - receiver.clearAbortBroadcast(); - receiver.setOrderedHint(mCurOrdered); - receiver.setInitialStickyHint(mCurSticky); - receiver.onReceive(mContext, intent); - } catch (Exception e) { - if (mRegistered && mCurOrdered) { - try { - if (DEBUG_BROADCAST) Slog.i(TAG, - "Finishing failed broadcast to " + mReceiver); - mgr.finishReceiver(mIIntentReceiver, - mCurCode, mCurData, mCurMap, false); - } catch (RemoteException ex) { - } - } - if (mInstrumentation == null || - !mInstrumentation.onException(mReceiver, e)) { - throw new RuntimeException( - "Error receiving broadcast " + intent - + " in " + mReceiver, e); - } - } - if (mRegistered && mCurOrdered) { - try { - if (DEBUG_BROADCAST) Slog.i(TAG, - "Finishing broadcast to " + mReceiver); - mgr.finishReceiver(mIIntentReceiver, - receiver.getResultCode(), - receiver.getResultData(), - receiver.getResultExtras(false), - receiver.getAbortBroadcast()); - } catch (RemoteException ex) { - } - } - } - } - - ReceiverDispatcher(BroadcastReceiver receiver, Context context, - Handler activityThread, Instrumentation instrumentation, - boolean registered) { - if (activityThread == null) { - throw new NullPointerException("Handler must not be null"); - } - - mIIntentReceiver = new InnerReceiver(this, !registered); - mReceiver = receiver; - mContext = context; - mActivityThread = activityThread; - mInstrumentation = instrumentation; - mRegistered = registered; - mLocation = new IntentReceiverLeaked(null); - mLocation.fillInStackTrace(); - } - - void validate(Context context, Handler activityThread) { - if (mContext != context) { - throw new IllegalStateException( - "Receiver " + mReceiver + - " registered with differing Context (was " + - mContext + " now " + context + ")"); - } - if (mActivityThread != activityThread) { - throw new IllegalStateException( - "Receiver " + mReceiver + - " registered with differing handler (was " + - mActivityThread + " now " + activityThread + ")"); - } - } - - IntentReceiverLeaked getLocation() { - return mLocation; - } - - BroadcastReceiver getIntentReceiver() { - return mReceiver; - } - - IIntentReceiver getIIntentReceiver() { - return mIIntentReceiver; - } - - void setUnregisterLocation(RuntimeException ex) { - mUnregisterLocation = ex; - } - - RuntimeException getUnregisterLocation() { - return mUnregisterLocation; - } - - public void performReceive(Intent intent, int resultCode, - String data, Bundle extras, boolean ordered, boolean sticky) { - if (DEBUG_BROADCAST) { - int seq = intent.getIntExtra("seq", -1); - Slog.i(TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq - + " to " + mReceiver); - } - Args args = new Args(); - args.mCurIntent = intent; - args.mCurCode = resultCode; - args.mCurData = data; - args.mCurMap = extras; - args.mCurOrdered = ordered; - args.mCurSticky = sticky; - if (!mActivityThread.post(args)) { - if (mRegistered && ordered) { - IActivityManager mgr = ActivityManagerNative.getDefault(); - try { - if (DEBUG_BROADCAST) Slog.i(TAG, - "Finishing sync broadcast to " + mReceiver); - mgr.finishReceiver(mIIntentReceiver, args.mCurCode, - args.mCurData, args.mCurMap, false); - } catch (RemoteException ex) { - } - } - } - } - - } - - public final IServiceConnection getServiceDispatcher(ServiceConnection c, - Context context, Handler handler, int flags) { - synchronized (mServices) { - ServiceDispatcher sd = null; - HashMap<ServiceConnection, ServiceDispatcher> map = mServices.get(context); - if (map != null) { - sd = map.get(c); - } - if (sd == null) { - sd = new ServiceDispatcher(c, context, handler, flags); - if (map == null) { - map = new HashMap<ServiceConnection, ServiceDispatcher>(); - mServices.put(context, map); - } - map.put(c, sd); - } else { - sd.validate(context, handler); - } - return sd.getIServiceConnection(); - } - } - - public final IServiceConnection forgetServiceDispatcher(Context context, - ServiceConnection c) { - synchronized (mServices) { - HashMap<ServiceConnection, ServiceDispatcher> map - = mServices.get(context); - ServiceDispatcher sd = null; - if (map != null) { - sd = map.get(c); - if (sd != null) { - map.remove(c); - sd.doForget(); - if (map.size() == 0) { - mServices.remove(context); - } - if ((sd.getFlags()&Context.BIND_DEBUG_UNBIND) != 0) { - HashMap<ServiceConnection, ServiceDispatcher> holder - = mUnboundServices.get(context); - if (holder == null) { - holder = new HashMap<ServiceConnection, ServiceDispatcher>(); - mUnboundServices.put(context, holder); - } - RuntimeException ex = new IllegalArgumentException( - "Originally unbound here:"); - ex.fillInStackTrace(); - sd.setUnbindLocation(ex); - holder.put(c, sd); - } - return sd.getIServiceConnection(); - } - } - HashMap<ServiceConnection, ServiceDispatcher> holder - = mUnboundServices.get(context); - if (holder != null) { - sd = holder.get(c); - if (sd != null) { - RuntimeException ex = sd.getUnbindLocation(); - throw new IllegalArgumentException( - "Unbinding Service " + c - + " that was already unbound", ex); - } - } - if (context == null) { - throw new IllegalStateException("Unbinding Service " + c - + " from Context that is no longer in use: " + context); - } else { - throw new IllegalArgumentException("Service not registered: " + c); - } - } - } - - static final class ServiceDispatcher { - private final InnerConnection mIServiceConnection; - private final ServiceConnection mConnection; - private final Context mContext; - private final Handler mActivityThread; - private final ServiceConnectionLeaked mLocation; - private final int mFlags; - - private RuntimeException mUnbindLocation; - - private boolean mDied; - - private static class ConnectionInfo { - IBinder binder; - IBinder.DeathRecipient deathMonitor; - } - - private static class InnerConnection extends IServiceConnection.Stub { - final WeakReference<ServiceDispatcher> mDispatcher; - - InnerConnection(ServiceDispatcher sd) { - mDispatcher = new WeakReference<ServiceDispatcher>(sd); - } - - public void connected(ComponentName name, IBinder service) throws RemoteException { - ServiceDispatcher sd = mDispatcher.get(); - if (sd != null) { - sd.connected(name, service); - } - } - } - - private final HashMap<ComponentName, ConnectionInfo> mActiveConnections - = new HashMap<ComponentName, ConnectionInfo>(); - - ServiceDispatcher(ServiceConnection conn, - Context context, Handler activityThread, int flags) { - mIServiceConnection = new InnerConnection(this); - mConnection = conn; - mContext = context; - mActivityThread = activityThread; - mLocation = new ServiceConnectionLeaked(null); - mLocation.fillInStackTrace(); - mFlags = flags; - } - - void validate(Context context, Handler activityThread) { - if (mContext != context) { - throw new RuntimeException( - "ServiceConnection " + mConnection + - " registered with differing Context (was " + - mContext + " now " + context + ")"); - } - if (mActivityThread != activityThread) { - throw new RuntimeException( - "ServiceConnection " + mConnection + - " registered with differing handler (was " + - mActivityThread + " now " + activityThread + ")"); - } - } - - void doForget() { - synchronized(this) { - Iterator<ConnectionInfo> it = mActiveConnections.values().iterator(); - while (it.hasNext()) { - ConnectionInfo ci = it.next(); - ci.binder.unlinkToDeath(ci.deathMonitor, 0); - } - mActiveConnections.clear(); - } - } - - ServiceConnectionLeaked getLocation() { - return mLocation; - } - - ServiceConnection getServiceConnection() { - return mConnection; - } - - IServiceConnection getIServiceConnection() { - return mIServiceConnection; - } - - int getFlags() { - return mFlags; - } - - void setUnbindLocation(RuntimeException ex) { - mUnbindLocation = ex; - } - - RuntimeException getUnbindLocation() { - return mUnbindLocation; - } - - public void connected(ComponentName name, IBinder service) { - if (mActivityThread != null) { - mActivityThread.post(new RunConnection(name, service, 0)); - } else { - doConnected(name, service); - } - } - - public void death(ComponentName name, IBinder service) { - ConnectionInfo old; - - synchronized (this) { - mDied = true; - old = mActiveConnections.remove(name); - if (old == null || old.binder != service) { - // Death for someone different than who we last - // reported... just ignore it. - return; - } - old.binder.unlinkToDeath(old.deathMonitor, 0); - } - - if (mActivityThread != null) { - mActivityThread.post(new RunConnection(name, service, 1)); - } else { - doDeath(name, service); - } - } - - public void doConnected(ComponentName name, IBinder service) { - ConnectionInfo old; - ConnectionInfo info; - - synchronized (this) { - old = mActiveConnections.get(name); - if (old != null && old.binder == service) { - // Huh, already have this one. Oh well! - return; - } - - if (service != null) { - // A new service is being connected... set it all up. - mDied = false; - info = new ConnectionInfo(); - info.binder = service; - info.deathMonitor = new DeathMonitor(name, service); - try { - service.linkToDeath(info.deathMonitor, 0); - mActiveConnections.put(name, info); - } catch (RemoteException e) { - // This service was dead before we got it... just - // don't do anything with it. - mActiveConnections.remove(name); - return; - } - - } else { - // The named service is being disconnected... clean up. - mActiveConnections.remove(name); - } - - if (old != null) { - old.binder.unlinkToDeath(old.deathMonitor, 0); - } - } - - // If there was an old service, it is not disconnected. - if (old != null) { - mConnection.onServiceDisconnected(name); - } - // If there is a new service, it is now connected. - if (service != null) { - mConnection.onServiceConnected(name, service); - } - } - - public void doDeath(ComponentName name, IBinder service) { - mConnection.onServiceDisconnected(name); - } - - private final class RunConnection implements Runnable { - RunConnection(ComponentName name, IBinder service, int command) { - mName = name; - mService = service; - mCommand = command; - } - - public void run() { - if (mCommand == 0) { - doConnected(mName, mService); - } else if (mCommand == 1) { - doDeath(mName, mService); - } - } - - final ComponentName mName; - final IBinder mService; - final int mCommand; - } + static IPackageManager sPackageManager; - private final class DeathMonitor implements IBinder.DeathRecipient - { - DeathMonitor(ComponentName name, IBinder service) { - mName = name; - mService = service; - } + final ApplicationThread mAppThread = new ApplicationThread(); + final Looper mLooper = Looper.myLooper(); + final H mH = new H(); + final HashMap<IBinder, ActivityClientRecord> mActivities + = new HashMap<IBinder, ActivityClientRecord>(); + // List of new activities (via ActivityRecord.nextIdle) that should + // be reported when next we idle. + ActivityClientRecord mNewActivities = null; + // Number of activities that are currently visible on-screen. + int mNumVisibleActivities = 0; + final HashMap<IBinder, Service> mServices + = new HashMap<IBinder, Service>(); + AppBindData mBoundApplication; + Configuration mConfiguration; + Configuration mResConfiguration; + Application mInitialApplication; + final ArrayList<Application> mAllApplications + = new ArrayList<Application>(); + // set of instantiated backup agents, keyed by package name + final HashMap<String, BackupAgent> mBackupAgents = new HashMap<String, BackupAgent>(); + static final ThreadLocal sThreadLocal = new ThreadLocal(); + Instrumentation mInstrumentation; + String mInstrumentationAppDir = null; + String mInstrumentationAppPackage = null; + String mInstrumentedAppDir = null; + boolean mSystemThread = false; + boolean mJitEnabled = false; - public void binderDied() { - death(mName, mService); - } + // These can be accessed by multiple threads; mPackages is the lock. + // XXX For now we keep around information about all packages we have + // seen, not removing entries from this map. + final HashMap<String, WeakReference<LoadedApk>> mPackages + = new HashMap<String, WeakReference<LoadedApk>>(); + final HashMap<String, WeakReference<LoadedApk>> mResourcePackages + = new HashMap<String, WeakReference<LoadedApk>>(); + Display mDisplay = null; + DisplayMetrics mDisplayMetrics = null; + final HashMap<ResourcesKey, WeakReference<Resources> > mActiveResources + = new HashMap<ResourcesKey, WeakReference<Resources> >(); + final ArrayList<ActivityClientRecord> mRelaunchingActivities + = new ArrayList<ActivityClientRecord>(); + Configuration mPendingConfiguration = null; - final ComponentName mName; - final IBinder mService; - } - } - } + // The lock of mProviderMap protects the following variables. + final HashMap<String, ProviderClientRecord> mProviderMap + = new HashMap<String, ProviderClientRecord>(); + final HashMap<IBinder, ProviderRefCount> mProviderRefCountMap + = new HashMap<IBinder, ProviderRefCount>(); + final HashMap<IBinder, ProviderClientRecord> mLocalProviders + = new HashMap<IBinder, ProviderClientRecord>(); - private static ContextImpl mSystemContext = null; + final GcIdler mGcIdler = new GcIdler(); + boolean mGcIdlerScheduled = false; - private static final class ActivityRecord { + private static final class ActivityClientRecord { IBinder token; int ident; Intent intent; @@ -1309,10 +195,10 @@ public final class ActivityThread { boolean hideForNow; Configuration newConfig; Configuration createdConfig; - ActivityRecord nextIdle; + ActivityClientRecord nextIdle; ActivityInfo activityInfo; - PackageInfo packageInfo; + LoadedApk packageInfo; List<ResultInfo> pendingResults; List<Intent> pendingIntents; @@ -1320,7 +206,7 @@ public final class ActivityThread { boolean startsNotResumed; boolean isForward; - ActivityRecord() { + ActivityClientRecord() { parent = null; embeddedID = null; paused = false; @@ -1339,12 +225,12 @@ public final class ActivityThread { } } - private final class ProviderRecord implements IBinder.DeathRecipient { + private final class ProviderClientRecord implements IBinder.DeathRecipient { final String mName; final IContentProvider mProvider; final ContentProvider mLocalProvider; - ProviderRecord(String name, IContentProvider provider, + ProviderClientRecord(String name, IContentProvider provider, ContentProvider localProvider) { mName = name; mProvider = provider; @@ -1421,7 +307,7 @@ public final class ActivityThread { } private static final class AppBindData { - PackageInfo info; + LoadedApk info; String processName; ApplicationInfo appInfo; List<ProviderInfo> providers; @@ -1511,7 +397,7 @@ public final class ActivityThread { public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident, ActivityInfo info, Bundle state, List<ResultInfo> pendingResults, List<Intent> pendingNewIntents, boolean notResumed, boolean isForward) { - ActivityRecord r = new ActivityRecord(); + ActivityClientRecord r = new ActivityClientRecord(); r.token = token; r.ident = ident; @@ -1531,7 +417,7 @@ public final class ActivityThread { public final void scheduleRelaunchActivity(IBinder token, List<ResultInfo> pendingResults, List<Intent> pendingNewIntents, int configChanges, boolean notResumed, Configuration config) { - ActivityRecord r = new ActivityRecord(); + ActivityClientRecord r = new ActivityClientRecord(); r.token = token; r.pendingResults = pendingResults; @@ -2028,14 +914,14 @@ public final class ActivityThread { public void handleMessage(Message msg) { switch (msg.what) { case LAUNCH_ACTIVITY: { - ActivityRecord r = (ActivityRecord)msg.obj; + ActivityClientRecord r = (ActivityClientRecord)msg.obj; r.packageInfo = getPackageInfoNoCheck( r.activityInfo.applicationInfo); handleLaunchActivity(r, null); } break; case RELAUNCH_ACTIVITY: { - ActivityRecord r = (ActivityRecord)msg.obj; + ActivityClientRecord r = (ActivityClientRecord)msg.obj; handleRelaunchActivity(r, msg.arg1); } break; case PAUSE_ACTIVITY: @@ -2157,11 +1043,11 @@ public final class ActivityThread { private final class Idler implements MessageQueue.IdleHandler { public final boolean queueIdle() { - ActivityRecord a = mNewActivities; + ActivityClientRecord a = mNewActivities; if (a != null) { mNewActivities = null; IActivityManager am = ActivityManagerNative.getDefault(); - ActivityRecord prev; + ActivityClientRecord prev; do { if (localLOGV) Slog.v( TAG, "Reporting idle of " + a + @@ -2217,71 +1103,132 @@ public final class ActivityThread { } } - static IPackageManager sPackageManager; + public static final ActivityThread currentActivityThread() { + return (ActivityThread)sThreadLocal.get(); + } - final ApplicationThread mAppThread = new ApplicationThread(); - final Looper mLooper = Looper.myLooper(); - final H mH = new H(); - final HashMap<IBinder, ActivityRecord> mActivities - = new HashMap<IBinder, ActivityRecord>(); - // List of new activities (via ActivityRecord.nextIdle) that should - // be reported when next we idle. - ActivityRecord mNewActivities = null; - // Number of activities that are currently visible on-screen. - int mNumVisibleActivities = 0; - final HashMap<IBinder, Service> mServices - = new HashMap<IBinder, Service>(); - AppBindData mBoundApplication; - Configuration mConfiguration; - Configuration mResConfiguration; - Application mInitialApplication; - final ArrayList<Application> mAllApplications - = new ArrayList<Application>(); - // set of instantiated backup agents, keyed by package name - final HashMap<String, BackupAgent> mBackupAgents = new HashMap<String, BackupAgent>(); - static final ThreadLocal sThreadLocal = new ThreadLocal(); - Instrumentation mInstrumentation; - String mInstrumentationAppDir = null; - String mInstrumentationAppPackage = null; - String mInstrumentedAppDir = null; - boolean mSystemThread = false; - boolean mJitEnabled = false; + public static final String currentPackageName() { + ActivityThread am = currentActivityThread(); + return (am != null && am.mBoundApplication != null) + ? am.mBoundApplication.processName : null; + } - // These can be accessed by multiple threads; mPackages is the lock. - // XXX For now we keep around information about all packages we have - // seen, not removing entries from this map. - final HashMap<String, WeakReference<PackageInfo>> mPackages - = new HashMap<String, WeakReference<PackageInfo>>(); - final HashMap<String, WeakReference<PackageInfo>> mResourcePackages - = new HashMap<String, WeakReference<PackageInfo>>(); - Display mDisplay = null; - DisplayMetrics mDisplayMetrics = null; - final HashMap<ResourcesKey, WeakReference<Resources> > mActiveResources - = new HashMap<ResourcesKey, WeakReference<Resources> >(); - final ArrayList<ActivityRecord> mRelaunchingActivities - = new ArrayList<ActivityRecord>(); - Configuration mPendingConfiguration = null; + public static final Application currentApplication() { + ActivityThread am = currentActivityThread(); + return am != null ? am.mInitialApplication : null; + } - // The lock of mProviderMap protects the following variables. - final HashMap<String, ProviderRecord> mProviderMap - = new HashMap<String, ProviderRecord>(); - final HashMap<IBinder, ProviderRefCount> mProviderRefCountMap - = new HashMap<IBinder, ProviderRefCount>(); - final HashMap<IBinder, ProviderRecord> mLocalProviders - = new HashMap<IBinder, ProviderRecord>(); + public static IPackageManager getPackageManager() { + if (sPackageManager != null) { + //Slog.v("PackageManager", "returning cur default = " + sPackageManager); + return sPackageManager; + } + IBinder b = ServiceManager.getService("package"); + //Slog.v("PackageManager", "default service binder = " + b); + sPackageManager = IPackageManager.Stub.asInterface(b); + //Slog.v("PackageManager", "default service = " + sPackageManager); + return sPackageManager; + } - final GcIdler mGcIdler = new GcIdler(); - boolean mGcIdlerScheduled = false; + DisplayMetrics getDisplayMetricsLocked(boolean forceUpdate) { + if (mDisplayMetrics != null && !forceUpdate) { + return mDisplayMetrics; + } + if (mDisplay == null) { + WindowManager wm = WindowManagerImpl.getDefault(); + mDisplay = wm.getDefaultDisplay(); + } + DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics(); + mDisplay.getMetrics(metrics); + //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h=" + // + metrics.heightPixels + " den=" + metrics.density + // + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi); + return metrics; + } + + /** + * Creates the top level Resources for applications with the given compatibility info. + * + * @param resDir the resource directory. + * @param compInfo the compability info. It will use the default compatibility info when it's + * null. + */ + Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) { + ResourcesKey key = new ResourcesKey(resDir, compInfo.applicationScale); + Resources r; + synchronized (mPackages) { + // Resources is app scale dependent. + if (false) { + Slog.w(TAG, "getTopLevelResources: " + resDir + " / " + + compInfo.applicationScale); + } + WeakReference<Resources> wr = mActiveResources.get(key); + r = wr != null ? wr.get() : null; + //if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate()); + if (r != null && r.getAssets().isUpToDate()) { + if (false) { + Slog.w(TAG, "Returning cached resources " + r + " " + resDir + + ": appScale=" + r.getCompatibilityInfo().applicationScale); + } + return r; + } + } + + //if (r != null) { + // Slog.w(TAG, "Throwing away out-of-date resources!!!! " + // + r + " " + resDir); + //} + + AssetManager assets = new AssetManager(); + if (assets.addAssetPath(resDir) == 0) { + return null; + } + + //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics); + DisplayMetrics metrics = getDisplayMetricsLocked(false); + r = new Resources(assets, metrics, getConfiguration(), compInfo); + if (false) { + Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " + + r.getConfiguration() + " appScale=" + + r.getCompatibilityInfo().applicationScale); + } + + synchronized (mPackages) { + WeakReference<Resources> wr = mActiveResources.get(key); + Resources existing = wr != null ? wr.get() : null; + if (existing != null && existing.getAssets().isUpToDate()) { + // Someone else already created the resources while we were + // unlocked; go ahead and use theirs. + r.getAssets().close(); + return existing; + } + + // XXX need to remove entries when weak references go away + mActiveResources.put(key, new WeakReference<Resources>(r)); + return r; + } + } + + /** + * Creates the top level resources for the given package. + */ + Resources getTopLevelResources(String resDir, LoadedApk pkgInfo) { + return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo); + } + + final Handler getHandler() { + return mH; + } - public final PackageInfo getPackageInfo(String packageName, int flags) { + public final LoadedApk getPackageInfo(String packageName, int flags) { synchronized (mPackages) { - WeakReference<PackageInfo> ref; + WeakReference<LoadedApk> ref; if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) { ref = mPackages.get(packageName); } else { ref = mResourcePackages.get(packageName); } - PackageInfo packageInfo = ref != null ? ref.get() : null; + LoadedApk packageInfo = ref != null ? ref.get() : null; //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo); //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir // + ": " + packageInfo.mResources.getAssets().isUpToDate()); @@ -2313,7 +1260,7 @@ public final class ActivityThread { return null; } - public final PackageInfo getPackageInfo(ApplicationInfo ai, int flags) { + public final LoadedApk getPackageInfo(ApplicationInfo ai, int flags) { boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0; boolean securityViolation = includeCode && ai.uid != 0 && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null @@ -2335,20 +1282,20 @@ public final class ActivityThread { return getPackageInfo(ai, null, securityViolation, includeCode); } - public final PackageInfo getPackageInfoNoCheck(ApplicationInfo ai) { + public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai) { return getPackageInfo(ai, null, false, true); } - private final PackageInfo getPackageInfo(ApplicationInfo aInfo, + private final LoadedApk getPackageInfo(ApplicationInfo aInfo, ClassLoader baseLoader, boolean securityViolation, boolean includeCode) { synchronized (mPackages) { - WeakReference<PackageInfo> ref; + WeakReference<LoadedApk> ref; if (includeCode) { ref = mPackages.get(aInfo.packageName); } else { ref = mResourcePackages.get(aInfo.packageName); } - PackageInfo packageInfo = ref != null ? ref.get() : null; + LoadedApk packageInfo = ref != null ? ref.get() : null; if (packageInfo == null || (packageInfo.mResources != null && !packageInfo.mResources.getAssets().isUpToDate())) { if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package " @@ -2357,15 +1304,15 @@ public final class ActivityThread { ? mBoundApplication.processName : null) + ")"); packageInfo = - new PackageInfo(this, aInfo, this, baseLoader, + new LoadedApk(this, aInfo, this, baseLoader, securityViolation, includeCode && (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0); if (includeCode) { mPackages.put(aInfo.packageName, - new WeakReference<PackageInfo>(packageInfo)); + new WeakReference<LoadedApk>(packageInfo)); } else { mResourcePackages.put(aInfo.packageName, - new WeakReference<PackageInfo>(packageInfo)); + new WeakReference<LoadedApk>(packageInfo)); } } return packageInfo; @@ -2414,7 +1361,7 @@ public final class ActivityThread { if (mSystemContext == null) { ContextImpl context = ContextImpl.createSystemContext(this); - PackageInfo info = new PackageInfo(this, "android", context, null); + LoadedApk info = new LoadedApk(this, "android", context, null); context.init(info, null, this); context.getResources().updateConfiguration( getConfiguration(), getDisplayMetricsLocked(false)); @@ -2429,7 +1376,7 @@ public final class ActivityThread { public void installSystemApplicationInfo(ApplicationInfo info) { synchronized (this) { ContextImpl context = getSystemContext(); - context.init(new PackageInfo(this, "android", context, info), null, this); + context.init(new LoadedApk(this, "android", context, info), null, this); } } @@ -2481,7 +1428,7 @@ public final class ActivityThread { public final Activity startActivityNow(Activity parent, String id, Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state, Object lastNonConfigurationInstance) { - ActivityRecord r = new ActivityRecord(); + ActivityClientRecord r = new ActivityClientRecord(); r.token = token; r.ident = 0; r.intent = intent; @@ -2552,7 +1499,7 @@ public final class ActivityThread { queueOrSendMessage(H.CLEAN_UP_CONTEXT, cci); } - private final Activity performLaunchActivity(ActivityRecord r, Intent customIntent) { + private final Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")"); ActivityInfo aInfo = r.activityInfo; @@ -2671,7 +1618,7 @@ public final class ActivityThread { return activity; } - private final void handleLaunchActivity(ActivityRecord r, Intent customIntent) { + private final void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) { // If we are getting ready to gc after going to the background, well // we are back active so skip it. unscheduleGcIdler(); @@ -2731,7 +1678,7 @@ public final class ActivityThread { } } - private final void deliverNewIntents(ActivityRecord r, + private final void deliverNewIntents(ActivityClientRecord r, List<Intent> intents) { final int N = intents.size(); for (int i=0; i<N; i++) { @@ -2743,7 +1690,7 @@ public final class ActivityThread { public final void performNewIntents(IBinder token, List<Intent> intents) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (r != null) { final boolean resumed = !r.paused; if (resumed) { @@ -2767,7 +1714,7 @@ public final class ActivityThread { String component = data.intent.getComponent().getClassName(); - PackageInfo packageInfo = getPackageInfoNoCheck( + LoadedApk packageInfo = getPackageInfoNoCheck( data.info.applicationInfo); IActivityManager mgr = ActivityManagerNative.getDefault(); @@ -2851,7 +1798,7 @@ public final class ActivityThread { unscheduleGcIdler(); // instantiate the BackupAgent class named in the manifest - PackageInfo packageInfo = getPackageInfoNoCheck(data.appInfo); + LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo); String packageName = packageInfo.mPackageName; if (mBackupAgents.get(packageName) != null) { Slog.d(TAG, "BackupAgent " + " for " + packageName @@ -2913,7 +1860,7 @@ public final class ActivityThread { private final void handleDestroyBackupAgent(CreateBackupAgentData data) { if (DEBUG_BACKUP) Slog.v(TAG, "handleDestroyBackupAgent: " + data); - PackageInfo packageInfo = getPackageInfoNoCheck(data.appInfo); + LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo); String packageName = packageInfo.mPackageName; BackupAgent agent = mBackupAgents.get(packageName); if (agent != null) { @@ -2934,7 +1881,7 @@ public final class ActivityThread { // we are back active so skip it. unscheduleGcIdler(); - PackageInfo packageInfo = getPackageInfoNoCheck( + LoadedApk packageInfo = getPackageInfoNoCheck( data.info.applicationInfo); Service service = null; try { @@ -3098,9 +2045,9 @@ public final class ActivityThread { //Slog.i(TAG, "Running services: " + mServices); } - public final ActivityRecord performResumeActivity(IBinder token, + public final ActivityClientRecord performResumeActivity(IBinder token, boolean clearHide) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (localLOGV) Slog.v(TAG, "Performing resume of " + r + " finished=" + r.activity.mFinished); if (r != null && !r.activity.mFinished) { @@ -3142,7 +2089,7 @@ public final class ActivityThread { // we are back active so skip it. unscheduleGcIdler(); - ActivityRecord r = performResumeActivity(token, clearHide); + ActivityClientRecord r = performResumeActivity(token, clearHide); if (r != null) { final Activity a = r.activity; @@ -3241,7 +2188,7 @@ public final class ActivityThread { private int mThumbnailWidth = -1; private int mThumbnailHeight = -1; - private final Bitmap createThumbnailBitmap(ActivityRecord r) { + private final Bitmap createThumbnailBitmap(ActivityClientRecord r) { Bitmap thumbnail = null; try { int w = mThumbnailWidth; @@ -3279,7 +2226,7 @@ public final class ActivityThread { private final void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving, int configChanges) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (r != null) { //Slog.v(TAG, "userLeaving=" + userLeaving + " handling pause of " + r); if (userLeaving) { @@ -3297,17 +2244,17 @@ public final class ActivityThread { } } - final void performUserLeavingActivity(ActivityRecord r) { + final void performUserLeavingActivity(ActivityClientRecord r) { mInstrumentation.callActivityOnUserLeaving(r.activity); } final Bundle performPauseActivity(IBinder token, boolean finished, boolean saveState) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); return r != null ? performPauseActivity(r, finished, saveState) : null; } - final Bundle performPauseActivity(ActivityRecord r, boolean finished, + final Bundle performPauseActivity(ActivityClientRecord r, boolean finished, boolean saveState) { if (r.paused) { if (r.activity.mFinished) { @@ -3358,7 +2305,7 @@ public final class ActivityThread { } final void performStopActivity(IBinder token) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); performStopActivityInner(r, null, false); } @@ -3374,7 +2321,7 @@ public final class ActivityThread { } } - private final void performStopActivityInner(ActivityRecord r, + private final void performStopActivityInner(ActivityClientRecord r, StopInfo info, boolean keepShown) { if (localLOGV) Slog.v(TAG, "Performing stop of " + r); if (r != null) { @@ -3425,7 +2372,7 @@ public final class ActivityThread { } } - private final void updateVisibility(ActivityRecord r, boolean show) { + private final void updateVisibility(ActivityClientRecord r, boolean show) { View v = r.activity.mDecor; if (v != null) { if (show) { @@ -3453,7 +2400,7 @@ public final class ActivityThread { } private final void handleStopActivity(IBinder token, boolean show, int configChanges) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); r.activity.mConfigChangeFlags |= configChanges; StopInfo info = new StopInfo(); @@ -3474,7 +2421,7 @@ public final class ActivityThread { } final void performRestartActivity(IBinder token) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (r.stopped) { r.activity.performRestart(); r.stopped = false; @@ -3482,7 +2429,7 @@ public final class ActivityThread { } private final void handleWindowVisibility(IBinder token, boolean show) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (!show && !r.stopped) { performStopActivityInner(r, null, show); } else if (show && r.stopped) { @@ -3500,7 +2447,7 @@ public final class ActivityThread { } } - private final void deliverResults(ActivityRecord r, List<ResultInfo> results) { + private final void deliverResults(ActivityClientRecord r, List<ResultInfo> results) { final int N = results.size(); for (int i=0; i<N; i++) { ResultInfo ri = results.get(i); @@ -3524,7 +2471,7 @@ public final class ActivityThread { } private final void handleSendResult(ResultData res) { - ActivityRecord r = mActivities.get(res.token); + ActivityClientRecord r = mActivities.get(res.token); if (DEBUG_RESULTS) Slog.v(TAG, "Handling send result to " + r); if (r != null) { final boolean resumed = !r.paused; @@ -3563,13 +2510,13 @@ public final class ActivityThread { } } - public final ActivityRecord performDestroyActivity(IBinder token, boolean finishing) { + public final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing) { return performDestroyActivity(token, finishing, 0, false); } - private final ActivityRecord performDestroyActivity(IBinder token, boolean finishing, + private final ActivityClientRecord performDestroyActivity(IBinder token, boolean finishing, int configChanges, boolean getNonConfigInstance) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (localLOGV) Slog.v(TAG, "Performing finish of " + r); if (r != null) { r.activity.mConfigChangeFlags |= configChanges; @@ -3672,7 +2619,7 @@ public final class ActivityThread { private final void handleDestroyActivity(IBinder token, boolean finishing, int configChanges, boolean getNonConfigInstance) { - ActivityRecord r = performDestroyActivity(token, finishing, + ActivityClientRecord r = performDestroyActivity(token, finishing, configChanges, getNonConfigInstance); if (r != null) { WindowManager wm = r.activity.getWindowManager(); @@ -3713,7 +2660,7 @@ public final class ActivityThread { } } - private final void handleRelaunchActivity(ActivityRecord tmp, int configChanges) { + private final void handleRelaunchActivity(ActivityClientRecord tmp, int configChanges) { // If we are getting ready to gc after going to the background, well // we are back active so skip it. unscheduleGcIdler(); @@ -3732,7 +2679,7 @@ public final class ActivityThread { IBinder token = tmp.token; tmp = null; for (int i=0; i<N; i++) { - ActivityRecord r = mRelaunchingActivities.get(i); + ActivityClientRecord r = mRelaunchingActivities.get(i); if (r.token == token) { tmp = r; mRelaunchingActivities.remove(i); @@ -3774,7 +2721,7 @@ public final class ActivityThread { handleConfigurationChanged(changedConfig); } - ActivityRecord r = mActivities.get(tmp.token); + ActivityClientRecord r = mActivities.get(tmp.token); if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handling relaunch of " + r); if (r == null) { return; @@ -3818,7 +2765,7 @@ public final class ActivityThread { } private final void handleRequestThumbnail(IBinder token) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); Bitmap thumbnail = createThumbnailBitmap(r); CharSequence description = null; try { @@ -3845,9 +2792,9 @@ public final class ActivityThread { = new ArrayList<ComponentCallbacks>(); if (mActivities.size() > 0) { - Iterator<ActivityRecord> it = mActivities.values().iterator(); + Iterator<ActivityClientRecord> it = mActivities.values().iterator(); while (it.hasNext()) { - ActivityRecord ar = it.next(); + ActivityClientRecord ar = it.next(); Activity a = ar.activity; if (a != null) { if (!ar.activity.mFinished && (allActivities || @@ -3876,7 +2823,7 @@ public final class ActivityThread { } synchronized (mProviderMap) { if (mLocalProviders.size() > 0) { - Iterator<ProviderRecord> it = mLocalProviders.values().iterator(); + Iterator<ProviderClientRecord> it = mLocalProviders.values().iterator(); while (it.hasNext()) { callbacks.add(it.next().mLocalProvider); } @@ -4022,7 +2969,7 @@ public final class ActivityThread { } final void handleActivityConfigurationChanged(IBinder token) { - ActivityRecord r = mActivities.get(token); + ActivityClientRecord r = mActivities.get(token); if (r == null || r.activity == null) { return; } @@ -4059,7 +3006,7 @@ public final class ActivityThread { for (int i=packages.length-1; i>=0; i--) { //Slog.i(TAG, "Cleaning old package: " + packages[i]); if (!hasPkgInfo) { - WeakReference<PackageInfo> ref; + WeakReference<LoadedApk> ref; ref = mPackages.get(packages[i]); if (ref != null && ref.get() != null) { hasPkgInfo = true; @@ -4204,7 +3151,7 @@ public final class ActivityThread { instrApp.sourceDir = ii.sourceDir; instrApp.publicSourceDir = ii.publicSourceDir; instrApp.dataDir = ii.dataDir; - PackageInfo pi = getPackageInfo(instrApp, + LoadedApk pi = getPackageInfo(instrApp, appContext.getClassLoader(), false, true); ContextImpl instrContext = new ContextImpl(); instrContext.init(pi, null, this); @@ -4315,7 +3262,7 @@ public final class ActivityThread { private final IContentProvider getProvider(Context context, String name) { synchronized(mProviderMap) { - final ProviderRecord pr = mProviderMap.get(name); + final ProviderClientRecord pr = mProviderMap.get(name); if (pr != null) { return pr.mProvider; } @@ -4426,9 +3373,9 @@ public final class ActivityThread { String name = null; // remove the provider from mProviderMap - Iterator<ProviderRecord> iter = mProviderMap.values().iterator(); + Iterator<ProviderClientRecord> iter = mProviderMap.values().iterator(); while (iter.hasNext()) { - ProviderRecord pr = iter.next(); + ProviderClientRecord pr = iter.next(); IBinder myBinder = pr.mProvider.asBinder(); if (myBinder == providerBinder) { //find if its published by this process itself @@ -4453,10 +3400,10 @@ public final class ActivityThread { final void removeDeadProvider(String name, IContentProvider provider) { synchronized(mProviderMap) { - ProviderRecord pr = mProviderMap.get(name); + ProviderClientRecord pr = mProviderMap.get(name); if (pr.mProvider.asBinder() == provider.asBinder()) { Slog.i(TAG, "Removing dead content provider: " + name); - ProviderRecord removed = mProviderMap.remove(name); + ProviderClientRecord removed = mProviderMap.remove(name); if (removed != null) { removed.mProvider.asBinder().unlinkToDeath(removed, 0); } @@ -4465,10 +3412,10 @@ public final class ActivityThread { } final void removeDeadProviderLocked(String name, IContentProvider provider) { - ProviderRecord pr = mProviderMap.get(name); + ProviderClientRecord pr = mProviderMap.get(name); if (pr.mProvider.asBinder() == provider.asBinder()) { Slog.i(TAG, "Removing dead content provider: " + name); - ProviderRecord removed = mProviderMap.remove(name); + ProviderClientRecord removed = mProviderMap.remove(name); if (removed != null) { removed.mProvider.asBinder().unlinkToDeath(removed, 0); } @@ -4536,7 +3483,7 @@ public final class ActivityThread { // Cache the pointer for the remote provider. String names[] = PATTERN_SEMICOLON.split(info.authority); for (int i=0; i<names.length; i++) { - ProviderRecord pr = new ProviderRecord(names[i], provider, + ProviderClientRecord pr = new ProviderClientRecord(names[i], provider, localProvider); try { provider.asBinder().linkToDeath(pr, 0); @@ -4547,7 +3494,7 @@ public final class ActivityThread { } if (localProvider != null) { mLocalProviders.put(provider.asBinder(), - new ProviderRecord(null, provider, localProvider)); + new ProviderClientRecord(null, provider, localProvider)); } } diff --git a/core/java/android/app/AppGlobals.java b/core/java/android/app/AppGlobals.java new file mode 100644 index 0000000..9a39129 --- /dev/null +++ b/core/java/android/app/AppGlobals.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.app; + +import android.content.pm.IPackageManager; + +/** + * Special private access for certain globals related to a process. + * @hide + */ +public class AppGlobals { + /** + * Return the first Application object made in the process. + * NOTE: Only works on the main thread. + */ + public static Application getInitialApplication() { + return ActivityThread.currentApplication(); + } + + /** + * Return the package name of the first .apk loaded into the process. + * NOTE: Only works on the main thread. + */ + public static String getInitialPackage() { + return ActivityThread.currentPackageName(); + } + + /** + * Return the raw interface to the package manager. + * @return + */ + public static IPackageManager getPackageManager() { + return ActivityThread.getPackageManager(); + } +} diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index bcdfe59..fc9bcf7 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -173,7 +173,7 @@ class ContextImpl extends Context { new HashMap<File, SharedPreferencesImpl>(); private AudioManager mAudioManager; - /*package*/ ActivityThread.PackageInfo mPackageInfo; + /*package*/ LoadedApk mPackageInfo; private Resources mResources; /*package*/ ActivityThread mMainThread; private Context mOuterContext; @@ -696,7 +696,7 @@ class ContextImpl extends Context { if (scheduler == null) { scheduler = mMainThread.getHandler(); } - rd = new ActivityThread.PackageInfo.ReceiverDispatcher( + rd = new LoadedApk.ReceiverDispatcher( resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); } } @@ -739,7 +739,7 @@ class ContextImpl extends Context { if (scheduler == null) { scheduler = mMainThread.getHandler(); } - rd = new ActivityThread.PackageInfo.ReceiverDispatcher( + rd = new LoadedApk.ReceiverDispatcher( resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); } } @@ -795,7 +795,7 @@ class ContextImpl extends Context { if (scheduler == null) { scheduler = mMainThread.getHandler(); } - rd = new ActivityThread.PackageInfo.ReceiverDispatcher( + rd = new LoadedApk.ReceiverDispatcher( receiver, context, scheduler, null, true).getIIntentReceiver(); } } @@ -1425,7 +1425,7 @@ class ContextImpl extends Context { return new ContextImpl(mMainThread.getSystemContext()); } - ActivityThread.PackageInfo pi = + LoadedApk pi = mMainThread.getPackageInfo(packageName, flags); if (pi != null) { ContextImpl c = new ContextImpl(); @@ -1492,12 +1492,12 @@ class ContextImpl extends Context { mOuterContext = this; } - final void init(ActivityThread.PackageInfo packageInfo, + final void init(LoadedApk packageInfo, IBinder activityToken, ActivityThread mainThread) { init(packageInfo, activityToken, mainThread, null); } - final void init(ActivityThread.PackageInfo packageInfo, + final void init(LoadedApk packageInfo, IBinder activityToken, ActivityThread mainThread, Resources container) { mPackageInfo = packageInfo; diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java new file mode 100644 index 0000000..0f98152 --- /dev/null +++ b/core/java/android/app/LoadedApk.java @@ -0,0 +1,1103 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.app; + +import com.android.internal.util.ArrayUtils; + +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.IIntentReceiver; +import android.content.Intent; +import android.content.ServiceConnection; +import android.content.pm.ApplicationInfo; +import android.content.pm.IPackageManager; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.content.res.CompatibilityInfo; +import android.content.res.Resources; +import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.os.Process; +import android.os.RemoteException; +import android.util.AndroidRuntimeException; +import android.util.Slog; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.ref.WeakReference; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; + +final class IntentReceiverLeaked extends AndroidRuntimeException { + public IntentReceiverLeaked(String msg) { + super(msg); + } +} + +final class ServiceConnectionLeaked extends AndroidRuntimeException { + public ServiceConnectionLeaked(String msg) { + super(msg); + } +} + +/** + * Local state maintained about a currently loaded .apk. + * @hide + */ +final class LoadedApk { + + private final ActivityThread mActivityThread; + private final ApplicationInfo mApplicationInfo; + final String mPackageName; + private final String mAppDir; + private final String mResDir; + private final String[] mSharedLibraries; + private final String mDataDir; + private final File mDataDirFile; + private final ClassLoader mBaseClassLoader; + private final boolean mSecurityViolation; + private final boolean mIncludeCode; + Resources mResources; + private ClassLoader mClassLoader; + private Application mApplication; + CompatibilityInfo mCompatibilityInfo; + + private final HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>> mReceivers + = new HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>>(); + private final HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>> mUnregisteredReceivers + = new HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>>(); + private final HashMap<Context, HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>> mServices + = new HashMap<Context, HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>>(); + private final HashMap<Context, HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>> mUnboundServices + = new HashMap<Context, HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>>(); + + int mClientCount = 0; + + Application getApplication() { + return mApplication; + } + + public LoadedApk(ActivityThread activityThread, ApplicationInfo aInfo, + ActivityThread mainThread, ClassLoader baseLoader, + boolean securityViolation, boolean includeCode) { + mActivityThread = activityThread; + mApplicationInfo = aInfo; + mPackageName = aInfo.packageName; + mAppDir = aInfo.sourceDir; + mResDir = aInfo.uid == Process.myUid() ? aInfo.sourceDir + : aInfo.publicSourceDir; + mSharedLibraries = aInfo.sharedLibraryFiles; + mDataDir = aInfo.dataDir; + mDataDirFile = mDataDir != null ? new File(mDataDir) : null; + mBaseClassLoader = baseLoader; + mSecurityViolation = securityViolation; + mIncludeCode = includeCode; + mCompatibilityInfo = new CompatibilityInfo(aInfo); + + if (mAppDir == null) { + if (ActivityThread.mSystemContext == null) { + ActivityThread.mSystemContext = + ContextImpl.createSystemContext(mainThread); + ActivityThread.mSystemContext.getResources().updateConfiguration( + mainThread.getConfiguration(), + mainThread.getDisplayMetricsLocked(false)); + //Slog.i(TAG, "Created system resources " + // + mSystemContext.getResources() + ": " + // + mSystemContext.getResources().getConfiguration()); + } + mClassLoader = ActivityThread.mSystemContext.getClassLoader(); + mResources = ActivityThread.mSystemContext.getResources(); + } + } + + public LoadedApk(ActivityThread activityThread, String name, + Context systemContext, ApplicationInfo info) { + mActivityThread = activityThread; + mApplicationInfo = info != null ? info : new ApplicationInfo(); + mApplicationInfo.packageName = name; + mPackageName = name; + mAppDir = null; + mResDir = null; + mSharedLibraries = null; + mDataDir = null; + mDataDirFile = null; + mBaseClassLoader = null; + mSecurityViolation = false; + mIncludeCode = true; + mClassLoader = systemContext.getClassLoader(); + mResources = systemContext.getResources(); + mCompatibilityInfo = new CompatibilityInfo(mApplicationInfo); + } + + public String getPackageName() { + return mPackageName; + } + + public ApplicationInfo getApplicationInfo() { + return mApplicationInfo; + } + + public boolean isSecurityViolation() { + return mSecurityViolation; + } + + /** + * Gets the array of shared libraries that are listed as + * used by the given package. + * + * @param packageName the name of the package (note: not its + * file name) + * @return null-ok; the array of shared libraries, each one + * a fully-qualified path + */ + private static String[] getLibrariesFor(String packageName) { + ApplicationInfo ai = null; + try { + ai = ActivityThread.getPackageManager().getApplicationInfo(packageName, + PackageManager.GET_SHARED_LIBRARY_FILES); + } catch (RemoteException e) { + throw new AssertionError(e); + } + + if (ai == null) { + return null; + } + + return ai.sharedLibraryFiles; + } + + /** + * Combines two arrays (of library names) such that they are + * concatenated in order but are devoid of duplicates. The + * result is a single string with the names of the libraries + * separated by colons, or <code>null</code> if both lists + * were <code>null</code> or empty. + * + * @param list1 null-ok; the first list + * @param list2 null-ok; the second list + * @return null-ok; the combination + */ + private static String combineLibs(String[] list1, String[] list2) { + StringBuilder result = new StringBuilder(300); + boolean first = true; + + if (list1 != null) { + for (String s : list1) { + if (first) { + first = false; + } else { + result.append(':'); + } + result.append(s); + } + } + + // Only need to check for duplicates if list1 was non-empty. + boolean dupCheck = !first; + + if (list2 != null) { + for (String s : list2) { + if (dupCheck && ArrayUtils.contains(list1, s)) { + continue; + } + + if (first) { + first = false; + } else { + result.append(':'); + } + result.append(s); + } + } + + return result.toString(); + } + + public ClassLoader getClassLoader() { + synchronized (this) { + if (mClassLoader != null) { + return mClassLoader; + } + + if (mIncludeCode && !mPackageName.equals("android")) { + String zip = mAppDir; + + /* + * The following is a bit of a hack to inject + * instrumentation into the system: If the app + * being started matches one of the instrumentation names, + * then we combine both the "instrumentation" and + * "instrumented" app into the path, along with the + * concatenation of both apps' shared library lists. + */ + + String instrumentationAppDir = + mActivityThread.mInstrumentationAppDir; + String instrumentationAppPackage = + mActivityThread.mInstrumentationAppPackage; + String instrumentedAppDir = + mActivityThread.mInstrumentedAppDir; + String[] instrumentationLibs = null; + + if (mAppDir.equals(instrumentationAppDir) + || mAppDir.equals(instrumentedAppDir)) { + zip = instrumentationAppDir + ":" + instrumentedAppDir; + if (! instrumentedAppDir.equals(instrumentationAppDir)) { + instrumentationLibs = + getLibrariesFor(instrumentationAppPackage); + } + } + + if ((mSharedLibraries != null) || + (instrumentationLibs != null)) { + zip = + combineLibs(mSharedLibraries, instrumentationLibs) + + ':' + zip; + } + + /* + * With all the combination done (if necessary, actually + * create the class loader. + */ + + if (ActivityThread.localLOGV) Slog.v(ActivityThread.TAG, "Class path: " + zip); + + mClassLoader = + ApplicationLoaders.getDefault().getClassLoader( + zip, mDataDir, mBaseClassLoader); + initializeJavaContextClassLoader(); + } else { + if (mBaseClassLoader == null) { + mClassLoader = ClassLoader.getSystemClassLoader(); + } else { + mClassLoader = mBaseClassLoader; + } + } + return mClassLoader; + } + } + + /** + * Setup value for Thread.getContextClassLoader(). If the + * package will not run in in a VM with other packages, we set + * the Java context ClassLoader to the + * PackageInfo.getClassLoader value. However, if this VM can + * contain multiple packages, we intead set the Java context + * ClassLoader to a proxy that will warn about the use of Java + * context ClassLoaders and then fall through to use the + * system ClassLoader. + * + * <p> Note that this is similar to but not the same as the + * android.content.Context.getClassLoader(). While both + * context class loaders are typically set to the + * PathClassLoader used to load the package archive in the + * single application per VM case, a single Android process + * may contain several Contexts executing on one thread with + * their own logical ClassLoaders while the Java context + * ClassLoader is a thread local. This is why in the case when + * we have multiple packages per VM we do not set the Java + * context ClassLoader to an arbitrary but instead warn the + * user to set their own if we detect that they are using a + * Java library that expects it to be set. + */ + private void initializeJavaContextClassLoader() { + IPackageManager pm = ActivityThread.getPackageManager(); + android.content.pm.PackageInfo pi; + try { + pi = pm.getPackageInfo(mPackageName, 0); + } catch (RemoteException e) { + throw new AssertionError(e); + } + /* + * Two possible indications that this package could be + * sharing its virtual machine with other packages: + * + * 1.) the sharedUserId attribute is set in the manifest, + * indicating a request to share a VM with other + * packages with the same sharedUserId. + * + * 2.) the application element of the manifest has an + * attribute specifying a non-default process name, + * indicating the desire to run in another packages VM. + */ + boolean sharedUserIdSet = (pi.sharedUserId != null); + boolean processNameNotDefault = + (pi.applicationInfo != null && + !mPackageName.equals(pi.applicationInfo.processName)); + boolean sharable = (sharedUserIdSet || processNameNotDefault); + ClassLoader contextClassLoader = + (sharable) + ? new WarningContextClassLoader() + : mClassLoader; + Thread.currentThread().setContextClassLoader(contextClassLoader); + } + + private static class WarningContextClassLoader extends ClassLoader { + + private static boolean warned = false; + + private void warn(String methodName) { + if (warned) { + return; + } + warned = true; + Thread.currentThread().setContextClassLoader(getParent()); + Slog.w(ActivityThread.TAG, "ClassLoader." + methodName + ": " + + "The class loader returned by " + + "Thread.getContextClassLoader() may fail for processes " + + "that host multiple applications. You should explicitly " + + "specify a context class loader. For example: " + + "Thread.setContextClassLoader(getClass().getClassLoader());"); + } + + @Override public URL getResource(String resName) { + warn("getResource"); + return getParent().getResource(resName); + } + + @Override public Enumeration<URL> getResources(String resName) throws IOException { + warn("getResources"); + return getParent().getResources(resName); + } + + @Override public InputStream getResourceAsStream(String resName) { + warn("getResourceAsStream"); + return getParent().getResourceAsStream(resName); + } + + @Override public Class<?> loadClass(String className) throws ClassNotFoundException { + warn("loadClass"); + return getParent().loadClass(className); + } + + @Override public void setClassAssertionStatus(String cname, boolean enable) { + warn("setClassAssertionStatus"); + getParent().setClassAssertionStatus(cname, enable); + } + + @Override public void setPackageAssertionStatus(String pname, boolean enable) { + warn("setPackageAssertionStatus"); + getParent().setPackageAssertionStatus(pname, enable); + } + + @Override public void setDefaultAssertionStatus(boolean enable) { + warn("setDefaultAssertionStatus"); + getParent().setDefaultAssertionStatus(enable); + } + + @Override public void clearAssertionStatus() { + warn("clearAssertionStatus"); + getParent().clearAssertionStatus(); + } + } + + public String getAppDir() { + return mAppDir; + } + + public String getResDir() { + return mResDir; + } + + public String getDataDir() { + return mDataDir; + } + + public File getDataDirFile() { + return mDataDirFile; + } + + public AssetManager getAssets(ActivityThread mainThread) { + return getResources(mainThread).getAssets(); + } + + public Resources getResources(ActivityThread mainThread) { + if (mResources == null) { + mResources = mainThread.getTopLevelResources(mResDir, this); + } + return mResources; + } + + public Application makeApplication(boolean forceDefaultAppClass, + Instrumentation instrumentation) { + if (mApplication != null) { + return mApplication; + } + + Application app = null; + + String appClass = mApplicationInfo.className; + if (forceDefaultAppClass || (appClass == null)) { + appClass = "android.app.Application"; + } + + try { + java.lang.ClassLoader cl = getClassLoader(); + ContextImpl appContext = new ContextImpl(); + appContext.init(this, null, mActivityThread); + app = mActivityThread.mInstrumentation.newApplication( + cl, appClass, appContext); + appContext.setOuterContext(app); + } catch (Exception e) { + if (!mActivityThread.mInstrumentation.onException(app, e)) { + throw new RuntimeException( + "Unable to instantiate application " + appClass + + ": " + e.toString(), e); + } + } + mActivityThread.mAllApplications.add(app); + mApplication = app; + + if (instrumentation != null) { + try { + instrumentation.callApplicationOnCreate(app); + } catch (Exception e) { + if (!instrumentation.onException(app, e)) { + throw new RuntimeException( + "Unable to create application " + app.getClass().getName() + + ": " + e.toString(), e); + } + } + } + + return app; + } + + public void removeContextRegistrations(Context context, + String who, String what) { + HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> rmap = + mReceivers.remove(context); + if (rmap != null) { + Iterator<LoadedApk.ReceiverDispatcher> it = rmap.values().iterator(); + while (it.hasNext()) { + LoadedApk.ReceiverDispatcher rd = it.next(); + IntentReceiverLeaked leak = new IntentReceiverLeaked( + what + " " + who + " has leaked IntentReceiver " + + rd.getIntentReceiver() + " that was " + + "originally registered here. Are you missing a " + + "call to unregisterReceiver()?"); + leak.setStackTrace(rd.getLocation().getStackTrace()); + Slog.e(ActivityThread.TAG, leak.getMessage(), leak); + try { + ActivityManagerNative.getDefault().unregisterReceiver( + rd.getIIntentReceiver()); + } catch (RemoteException e) { + // system crashed, nothing we can do + } + } + } + mUnregisteredReceivers.remove(context); + //Slog.i(TAG, "Receiver registrations: " + mReceivers); + HashMap<ServiceConnection, LoadedApk.ServiceDispatcher> smap = + mServices.remove(context); + if (smap != null) { + Iterator<LoadedApk.ServiceDispatcher> it = smap.values().iterator(); + while (it.hasNext()) { + LoadedApk.ServiceDispatcher sd = it.next(); + ServiceConnectionLeaked leak = new ServiceConnectionLeaked( + what + " " + who + " has leaked ServiceConnection " + + sd.getServiceConnection() + " that was originally bound here"); + leak.setStackTrace(sd.getLocation().getStackTrace()); + Slog.e(ActivityThread.TAG, leak.getMessage(), leak); + try { + ActivityManagerNative.getDefault().unbindService( + sd.getIServiceConnection()); + } catch (RemoteException e) { + // system crashed, nothing we can do + } + sd.doForget(); + } + } + mUnboundServices.remove(context); + //Slog.i(TAG, "Service registrations: " + mServices); + } + + public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r, + Context context, Handler handler, + Instrumentation instrumentation, boolean registered) { + synchronized (mReceivers) { + LoadedApk.ReceiverDispatcher rd = null; + HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> map = null; + if (registered) { + map = mReceivers.get(context); + if (map != null) { + rd = map.get(r); + } + } + if (rd == null) { + rd = new ReceiverDispatcher(r, context, handler, + instrumentation, registered); + if (registered) { + if (map == null) { + map = new HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>(); + mReceivers.put(context, map); + } + map.put(r, rd); + } + } else { + rd.validate(context, handler); + } + return rd.getIIntentReceiver(); + } + } + + public IIntentReceiver forgetReceiverDispatcher(Context context, + BroadcastReceiver r) { + synchronized (mReceivers) { + HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> map = mReceivers.get(context); + LoadedApk.ReceiverDispatcher rd = null; + if (map != null) { + rd = map.get(r); + if (rd != null) { + map.remove(r); + if (map.size() == 0) { + mReceivers.remove(context); + } + if (r.getDebugUnregister()) { + HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> holder + = mUnregisteredReceivers.get(context); + if (holder == null) { + holder = new HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>(); + mUnregisteredReceivers.put(context, holder); + } + RuntimeException ex = new IllegalArgumentException( + "Originally unregistered here:"); + ex.fillInStackTrace(); + rd.setUnregisterLocation(ex); + holder.put(r, rd); + } + return rd.getIIntentReceiver(); + } + } + HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> holder + = mUnregisteredReceivers.get(context); + if (holder != null) { + rd = holder.get(r); + if (rd != null) { + RuntimeException ex = rd.getUnregisterLocation(); + throw new IllegalArgumentException( + "Unregistering Receiver " + r + + " that was already unregistered", ex); + } + } + if (context == null) { + throw new IllegalStateException("Unbinding Receiver " + r + + " from Context that is no longer in use: " + context); + } else { + throw new IllegalArgumentException("Receiver not registered: " + r); + } + + } + } + + static final class ReceiverDispatcher { + + final static class InnerReceiver extends IIntentReceiver.Stub { + final WeakReference<LoadedApk.ReceiverDispatcher> mDispatcher; + final LoadedApk.ReceiverDispatcher mStrongRef; + + InnerReceiver(LoadedApk.ReceiverDispatcher rd, boolean strong) { + mDispatcher = new WeakReference<LoadedApk.ReceiverDispatcher>(rd); + mStrongRef = strong ? rd : null; + } + public void performReceive(Intent intent, int resultCode, + String data, Bundle extras, boolean ordered, boolean sticky) { + LoadedApk.ReceiverDispatcher rd = mDispatcher.get(); + if (ActivityThread.DEBUG_BROADCAST) { + int seq = intent.getIntExtra("seq", -1); + Slog.i(ActivityThread.TAG, "Receiving broadcast " + intent.getAction() + " seq=" + seq + + " to " + (rd != null ? rd.mReceiver : null)); + } + if (rd != null) { + rd.performReceive(intent, resultCode, data, extras, + ordered, sticky); + } else { + // The activity manager dispatched a broadcast to a registered + // receiver in this process, but before it could be delivered the + // receiver was unregistered. Acknowledge the broadcast on its + // behalf so that the system's broadcast sequence can continue. + if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, + "Finishing broadcast to unregistered receiver"); + IActivityManager mgr = ActivityManagerNative.getDefault(); + try { + mgr.finishReceiver(this, resultCode, data, extras, false); + } catch (RemoteException e) { + Slog.w(ActivityThread.TAG, "Couldn't finish broadcast to unregistered receiver"); + } + } + } + } + + final IIntentReceiver.Stub mIIntentReceiver; + final BroadcastReceiver mReceiver; + final Context mContext; + final Handler mActivityThread; + final Instrumentation mInstrumentation; + final boolean mRegistered; + final IntentReceiverLeaked mLocation; + RuntimeException mUnregisterLocation; + + final class Args implements Runnable { + private Intent mCurIntent; + private int mCurCode; + private String mCurData; + private Bundle mCurMap; + private boolean mCurOrdered; + private boolean mCurSticky; + + public void run() { + BroadcastReceiver receiver = mReceiver; + if (ActivityThread.DEBUG_BROADCAST) { + int seq = mCurIntent.getIntExtra("seq", -1); + Slog.i(ActivityThread.TAG, "Dispatching broadcast " + mCurIntent.getAction() + + " seq=" + seq + " to " + mReceiver); + Slog.i(ActivityThread.TAG, " mRegistered=" + mRegistered + + " mCurOrdered=" + mCurOrdered); + } + + IActivityManager mgr = ActivityManagerNative.getDefault(); + Intent intent = mCurIntent; + mCurIntent = null; + + if (receiver == null) { + if (mRegistered && mCurOrdered) { + try { + if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, + "Finishing null broadcast to " + mReceiver); + mgr.finishReceiver(mIIntentReceiver, + mCurCode, mCurData, mCurMap, false); + } catch (RemoteException ex) { + } + } + return; + } + + try { + ClassLoader cl = mReceiver.getClass().getClassLoader(); + intent.setExtrasClassLoader(cl); + if (mCurMap != null) { + mCurMap.setClassLoader(cl); + } + receiver.setOrderedHint(true); + receiver.setResult(mCurCode, mCurData, mCurMap); + receiver.clearAbortBroadcast(); + receiver.setOrderedHint(mCurOrdered); + receiver.setInitialStickyHint(mCurSticky); + receiver.onReceive(mContext, intent); + } catch (Exception e) { + if (mRegistered && mCurOrdered) { + try { + if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, + "Finishing failed broadcast to " + mReceiver); + mgr.finishReceiver(mIIntentReceiver, + mCurCode, mCurData, mCurMap, false); + } catch (RemoteException ex) { + } + } + if (mInstrumentation == null || + !mInstrumentation.onException(mReceiver, e)) { + throw new RuntimeException( + "Error receiving broadcast " + intent + + " in " + mReceiver, e); + } + } + if (mRegistered && mCurOrdered) { + try { + if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, + "Finishing broadcast to " + mReceiver); + mgr.finishReceiver(mIIntentReceiver, + receiver.getResultCode(), + receiver.getResultData(), + receiver.getResultExtras(false), + receiver.getAbortBroadcast()); + } catch (RemoteException ex) { + } + } + } + } + + ReceiverDispatcher(BroadcastReceiver receiver, Context context, + Handler activityThread, Instrumentation instrumentation, + boolean registered) { + if (activityThread == null) { + throw new NullPointerException("Handler must not be null"); + } + + mIIntentReceiver = new InnerReceiver(this, !registered); + mReceiver = receiver; + mContext = context; + mActivityThread = activityThread; + mInstrumentation = instrumentation; + mRegistered = registered; + mLocation = new IntentReceiverLeaked(null); + mLocation.fillInStackTrace(); + } + + void validate(Context context, Handler activityThread) { + if (mContext != context) { + throw new IllegalStateException( + "Receiver " + mReceiver + + " registered with differing Context (was " + + mContext + " now " + context + ")"); + } + if (mActivityThread != activityThread) { + throw new IllegalStateException( + "Receiver " + mReceiver + + " registered with differing handler (was " + + mActivityThread + " now " + activityThread + ")"); + } + } + + IntentReceiverLeaked getLocation() { + return mLocation; + } + + BroadcastReceiver getIntentReceiver() { + return mReceiver; + } + + IIntentReceiver getIIntentReceiver() { + return mIIntentReceiver; + } + + void setUnregisterLocation(RuntimeException ex) { + mUnregisterLocation = ex; + } + + RuntimeException getUnregisterLocation() { + return mUnregisterLocation; + } + + public void performReceive(Intent intent, int resultCode, + String data, Bundle extras, boolean ordered, boolean sticky) { + if (ActivityThread.DEBUG_BROADCAST) { + int seq = intent.getIntExtra("seq", -1); + Slog.i(ActivityThread.TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq + + " to " + mReceiver); + } + Args args = new Args(); + args.mCurIntent = intent; + args.mCurCode = resultCode; + args.mCurData = data; + args.mCurMap = extras; + args.mCurOrdered = ordered; + args.mCurSticky = sticky; + if (!mActivityThread.post(args)) { + if (mRegistered && ordered) { + IActivityManager mgr = ActivityManagerNative.getDefault(); + try { + if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG, + "Finishing sync broadcast to " + mReceiver); + mgr.finishReceiver(mIIntentReceiver, args.mCurCode, + args.mCurData, args.mCurMap, false); + } catch (RemoteException ex) { + } + } + } + } + + } + + public final IServiceConnection getServiceDispatcher(ServiceConnection c, + Context context, Handler handler, int flags) { + synchronized (mServices) { + LoadedApk.ServiceDispatcher sd = null; + HashMap<ServiceConnection, LoadedApk.ServiceDispatcher> map = mServices.get(context); + if (map != null) { + sd = map.get(c); + } + if (sd == null) { + sd = new ServiceDispatcher(c, context, handler, flags); + if (map == null) { + map = new HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>(); + mServices.put(context, map); + } + map.put(c, sd); + } else { + sd.validate(context, handler); + } + return sd.getIServiceConnection(); + } + } + + public final IServiceConnection forgetServiceDispatcher(Context context, + ServiceConnection c) { + synchronized (mServices) { + HashMap<ServiceConnection, LoadedApk.ServiceDispatcher> map + = mServices.get(context); + LoadedApk.ServiceDispatcher sd = null; + if (map != null) { + sd = map.get(c); + if (sd != null) { + map.remove(c); + sd.doForget(); + if (map.size() == 0) { + mServices.remove(context); + } + if ((sd.getFlags()&Context.BIND_DEBUG_UNBIND) != 0) { + HashMap<ServiceConnection, LoadedApk.ServiceDispatcher> holder + = mUnboundServices.get(context); + if (holder == null) { + holder = new HashMap<ServiceConnection, LoadedApk.ServiceDispatcher>(); + mUnboundServices.put(context, holder); + } + RuntimeException ex = new IllegalArgumentException( + "Originally unbound here:"); + ex.fillInStackTrace(); + sd.setUnbindLocation(ex); + holder.put(c, sd); + } + return sd.getIServiceConnection(); + } + } + HashMap<ServiceConnection, LoadedApk.ServiceDispatcher> holder + = mUnboundServices.get(context); + if (holder != null) { + sd = holder.get(c); + if (sd != null) { + RuntimeException ex = sd.getUnbindLocation(); + throw new IllegalArgumentException( + "Unbinding Service " + c + + " that was already unbound", ex); + } + } + if (context == null) { + throw new IllegalStateException("Unbinding Service " + c + + " from Context that is no longer in use: " + context); + } else { + throw new IllegalArgumentException("Service not registered: " + c); + } + } + } + + static final class ServiceDispatcher { + private final ServiceDispatcher.InnerConnection mIServiceConnection; + private final ServiceConnection mConnection; + private final Context mContext; + private final Handler mActivityThread; + private final ServiceConnectionLeaked mLocation; + private final int mFlags; + + private RuntimeException mUnbindLocation; + + private boolean mDied; + + private static class ConnectionInfo { + IBinder binder; + IBinder.DeathRecipient deathMonitor; + } + + private static class InnerConnection extends IServiceConnection.Stub { + final WeakReference<LoadedApk.ServiceDispatcher> mDispatcher; + + InnerConnection(LoadedApk.ServiceDispatcher sd) { + mDispatcher = new WeakReference<LoadedApk.ServiceDispatcher>(sd); + } + + public void connected(ComponentName name, IBinder service) throws RemoteException { + LoadedApk.ServiceDispatcher sd = mDispatcher.get(); + if (sd != null) { + sd.connected(name, service); + } + } + } + + private final HashMap<ComponentName, ServiceDispatcher.ConnectionInfo> mActiveConnections + = new HashMap<ComponentName, ServiceDispatcher.ConnectionInfo>(); + + ServiceDispatcher(ServiceConnection conn, + Context context, Handler activityThread, int flags) { + mIServiceConnection = new InnerConnection(this); + mConnection = conn; + mContext = context; + mActivityThread = activityThread; + mLocation = new ServiceConnectionLeaked(null); + mLocation.fillInStackTrace(); + mFlags = flags; + } + + void validate(Context context, Handler activityThread) { + if (mContext != context) { + throw new RuntimeException( + "ServiceConnection " + mConnection + + " registered with differing Context (was " + + mContext + " now " + context + ")"); + } + if (mActivityThread != activityThread) { + throw new RuntimeException( + "ServiceConnection " + mConnection + + " registered with differing handler (was " + + mActivityThread + " now " + activityThread + ")"); + } + } + + void doForget() { + synchronized(this) { + Iterator<ServiceDispatcher.ConnectionInfo> it = mActiveConnections.values().iterator(); + while (it.hasNext()) { + ServiceDispatcher.ConnectionInfo ci = it.next(); + ci.binder.unlinkToDeath(ci.deathMonitor, 0); + } + mActiveConnections.clear(); + } + } + + ServiceConnectionLeaked getLocation() { + return mLocation; + } + + ServiceConnection getServiceConnection() { + return mConnection; + } + + IServiceConnection getIServiceConnection() { + return mIServiceConnection; + } + + int getFlags() { + return mFlags; + } + + void setUnbindLocation(RuntimeException ex) { + mUnbindLocation = ex; + } + + RuntimeException getUnbindLocation() { + return mUnbindLocation; + } + + public void connected(ComponentName name, IBinder service) { + if (mActivityThread != null) { + mActivityThread.post(new RunConnection(name, service, 0)); + } else { + doConnected(name, service); + } + } + + public void death(ComponentName name, IBinder service) { + ServiceDispatcher.ConnectionInfo old; + + synchronized (this) { + mDied = true; + old = mActiveConnections.remove(name); + if (old == null || old.binder != service) { + // Death for someone different than who we last + // reported... just ignore it. + return; + } + old.binder.unlinkToDeath(old.deathMonitor, 0); + } + + if (mActivityThread != null) { + mActivityThread.post(new RunConnection(name, service, 1)); + } else { + doDeath(name, service); + } + } + + public void doConnected(ComponentName name, IBinder service) { + ServiceDispatcher.ConnectionInfo old; + ServiceDispatcher.ConnectionInfo info; + + synchronized (this) { + old = mActiveConnections.get(name); + if (old != null && old.binder == service) { + // Huh, already have this one. Oh well! + return; + } + + if (service != null) { + // A new service is being connected... set it all up. + mDied = false; + info = new ConnectionInfo(); + info.binder = service; + info.deathMonitor = new DeathMonitor(name, service); + try { + service.linkToDeath(info.deathMonitor, 0); + mActiveConnections.put(name, info); + } catch (RemoteException e) { + // This service was dead before we got it... just + // don't do anything with it. + mActiveConnections.remove(name); + return; + } + + } else { + // The named service is being disconnected... clean up. + mActiveConnections.remove(name); + } + + if (old != null) { + old.binder.unlinkToDeath(old.deathMonitor, 0); + } + } + + // If there was an old service, it is not disconnected. + if (old != null) { + mConnection.onServiceDisconnected(name); + } + // If there is a new service, it is now connected. + if (service != null) { + mConnection.onServiceConnected(name, service); + } + } + + public void doDeath(ComponentName name, IBinder service) { + mConnection.onServiceDisconnected(name); + } + + private final class RunConnection implements Runnable { + RunConnection(ComponentName name, IBinder service, int command) { + mName = name; + mService = service; + mCommand = command; + } + + public void run() { + if (mCommand == 0) { + doConnected(mName, mService); + } else if (mCommand == 1) { + doDeath(mName, mService); + } + } + + final ComponentName mName; + final IBinder mService; + final int mCommand; + } + + private final class DeathMonitor implements IBinder.DeathRecipient + { + DeathMonitor(ComponentName name, IBinder service) { + mName = name; + mService = service; + } + + public void binderDied() { + death(mName, mService); + } + + final ComponentName mName; + final IBinder mService; + } + } +} diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java index b4718ab..69f7611 100644 --- a/core/java/android/content/ContentResolver.java +++ b/core/java/android/content/ContentResolver.java @@ -18,6 +18,7 @@ package android.content; import android.accounts.Account; import android.app.ActivityThread; +import android.app.AppGlobals; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetFileDescriptor; import android.content.res.Resources; @@ -1306,7 +1307,7 @@ public abstract class ContentResolver { // ActivityThread.currentPackageName() only returns non-null if the // current thread is an application main thread. This parameter tells // us whether an event loop is blocked, and if so, which app it is. - String blockingPackage = ActivityThread.currentPackageName(); + String blockingPackage = AppGlobals.getInitialPackage(); EventLog.writeEvent( EventLogTags.CONTENT_QUERY_SAMPLE, @@ -1329,7 +1330,7 @@ public abstract class ContentResolver { } } } - String blockingPackage = ActivityThread.currentPackageName(); + String blockingPackage = AppGlobals.getInitialPackage(); EventLog.writeEvent( EventLogTags.CONTENT_UPDATE_SAMPLE, uri.toString(), diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index 0e798dc..cdc9bbb 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -19,6 +19,7 @@ package android.database.sqlite; import com.google.android.collect.Maps; import android.app.ActivityThread; +import android.app.AppGlobals; import android.content.ContentValues; import android.database.Cursor; import android.database.DatabaseUtils; @@ -1921,7 +1922,7 @@ public class SQLiteDatabase extends SQLiteClosable { // main thread, or when we are invoked via Binder (e.g. ContentProvider). // Hopefully the full path to the database will be informative enough. - String blockingPackage = ActivityThread.currentPackageName(); + String blockingPackage = AppGlobals.getInitialPackage(); if (blockingPackage == null) blockingPackage = ""; EventLog.writeEvent( diff --git a/opengl/java/com/google/android/gles_jni/GLImpl.java b/opengl/java/com/google/android/gles_jni/GLImpl.java index 30b9325..090c0cb 100644 --- a/opengl/java/com/google/android/gles_jni/GLImpl.java +++ b/opengl/java/com/google/android/gles_jni/GLImpl.java @@ -19,7 +19,7 @@ package com.google.android.gles_jni; -import android.app.ActivityThread; +import android.app.AppGlobals; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.os.Build; @@ -65,7 +65,7 @@ public class GLImpl implements GL10, GL10Ext, GL11, GL11Ext, GL11ExtensionPack { private static boolean allowIndirectBuffers(String appName) { boolean result = false; int version = 0; - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); try { ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0); if (applicationInfo != null) { diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index 2c388ee..49e792c 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -17,8 +17,8 @@ package com.android.server; import android.app.ActivityManagerNative; -import android.app.ActivityThread; import android.app.AlarmManager; +import android.app.AppGlobals; import android.app.IActivityManager; import android.app.IApplicationThread; import android.app.IBackupAgent; @@ -399,7 +399,7 @@ class BackupManagerService extends IBackupManager.Stub { public BackupManagerService(Context context) { mContext = context; mPackageManager = context.getPackageManager(); - mPackageManagerBinder = ActivityThread.getPackageManager(); + mPackageManagerBinder = AppGlobals.getPackageManager(); mActivityManager = ActivityManagerNative.getDefault(); mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index b3f49d9..0e1eb6f 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -34,6 +34,7 @@ import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.app.ActivityThread; import android.app.AlertDialog; +import android.app.AppGlobals; import android.app.ApplicationErrorReport; import android.app.Dialog; import android.app.IActivityController; @@ -410,8 +411,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * due to app switches being disabled. */ class PendingActivityLaunch { - HistoryRecord r; - HistoryRecord sourceRecord; + ActivityRecord r; + ActivityRecord sourceRecord; Uri[] grantedUriPermissions; int grantedMode; boolean onlyIfNeeded; @@ -471,47 +472,47 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * When we are in the process of pausing an activity, before starting the * next one, this variable holds the activity that is currently being paused. */ - HistoryRecord mPausingActivity = null; + ActivityRecord mPausingActivity = null; /** * Current activity that is resumed, or null if there is none. */ - HistoryRecord mResumedActivity = null; + ActivityRecord mResumedActivity = null; /** * Activity we have told the window manager to have key focus. */ - HistoryRecord mFocusedActivity = null; + ActivityRecord mFocusedActivity = null; /** * This is the last activity that we put into the paused state. This is * used to determine if we need to do an activity transition while sleeping, * when we normally hold the top activity paused. */ - HistoryRecord mLastPausedActivity = null; + ActivityRecord mLastPausedActivity = null; /** * List of activities that are waiting for a new activity * to become visible before completing whatever operation they are * supposed to do. */ - final ArrayList<HistoryRecord> mWaitingVisibleActivities - = new ArrayList<HistoryRecord>(); + final ArrayList<ActivityRecord> mWaitingVisibleActivities + = new ArrayList<ActivityRecord>(); /** * List of activities that are ready to be stopped, but waiting * for the next activity to settle down before doing so. It contains * HistoryRecord objects. */ - final ArrayList<HistoryRecord> mStoppingActivities - = new ArrayList<HistoryRecord>(); + final ArrayList<ActivityRecord> mStoppingActivities + = new ArrayList<ActivityRecord>(); /** * Animations that for the current transition have requested not to * be considered for the transition animation. */ - final ArrayList<HistoryRecord> mNoAnimActivities - = new ArrayList<HistoryRecord>(); + final ArrayList<ActivityRecord> mNoAnimActivities + = new ArrayList<ActivityRecord>(); /** * List of intents that were used to start the most recent tasks. @@ -524,8 +525,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * for the previous activity to settle down before doing so. It contains * HistoryRecord objects. */ - final ArrayList<HistoryRecord> mFinishingActivities - = new ArrayList<HistoryRecord>(); + final ArrayList<ActivityRecord> mFinishingActivities + = new ArrayList<ActivityRecord>(); /** * All of the applications we currently have running organized by name. @@ -1096,7 +1097,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen false, false, MY_PID, Process.SYSTEM_UID); Dialog d = new AppNotRespondingDialog(ActivityManagerService.this, - mContext, proc, (HistoryRecord)data.get("activity")); + mContext, proc, (ActivityRecord)data.get("activity")); d.show(); proc.anrDialog = d; } @@ -1310,7 +1311,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return; } - HistoryRecord root = (HistoryRecord)msg.obj; + ActivityRecord root = (ActivityRecord)msg.obj; ProcessRecord process = root.app; if (process == null) { return; @@ -1716,7 +1717,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return mAppBindArgs; } - private final void setFocusedActivityLocked(HistoryRecord r) { + private final void setFocusedActivityLocked(ActivityRecord r) { if (mFocusedActivity != r) { mFocusedActivity = r; mWindowManager.setFocusedApp(r, true); @@ -1807,16 +1808,16 @@ public final class ActivityManagerService extends ActivityManagerNative implemen updateLruProcessInternalLocked(app, oomAdj, updateActivityTime, 0); } - private final boolean updateLRUListLocked(HistoryRecord r) { + private final boolean updateLRUListLocked(ActivityRecord r) { final boolean hadit = mLRUActivities.remove(r); mLRUActivities.add(r); return hadit; } - private final HistoryRecord topRunningActivityLocked(HistoryRecord notTop) { + private final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { int i = mHistory.size()-1; while (i >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (!r.finishing && r != notTop) { return r; } @@ -1825,10 +1826,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return null; } - private final HistoryRecord topRunningNonDelayedActivityLocked(HistoryRecord notTop) { + private final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { int i = mHistory.size()-1; while (i >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (!r.finishing && !r.delayedResume && r != notTop) { return r; } @@ -1846,10 +1847,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * * @return Returns the HistoryRecord of the next activity on the stack. */ - private final HistoryRecord topRunningActivityLocked(IBinder token, int taskId) { + private final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { int i = mHistory.size()-1; while (i >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); // Note: the taskId check depends on real taskId fields being non-zero if (!r.finishing && (token != r) && (taskId != r.task.taskId)) { return r; @@ -1874,7 +1875,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } private void ensurePackageDexOpt(String packageName) { - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); try { if (pm.performDexOpt(packageName)) { mDidDexOpt = true; @@ -1890,7 +1891,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen || transit == WindowManagerPolicy.TRANSIT_TASK_TO_FRONT; } - private final boolean realStartActivityLocked(HistoryRecord r, + private final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, boolean andResume, boolean checkConfig) throws RemoteException { @@ -2019,7 +2020,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return true; } - private final void startSpecificActivityLocked(HistoryRecord r, + private final void startSpecificActivityLocked(ActivityRecord r, boolean andResume, boolean checkConfig) { // Is this activity's application already running? ProcessRecord app = getProcessRecordLocked(r.processName, @@ -2258,7 +2259,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen Slog.e(TAG, "Trying to pause when pause is already pending for " + mPausingActivity, e); } - HistoryRecord prev = mResumedActivity; + ActivityRecord prev = mResumedActivity; if (prev == null) { RuntimeException e = new RuntimeException(); Slog.e(TAG, "Trying to pause when nothing is resumed", e); @@ -2333,7 +2334,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } private final void completePauseLocked() { - HistoryRecord prev = mPausingActivity; + ActivityRecord prev = mPausingActivity; if (DEBUG_PAUSE) Slog.v(TAG, "Complete pause: " + prev); if (prev != null) { @@ -2415,7 +2416,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * the resumed state (either by launching it or explicitly telling it), * this function updates the rest of our state to match that fact. */ - private final void completeResumeLocked(HistoryRecord next) { + private final void completeResumeLocked(ActivityRecord next) { next.idle = false; next.results = null; next.newIntents = null; @@ -2460,8 +2461,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * Make sure that all activities that need to be visible (that is, they * currently can be seen by the user) actually are. */ - private final void ensureActivitiesVisibleLocked(HistoryRecord top, - HistoryRecord starting, String onlyThisProcess, int configChanges) { + private final void ensureActivitiesVisibleLocked(ActivityRecord top, + ActivityRecord starting, String onlyThisProcess, int configChanges) { if (DEBUG_VISBILITY) Slog.v( TAG, "ensureActivitiesVisible behind " + top + " configChanges=0x" + Integer.toHexString(configChanges)); @@ -2473,10 +2474,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen while (mHistory.get(i) != top) { i--; } - HistoryRecord r; + ActivityRecord r; boolean behindFullscreen = false; for (; i>=0; i--) { - r = (HistoryRecord)mHistory.get(i); + r = (ActivityRecord)mHistory.get(i); if (DEBUG_VISBILITY) Slog.v( TAG, "Make visible? " + r + " finishing=" + r.finishing + " state=" + r.state); @@ -2559,7 +2560,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Now for any activities that aren't visible to the user, make // sure they no longer are keeping the screen frozen. while (i >= 0) { - r = (HistoryRecord)mHistory.get(i); + r = (ActivityRecord)mHistory.get(i); if (DEBUG_VISBILITY) Slog.v( TAG, "Make invisible? " + r + " finishing=" + r.finishing + " state=" + r.state @@ -2602,15 +2603,15 @@ public final class ActivityManagerService extends ActivityManagerNative implemen /** * Version of ensureActivitiesVisible that can easily be called anywhere. */ - private final void ensureActivitiesVisibleLocked(HistoryRecord starting, + private final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) { - HistoryRecord r = topRunningActivityLocked(null); + ActivityRecord r = topRunningActivityLocked(null); if (r != null) { ensureActivitiesVisibleLocked(r, starting, null, configChanges); } } - private void updateUsageStats(HistoryRecord resumedComponent, boolean resumed) { + private void updateUsageStats(ActivityRecord resumedComponent, boolean resumed) { if (resumed) { mUsageStatsService.noteResumeComponent(resumedComponent.realActivity); } else { @@ -2708,7 +2709,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - private void reportResumedActivityLocked(HistoryRecord r) { + private void reportResumedActivityLocked(ActivityRecord r) { //Slog.i(TAG, "**** REPORT RESUME: " + r); final int identHash = System.identityHashCode(r); @@ -2737,9 +2738,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * @return Returns true if something is being resumed, or false if * nothing happened. */ - private final boolean resumeTopActivityLocked(HistoryRecord prev) { + private final boolean resumeTopActivityLocked(ActivityRecord prev) { // Find the first activity that is not finishing. - HistoryRecord next = topRunningActivityLocked(null); + ActivityRecord next = topRunningActivityLocked(null); // Remember how we'll process this pause/resume situation, and ensure // that the state is reset however we wind up proceeding. @@ -2873,7 +2874,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // This activity is now becoming visible. mWindowManager.setAppVisibility(next, true); - HistoryRecord lastResumedActivity = mResumedActivity; + ActivityRecord lastResumedActivity = mResumedActivity; ActivityState lastState = next.state; updateCpuStats(); @@ -2902,7 +2903,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // We should be all done, but let's just make sure our activity // is still at the top and schedule another run if something // weird happened. - HistoryRecord nextNext = topRunningActivityLocked(null); + ActivityRecord nextNext = topRunningActivityLocked(null); if (DEBUG_SWITCH) Slog.i(TAG, "Activity config changed during resume: " + next + ", new next: " + nextNext); @@ -3000,7 +3001,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return true; } - private final void startActivityLocked(HistoryRecord r, boolean newTask, + private final void startActivityLocked(ActivityRecord r, boolean newTask, boolean doResume) { final int NH = mHistory.size(); @@ -3008,10 +3009,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (!newTask) { // If starting in an existing task, find where that is... - HistoryRecord next = null; + ActivityRecord next = null; boolean startIt = true; for (int i = NH-1; i >= 0; i--) { - HistoryRecord p = (HistoryRecord)mHistory.get(i); + ActivityRecord p = (ActivityRecord)mHistory.get(i); if (p.finishing) { continue; } @@ -3105,7 +3106,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // "has the same starting icon" as the next one. This allows the // window manager to keep the previous window it had previously // created, if it still had one. - HistoryRecord prev = mResumedActivity; + ActivityRecord prev = mResumedActivity; if (prev != null) { // We don't want to reuse the previous starting preview if: // (1) The current activity is in a different task. @@ -3143,14 +3144,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * @return Returns the old activity that should be continue to be used, * or null if none was found. */ - private final HistoryRecord performClearTaskLocked(int taskId, - HistoryRecord newR, int launchFlags, boolean doClear) { + private final ActivityRecord performClearTaskLocked(int taskId, + ActivityRecord newR, int launchFlags, boolean doClear) { int i = mHistory.size(); // First find the requested task. while (i > 0) { i--; - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r.task.taskId == taskId) { i++; break; @@ -3160,7 +3161,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Now clear it. while (i > 0) { i--; - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r.finishing) { continue; } @@ -3169,11 +3170,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } if (r.realActivity.equals(newR.realActivity)) { // Here it is! Now finish everything in front... - HistoryRecord ret = r; + ActivityRecord ret = r; if (doClear) { while (i < (mHistory.size()-1)) { i++; - r = (HistoryRecord)mHistory.get(i); + r = (ActivityRecord)mHistory.get(i); if (r.finishing) { continue; } @@ -3210,11 +3211,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * Find the activity in the history stack within the given task. Returns * the index within the history at which it's found, or < 0 if not found. */ - private final int findActivityInHistoryLocked(HistoryRecord r, int task) { + private final int findActivityInHistoryLocked(ActivityRecord r, int task) { int i = mHistory.size(); while (i > 0) { i--; - HistoryRecord candidate = (HistoryRecord)mHistory.get(i); + ActivityRecord candidate = (ActivityRecord)mHistory.get(i); if (candidate.task.taskId != task) { break; } @@ -3230,10 +3231,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * Reorder the history stack so that the activity at the given index is * brought to the front. */ - private final HistoryRecord moveActivityToFrontLocked(int where) { - HistoryRecord newTop = (HistoryRecord)mHistory.remove(where); + private final ActivityRecord moveActivityToFrontLocked(int where) { + ActivityRecord newTop = (ActivityRecord)mHistory.remove(where); int top = mHistory.size(); - HistoryRecord oldTop = (HistoryRecord)mHistory.get(top-1); + ActivityRecord oldTop = (ActivityRecord)mHistory.get(top-1); mHistory.add(top, newTop); oldTop.frontOfTask = false; newTop.frontOfTask = true; @@ -3244,7 +3245,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * Deliver a new Intent to an existing activity, so that its onNewIntent() * method will be called at the proper time. */ - private final void deliverNewIntentLocked(HistoryRecord r, Intent intent) { + private final void deliverNewIntentLocked(ActivityRecord r, Intent intent) { boolean sent = false; if (r.state == ActivityState.RESUMED && r.app != null && r.app.thread != null) { @@ -3262,7 +3263,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - private final void logStartActivity(int tag, HistoryRecord r, + private final void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { EventLog.writeEvent(tag, System.identityHashCode(r), task.taskId, @@ -3280,14 +3281,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen boolean componentSpecified) { Slog.i(TAG, "Starting activity: " + intent); - HistoryRecord sourceRecord = null; - HistoryRecord resultRecord = null; + ActivityRecord sourceRecord = null; + ActivityRecord resultRecord = null; if (resultTo != null) { int index = indexOfTokenLocked(resultTo); if (DEBUG_RESULTS) Slog.v( TAG, "Sending result to " + resultTo + " (index " + index + ")"); if (index >= 0) { - sourceRecord = (HistoryRecord)mHistory.get(index); + sourceRecord = (ActivityRecord)mHistory.get(index); if (requestCode >= 0 && !sourceRecord.finishing) { resultRecord = sourceRecord; } @@ -3390,7 +3391,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - HistoryRecord r = new HistoryRecord(this, callerApp, callingUid, + ActivityRecord r = new ActivityRecord(this, callerApp, callingUid, intent, resolvedType, aInfo, mConfiguration, resultRecord, resultWho, requestCode, componentSpecified); @@ -3439,8 +3440,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen mPendingActivityLaunches.clear(); } - private final int startActivityUncheckedLocked(HistoryRecord r, - HistoryRecord sourceRecord, Uri[] grantedUriPermissions, + private final int startActivityUncheckedLocked(ActivityRecord r, + ActivityRecord sourceRecord, Uri[] grantedUriPermissions, int grantedMode, boolean onlyIfNeeded, boolean doResume) { final Intent intent = r.intent; final int callingUid = r.launchedFromUid; @@ -3460,7 +3461,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen r.delayedResume = true; } - HistoryRecord notTop = (launchFlags&Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP) + ActivityRecord notTop = (launchFlags&Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP) != 0 ? r : null; // If the onlyIfNeeded flag is set, then we can do this if the activity @@ -3468,7 +3469,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // a special case, if we do not know the caller then we count the // current top activity as the caller. if (onlyIfNeeded) { - HistoryRecord checkedCaller = sourceRecord; + ActivityRecord checkedCaller = sourceRecord; if (checkedCaller == null) { checkedCaller = topRunningNonDelayedActivityLocked(notTop); } @@ -3534,7 +3535,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // a SINGLE_INSTANCE activity, there can be one and only one // instance of it in the history, and it is always in its own // unique task, so we do a special search. - HistoryRecord taskTop = r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE + ActivityRecord taskTop = r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE ? findTaskLocked(intent, r.info) : findActivityLocked(intent, r.info); if (taskTop != null) { @@ -3551,7 +3552,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // to have the same behavior as if a new instance was // being started, which means not bringing it to the front // if the caller is not itself in the front. - HistoryRecord curTop = topRunningNonDelayedActivityLocked(notTop); + ActivityRecord curTop = topRunningNonDelayedActivityLocked(notTop); if (curTop.task != taskTop.task) { r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); boolean callerAtFront = sourceRecord == null @@ -3584,7 +3585,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // from the task up to the one being started. In most // cases this means we are resetting the task to its // initial state. - HistoryRecord top = performClearTaskLocked( + ActivityRecord top = performClearTaskLocked( taskTop.task.taskId, r, launchFlags, true); if (top != null) { if (top.frontOfTask) { @@ -3669,7 +3670,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // If the activity being launched is the same as the one currently // at the top, then we need to check if it should only be launched // once. - HistoryRecord top = topRunningNonDelayedActivityLocked(notTop); + ActivityRecord top = topRunningNonDelayedActivityLocked(notTop); if (top != null && r.resultTo == null) { if (top.realActivity.equals(r.realActivity)) { if (top.app != null && top.app.thread != null) { @@ -3727,7 +3728,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // In this case, we are adding the activity to an existing // task, but the caller has asked to clear that task if the // activity is already running. - HistoryRecord top = performClearTaskLocked( + ActivityRecord top = performClearTaskLocked( sourceRecord.task.taskId, r, launchFlags, true); if (top != null) { logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task); @@ -3746,7 +3747,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // we want to shuffle it to the front of the stack if so. int where = findActivityInHistoryLocked(r, sourceRecord.task.taskId); if (where >= 0) { - HistoryRecord top = moveActivityToFrontLocked(where); + ActivityRecord top = moveActivityToFrontLocked(where); logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task); deliverNewIntentLocked(top, r.intent); if (doResume) { @@ -3767,8 +3768,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // of a new task... just put it in the top task, though these days // this case should never happen. final int N = mHistory.size(); - HistoryRecord prev = - N > 0 ? (HistoryRecord)mHistory.get(N-1) : null; + ActivityRecord prev = + N > 0 ? (ActivityRecord)mHistory.get(N-1) : null; r.task = prev != null ? prev.task : new TaskRecord(mCurTask, r.info, intent, @@ -3784,7 +3785,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return START_SUCCESS; } - void reportActivityLaunchedLocked(boolean timeout, HistoryRecord r, + void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, long thisTime, long totalTime) { for (int i=mWaitingActivityLaunched.size()-1; i>=0; i--) { WaitResult w = mWaitingActivityLaunched.get(i); @@ -3798,7 +3799,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen notify(); } - void reportActivityVisibleLocked(HistoryRecord r) { + void reportActivityVisibleLocked(ActivityRecord r) { for (int i=mWaitingActivityVisible.size()-1; i>=0; i--) { WaitResult w = mWaitingActivityVisible.get(i); w.timeout = false; @@ -3830,7 +3831,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen ActivityInfo aInfo; try { ResolveInfo rInfo = - ActivityThread.getPackageManager().resolveIntent( + AppGlobals.getPackageManager().resolveIntent( intent, resolvedType, PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS); @@ -3908,7 +3909,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT, new IntentSender(target)); if (mHeavyWeightProcess.activities.size() > 0) { - HistoryRecord hist = mHeavyWeightProcess.activities.get(0); + ActivityRecord hist = mHeavyWeightProcess.activities.get(0); newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_APP, hist.packageName); newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_TASK, @@ -3927,7 +3928,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen componentSpecified = true; try { ResolveInfo rInfo = - ActivityThread.getPackageManager().resolveIntent( + AppGlobals.getPackageManager().resolveIntent( intent, null, PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS); @@ -3970,7 +3971,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } while (!outResult.timeout && outResult.who == null); } else if (res == IActivityManager.START_TASK_TO_FRONT) { - HistoryRecord r = this.topRunningActivityLocked(null); + ActivityRecord r = this.topRunningActivityLocked(null); if (r.nowVisible) { outResult.timeout = false; outResult.who = new ComponentName(r.info.packageName, r.info.name); @@ -4067,7 +4068,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return false; } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); if (r.app == null || r.app.thread == null) { // The caller is not running... d'oh! return false; @@ -4081,7 +4082,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen ActivityInfo aInfo = null; try { List<ResolveInfo> resolves = - ActivityThread.getPackageManager().queryIntentActivities( + AppGlobals.getPackageManager().queryIntentActivities( intent, r.resolvedType, PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS); @@ -4125,7 +4126,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen r.finishing = true; // Propagate reply information over to the new activity. - final HistoryRecord resultTo = r.resultTo; + final ActivityRecord resultTo = r.resultTo; final String resultWho = r.resultWho; final int requestCode = r.requestCode; r.resultTo = null; @@ -4170,7 +4171,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen ActivityInfo aInfo; try { ResolveInfo rInfo = - ActivityThread.getPackageManager().resolveIntent( + AppGlobals.getPackageManager().resolveIntent( intent, resolvedType, PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS); aInfo = rInfo != null ? rInfo.activityInfo : null; @@ -4224,7 +4225,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return; } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); final long origId = Binder.clearCallingIdentity(); mWindowManager.setAppOrientation(r, requestedOrientation); Configuration config = mWindowManager.updateOrientationFromAppTokens( @@ -4246,12 +4247,12 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); return mWindowManager.getAppOrientation(r); } } - private final void stopActivityLocked(HistoryRecord r) { + private final void stopActivityLocked(ActivityRecord r) { if (DEBUG_SWITCH) Slog.d(TAG, "Stopping: " + r); if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { @@ -4302,12 +4303,12 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return false; } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); // Is this the last activity left? boolean lastActivity = true; for (int i=mHistory.size()-1; i>=0; i--) { - HistoryRecord p = (HistoryRecord)mHistory.get(i); + ActivityRecord p = (ActivityRecord)mHistory.get(i); if (!p.finishing && p != r) { lastActivity = false; break; @@ -4330,7 +4331,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * @return Returns true if this activity has been removed from the history * list, or false if it is still in the list and will be removed later. */ - private final boolean finishActivityLocked(HistoryRecord r, int index, + private final boolean finishActivityLocked(ActivityRecord r, int index, int resultCode, Intent resultData, String reason) { if (r.finishing) { Slog.w(TAG, "Duplicate finish request for " + r); @@ -4343,7 +4344,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen r.task.taskId, r.shortComponentName, reason); r.task.numActivities--; if (index < (mHistory.size()-1)) { - HistoryRecord next = (HistoryRecord)mHistory.get(index+1); + ActivityRecord next = (ActivityRecord)mHistory.get(index+1); if (next.task == r.task) { if (r.frontOfTask) { // The next activity is now the front of the task. @@ -4364,7 +4365,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } // send the result - HistoryRecord resultTo = r.resultTo; + ActivityRecord resultTo = r.resultTo; if (resultTo != null) { if (DEBUG_RESULTS) Slog.v(TAG, "Adding result to " + resultTo + " who=" + r.resultWho + " req=" + r.requestCode @@ -4396,7 +4397,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (mResumedActivity == r) { boolean endTask = index <= 0 - || ((HistoryRecord)mHistory.get(index-1)).task != r.task; + || ((ActivityRecord)mHistory.get(index-1)).task != r.task; if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare close transition: finishing " + r); mWindowManager.prepareAppTransition(endTask @@ -4429,7 +4430,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen private static final int FINISH_AFTER_PAUSE = 1; private static final int FINISH_AFTER_VISIBLE = 2; - private final HistoryRecord finishCurrentActivityLocked(HistoryRecord r, + private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode) { final int index = indexOfTokenLocked(r); if (index < 0) { @@ -4439,7 +4440,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return finishCurrentActivityLocked(r, index, mode); } - private final HistoryRecord finishCurrentActivityLocked(HistoryRecord r, + private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int index, int mode) { // First things first: if this activity is currently visible, // and the resumed activity is not yet visible, then hold off on @@ -4504,7 +4505,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen synchronized(this) { if (mController != null) { // Find the first activity that is not finishing. - HistoryRecord next = topRunningActivityLocked(token, 0); + ActivityRecord next = topRunningActivityLocked(token, 0); if (next != null) { // ask watcher if this is allowed boolean resumeOK = true; @@ -4543,10 +4544,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return; } - ArrayList<HistoryRecord> activities = new ArrayList<HistoryRecord>( + ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>( mHeavyWeightProcess.activities); for (int i=0; i<activities.size(); i++) { - HistoryRecord r = activities.get(i); + ActivityRecord r = activities.get(i); if (!r.finishing) { int index = indexOfTokenLocked(r); if (index >= 0) { @@ -4561,7 +4562,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - void sendActivityResultLocked(int callingUid, HistoryRecord r, + void sendActivityResultLocked(int callingUid, ActivityRecord r, String resultWho, int requestCode, int resultCode, Intent data) { if (callingUid > 0) { @@ -4594,13 +4595,13 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return; } - HistoryRecord self = (HistoryRecord)mHistory.get(index); + ActivityRecord self = (ActivityRecord)mHistory.get(index); final long origId = Binder.clearCallingIdentity(); int i; for (i=mHistory.size()-1; i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r.resultTo == self && r.requestCode == requestCode) { if ((r.resultWho == null && resultWho == null) || (r.resultWho != null && r.resultWho.equals(resultWho))) { @@ -4618,7 +4619,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen synchronized(this) { int i; for (i=mHistory.size()-1; i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r == token) { return true; } @@ -4637,7 +4638,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return; } - HistoryRecord self = (HistoryRecord)mHistory.get(index); + ActivityRecord self = (ActivityRecord)mHistory.get(index); final long origId = Binder.clearCallingIdentity(); @@ -4654,7 +4655,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen /** * Perform clean-up of service connections in an activity record. */ - private final void cleanUpActivityServicesLocked(HistoryRecord r) { + private final void cleanUpActivityServicesLocked(ActivityRecord r) { // Throw away any services that have been bound by this activity. if (r.connections != null) { Iterator<ConnectionRecord> it = r.connections.iterator(); @@ -4673,7 +4674,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * processing going away, in which case there is no remaining client-side * state to destroy so only the cleanup here is needed. */ - private final void cleanUpActivityLocked(HistoryRecord r, boolean cleanServices) { + private final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices) { if (mResumedActivity == r) { mResumedActivity = null; } @@ -4717,7 +4718,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); } - private final void removeActivityFromHistoryLocked(HistoryRecord r) { + private final void removeActivityFromHistoryLocked(ActivityRecord r) { if (r.state != ActivityState.DESTROYED) { mHistory.remove(r); r.inHistory = false; @@ -4737,7 +4738,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * a configuration switch where we destroy the current client-side object * but then create a new client-side object for this same HistoryRecord. */ - private final boolean destroyActivityLocked(HistoryRecord r, + private final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp) { if (DEBUG_SWITCH) Slog.v( TAG, "Removing activity: token=" + r @@ -4827,7 +4828,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen + " with " + i + " entries"); while (i > 0) { i--; - HistoryRecord r = (HistoryRecord)list.get(i); + ActivityRecord r = (ActivityRecord)list.get(i); if (localLOGV) Slog.v( TAG, "Record #" + i + " " + r + ": app=" + r.app); if (r.app == app) { @@ -4873,7 +4874,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen TAG, "Removing app " + app + " from history with " + i + " entries"); while (i > 0) { i--; - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (localLOGV) Slog.v( TAG, "Record #" + i + " " + r + ": app=" + r.app); if (r.app == app) { @@ -5078,8 +5079,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return tracesFile; } - final void appNotResponding(ProcessRecord app, HistoryRecord activity, - HistoryRecord parent, final String annotation) { + final void appNotResponding(ProcessRecord app, ActivityRecord activity, + ActivityRecord parent, final String annotation) { ArrayList<Integer> pids = new ArrayList<Integer>(20); synchronized (this) { @@ -5231,7 +5232,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return; } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); ProcessRecord app = r.app; if (localLOGV) Slog.v( @@ -5283,7 +5284,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen int pid = Binder.getCallingPid(); long callingId = Binder.clearCallingIdentity(); try { - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); int pkgUid = -1; synchronized(this) { try { @@ -5340,7 +5341,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen long callingId = Binder.clearCallingIdentity(); try { - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); int pkgUid = -1; synchronized(this) { try { @@ -5372,7 +5373,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen long callingId = Binder.clearCallingIdentity(); try { - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); int pkgUid = -1; synchronized(this) { try { @@ -5443,7 +5444,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen mWindowManager.closeSystemDialogs(reason); for (i=mHistory.size()-1; i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { finishActivityLocked(r, i, Activity.RESULT_CANCELED, null, "close-sys"); @@ -5546,7 +5547,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (uid < 0) { try { - uid = ActivityThread.getPackageManager().getPackageUid(name); + uid = AppGlobals.getPackageManager().getPackageUid(name); } catch (RemoteException e) { } } @@ -5567,7 +5568,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen callerWillRestart, doit); for (i=mHistory.size()-1; i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r.packageName.equals(name)) { if (!doit) { return true; @@ -5839,7 +5840,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen boolean didSomething = false; // See if the top visible activity is waiting to run in this process... - HistoryRecord hr = topRunningActivityLocked(null); + ActivityRecord hr = topRunningActivityLocked(null); if (hr != null && normalMode) { if (hr.app == null && app.info.uid == hr.info.applicationInfo.uid && processName.equals(hr.processName)) { @@ -5941,18 +5942,18 @@ public final class ActivityManagerService extends ActivityManagerNative implemen Binder.restoreCallingIdentity(origId); } - final ArrayList<HistoryRecord> processStoppingActivitiesLocked( + final ArrayList<ActivityRecord> processStoppingActivitiesLocked( boolean remove) { int N = mStoppingActivities.size(); if (N <= 0) return null; - ArrayList<HistoryRecord> stops = null; + ArrayList<ActivityRecord> stops = null; final boolean nowVisible = mResumedActivity != null && mResumedActivity.nowVisible && !mResumedActivity.waitingVisible; for (int i=0; i<N; i++) { - HistoryRecord s = mStoppingActivities.get(i); + ActivityRecord s = mStoppingActivities.get(i); if (localLOGV) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible + " waitingVisible=" + s.waitingVisible + " finishing=" + s.finishing); @@ -5972,7 +5973,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (!s.waitingVisible && remove) { if (localLOGV) Slog.v(TAG, "Ready to stop: " + s); if (stops == null) { - stops = new ArrayList<HistoryRecord>(); + stops = new ArrayList<ActivityRecord>(); } stops.add(s); mStoppingActivities.remove(i); @@ -5994,9 +5995,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen Configuration config) { if (localLOGV) Slog.v(TAG, "Activity idle: " + token); - ArrayList<HistoryRecord> stops = null; - ArrayList<HistoryRecord> finishes = null; - ArrayList<HistoryRecord> thumbnails = null; + ArrayList<ActivityRecord> stops = null; + ArrayList<ActivityRecord> finishes = null; + ArrayList<ActivityRecord> thumbnails = null; int NS = 0; int NF = 0; int NT = 0; @@ -6012,7 +6013,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Get the activity record. int index = indexOfTokenLocked(token); if (index >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); if (fromTimeout) { reportActivityLaunchedLocked(fromTimeout, r, -1, -1); @@ -6061,11 +6062,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen stops = processStoppingActivitiesLocked(true); NS = stops != null ? stops.size() : 0; if ((NF=mFinishingActivities.size()) > 0) { - finishes = new ArrayList<HistoryRecord>(mFinishingActivities); + finishes = new ArrayList<ActivityRecord>(mFinishingActivities); mFinishingActivities.clear(); } if ((NT=mCancelledThumbnails.size()) > 0) { - thumbnails = new ArrayList<HistoryRecord>(mCancelledThumbnails); + thumbnails = new ArrayList<ActivityRecord>(mCancelledThumbnails); mCancelledThumbnails.clear(); } @@ -6088,7 +6089,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Stop any activities that are scheduled to do so but have been // waiting for the next one to start. for (i=0; i<NS; i++) { - HistoryRecord r = (HistoryRecord)stops.get(i); + ActivityRecord r = (ActivityRecord)stops.get(i); synchronized (this) { if (r.finishing) { finishCurrentActivityLocked(r, FINISH_IMMEDIATELY); @@ -6101,7 +6102,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Finish any activities that are scheduled to do so but have been // waiting for the next one to start. for (i=0; i<NF; i++) { - HistoryRecord r = (HistoryRecord)finishes.get(i); + ActivityRecord r = (ActivityRecord)finishes.get(i); synchronized (this) { destroyActivityLocked(r, true); } @@ -6109,7 +6110,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Report back to any thumbnail receivers. for (i=0; i<NT; i++) { - HistoryRecord r = (HistoryRecord)thumbnails.get(i); + ActivityRecord r = (ActivityRecord)thumbnails.get(i); sendPendingThumbnail(r, null, null, null, true); } @@ -6203,12 +6204,12 @@ public final class ActivityManagerService extends ActivityManagerNative implemen TAG, "Activity paused: token=" + token + ", icicle=" + icicle + ", timeout=" + timeout); - HistoryRecord r = null; + ActivityRecord r = null; synchronized (this) { int index = indexOfTokenLocked(token); if (index >= 0) { - r = (HistoryRecord)mHistory.get(index); + r = (ActivityRecord)mHistory.get(index); if (!timeout) { r.icicle = icicle; r.haveState = true; @@ -6232,14 +6233,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (localLOGV) Slog.v( TAG, "Activity stopped: token=" + token); - HistoryRecord r = null; + ActivityRecord r = null; final long origId = Binder.clearCallingIdentity(); synchronized (this) { int index = indexOfTokenLocked(token); if (index >= 0) { - r = (HistoryRecord)mHistory.get(index); + r = (ActivityRecord)mHistory.get(index); r.thumbnail = thumbnail; r.description = description; r.stopped = true; @@ -6269,7 +6270,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen int index = indexOfTokenLocked(token); if (index >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); if (r.state == ActivityState.DESTROYING) { final long origId = Binder.clearCallingIdentity(); removeActivityFromHistoryLocked(r); @@ -6281,22 +6282,22 @@ public final class ActivityManagerService extends ActivityManagerNative implemen public String getCallingPackage(IBinder token) { synchronized (this) { - HistoryRecord r = getCallingRecordLocked(token); + ActivityRecord r = getCallingRecordLocked(token); return r != null && r.app != null ? r.info.packageName : null; } } public ComponentName getCallingActivity(IBinder token) { synchronized (this) { - HistoryRecord r = getCallingRecordLocked(token); + ActivityRecord r = getCallingRecordLocked(token); return r != null ? r.intent.getComponent() : null; } } - private HistoryRecord getCallingRecordLocked(IBinder token) { + private ActivityRecord getCallingRecordLocked(IBinder token) { int index = indexOfTokenLocked(token); if (index >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); if (r != null) { return r.resultTo; } @@ -6308,7 +6309,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen synchronized(this) { int index = indexOfTokenLocked(token); if (index >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); return r.intent.getComponent(); } return null; @@ -6319,7 +6320,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen synchronized(this) { int index = indexOfTokenLocked(token); if (index >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); return r.packageName; } return null; @@ -6346,7 +6347,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen try { if (callingUid != 0 && callingUid != Process.SYSTEM_UID && Process.supportsProcesses()) { - int uid = ActivityThread.getPackageManager() + int uid = AppGlobals.getPackageManager() .getPackageUid(packageName); if (uid != Binder.getCallingUid()) { String msg = "Permission Denial: getIntentSender() from pid=" @@ -6371,13 +6372,13 @@ public final class ActivityManagerService extends ActivityManagerNative implemen IIntentSender getIntentSenderLocked(int type, String packageName, int callingUid, IBinder token, String resultWho, int requestCode, Intent intent, String resolvedType, int flags) { - HistoryRecord activity = null; + ActivityRecord activity = null; if (type == INTENT_SENDER_ACTIVITY_RESULT) { int index = indexOfTokenLocked(token); if (index < 0) { return null; } - activity = (HistoryRecord)mHistory.get(index); + activity = (ActivityRecord)mHistory.get(index); if (activity.finishing) { return null; } @@ -6427,7 +6428,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen synchronized(this) { PendingIntentRecord rec = (PendingIntentRecord)sender; try { - int uid = ActivityThread.getPackageManager() + int uid = AppGlobals.getPackageManager() .getPackageUid(rec.key.packageName); if (uid != Binder.getCallingUid()) { String msg = "Permission Denial: cancelIntentSender() from pid=" @@ -6586,7 +6587,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return PackageManager.PERMISSION_GRANTED; } try { - return ActivityThread.getPackageManager() + return AppGlobals.getPackageManager() .checkUidPermission(permission, uid); } catch (RemoteException e) { // Should never happen, but if it does... deny! @@ -6695,7 +6696,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } private void grantUriPermissionLocked(int callingUid, - String targetPkg, Uri uri, int modeFlags, HistoryRecord activity) { + String targetPkg, Uri uri, int modeFlags, ActivityRecord activity) { modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (modeFlags == 0) { @@ -6705,7 +6706,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Requested grant " + targetPkg + " permission to " + uri); - final IPackageManager pm = ActivityThread.getPackageManager(); + final IPackageManager pm = AppGlobals.getPackageManager(); // If this is not a content: uri, we can't do anything with it. if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { @@ -6824,7 +6825,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } private void grantUriPermissionFromIntentLocked(int callingUid, - String targetPkg, Intent intent, HistoryRecord activity) { + String targetPkg, Intent intent, ActivityRecord activity) { if (intent == null) { return; } @@ -6875,7 +6876,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - private void removeActivityUriPermissionsLocked(HistoryRecord activity) { + private void removeActivityUriPermissionsLocked(ActivityRecord activity) { if (activity.readUriPermissions != null) { for (UriPermission perm : activity.readUriPermissions) { perm.readActivities.remove(activity); @@ -6909,7 +6910,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Revoking all granted permissions to " + uri); - final IPackageManager pm = ActivityThread.getPackageManager(); + final IPackageManager pm = AppGlobals.getPackageManager(); final String authority = uri.getAuthority(); ProviderInfo pi = null; @@ -7003,7 +7004,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return; } - final IPackageManager pm = ActivityThread.getPackageManager(); + final IPackageManager pm = AppGlobals.getPackageManager(); final String authority = uri.getAuthority(); ProviderInfo pi = null; @@ -7057,7 +7058,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen PendingThumbnailsRecord pending = null; IApplicationThread topThumbnail = null; - HistoryRecord topRecord = null; + ActivityRecord topRecord = null; synchronized(this) { if (localLOGV) Slog.v( @@ -7083,17 +7084,17 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } int pos = mHistory.size()-1; - HistoryRecord next = - pos >= 0 ? (HistoryRecord)mHistory.get(pos) : null; - HistoryRecord top = null; + ActivityRecord next = + pos >= 0 ? (ActivityRecord)mHistory.get(pos) : null; + ActivityRecord top = null; CharSequence topDescription = null; TaskRecord curTask = null; int numActivities = 0; int numRunning = 0; while (pos >= 0 && maxNum > 0) { - final HistoryRecord r = next; + final ActivityRecord r = next; pos--; - next = pos >= 0 ? (HistoryRecord)mHistory.get(pos) : null; + next = pos >= 0 ? (ActivityRecord)mHistory.get(pos) : null; // Initialize state for next task if needed. if (top == null || @@ -7195,7 +7196,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen enforceCallingPermission(android.Manifest.permission.GET_TASKS, "getRecentTasks()"); - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); final int N = mRecentTasks.size(); ArrayList<ActivityManager.RecentTaskInfo> res @@ -7242,12 +7243,12 @@ public final class ActivityManagerService extends ActivityManagerNative implemen private final int findAffinityTaskTopLocked(int startIndex, String affinity) { int j; - TaskRecord startTask = ((HistoryRecord)mHistory.get(startIndex)).task; + TaskRecord startTask = ((ActivityRecord)mHistory.get(startIndex)).task; TaskRecord jt = startTask; // First look backwards for (j=startIndex-1; j>=0; j--) { - HistoryRecord r = (HistoryRecord)mHistory.get(j); + ActivityRecord r = (ActivityRecord)mHistory.get(j); if (r.task != jt) { jt = r.task; if (affinity.equals(jt.affinity)) { @@ -7260,7 +7261,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen final int N = mHistory.size(); jt = startTask; for (j=startIndex+1; j<N; j++) { - HistoryRecord r = (HistoryRecord)mHistory.get(j); + ActivityRecord r = (ActivityRecord)mHistory.get(j); if (r.task != jt) { if (affinity.equals(jt.affinity)) { return j; @@ -7270,7 +7271,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } // Might it be at the top? - if (affinity.equals(((HistoryRecord)mHistory.get(N-1)).task.affinity)) { + if (affinity.equals(((ActivityRecord)mHistory.get(N-1)).task.affinity)) { return N-1; } @@ -7281,8 +7282,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * Perform a reset of the given task, if needed as part of launching it. * Returns the new HistoryRecord at the top of the task. */ - private final HistoryRecord resetTaskIfNeededLocked(HistoryRecord taskTop, - HistoryRecord newActivity) { + private final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, + ActivityRecord newActivity) { boolean forceReset = (newActivity.info.flags &ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; if (taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { @@ -7297,13 +7298,13 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // We are going to move through the history list so that we can look // at each activity 'target' with 'below' either the interesting // activity immediately below it in the stack or null. - HistoryRecord target = null; + ActivityRecord target = null; int targetI = 0; int taskTopI = -1; int replyChainEnd = -1; int lastReparentPos = -1; for (int i=mHistory.size()-1; i>=-1; i--) { - HistoryRecord below = i >= 0 ? (HistoryRecord)mHistory.get(i) : null; + ActivityRecord below = i >= 0 ? (ActivityRecord)mHistory.get(i) : null; if (below != null && below.finishing) { continue; @@ -7357,7 +7358,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // bottom of the activity stack. This also keeps it // correctly ordered with any activities we previously // moved. - HistoryRecord p = (HistoryRecord)mHistory.get(0); + ActivityRecord p = (ActivityRecord)mHistory.get(0); if (target.taskAffinity != null && target.taskAffinity.equals(p.task.affinity)) { // If the activity currently at the bottom has the @@ -7383,7 +7384,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } int dstPos = 0; for (int srcPos=targetI; srcPos<=replyChainEnd; srcPos++) { - p = (HistoryRecord)mHistory.get(srcPos); + p = (ActivityRecord)mHistory.get(srcPos); if (p.finishing) { continue; } @@ -7422,7 +7423,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // like these are all in the reply chain. replyChainEnd = targetI+1; while (replyChainEnd < mHistory.size() && - ((HistoryRecord)mHistory.get( + ((ActivityRecord)mHistory.get( replyChainEnd)).task == task) { replyChainEnd++; } @@ -7430,9 +7431,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } else if (replyChainEnd < 0) { replyChainEnd = targetI; } - HistoryRecord p = null; + ActivityRecord p = null; for (int srcPos=targetI; srcPos<=replyChainEnd; srcPos++) { - p = (HistoryRecord)mHistory.get(srcPos); + p = (ActivityRecord)mHistory.get(srcPos); if (p.finishing) { continue; } @@ -7490,9 +7491,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (replyChainEnd < 0) { replyChainEnd = targetI; } - HistoryRecord p = null; + ActivityRecord p = null; for (int srcPos=targetI; srcPos<=replyChainEnd; srcPos++) { - p = (HistoryRecord)mHistory.get(srcPos); + p = (ActivityRecord)mHistory.get(srcPos); if (p.finishing) { continue; } @@ -7510,7 +7511,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen replyChainEnd = targetI; } for (int srcPos=replyChainEnd; srcPos>=targetI; srcPos--) { - HistoryRecord p = (HistoryRecord)mHistory.get(srcPos); + ActivityRecord p = (ActivityRecord)mHistory.get(srcPos); if (p.finishing) { continue; } @@ -7541,7 +7542,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // below so it remains singleTop. if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { for (int j=lastReparentPos-1; j>=0; j--) { - HistoryRecord p = (HistoryRecord)mHistory.get(j); + ActivityRecord p = (ActivityRecord)mHistory.get(j); if (p.finishing) { continue; } @@ -7587,7 +7588,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } for (int i=mHistory.size()-1; i>=0; i--) { - HistoryRecord hr = (HistoryRecord)mHistory.get(i); + ActivityRecord hr = (ActivityRecord)mHistory.get(i); if (hr.task.taskId == task) { moveTaskToFrontLocked(hr.task, null); return; @@ -7599,13 +7600,13 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - private final void moveTaskToFrontLocked(TaskRecord tr, HistoryRecord reason) { + private final void moveTaskToFrontLocked(TaskRecord tr, ActivityRecord reason) { if (DEBUG_SWITCH) Slog.v(TAG, "moveTaskToFront: " + tr); final int task = tr.taskId; int top = mHistory.size()-1; - if (top < 0 || ((HistoryRecord)mHistory.get(top)).task.taskId == task) { + if (top < 0 || ((ActivityRecord)mHistory.get(top)).task.taskId == task) { // nothing to do! return; } @@ -7620,7 +7621,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Shift all activities with this task up to the top // of the stack, keeping them in the same internal order. while (pos >= 0) { - HistoryRecord r = (HistoryRecord)mHistory.get(pos); + ActivityRecord r = (ActivityRecord)mHistory.get(pos); if (localLOGV) Slog.v( TAG, "At " + pos + " ckp " + r.task + ": " + r); boolean first = true; @@ -7643,7 +7644,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (reason != null && (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { mWindowManager.prepareAppTransition(WindowManagerPolicy.TRANSIT_NONE); - HistoryRecord r = topRunningActivityLocked(null); + ActivityRecord r = topRunningActivityLocked(null); if (r != null) { mNoAnimActivities.add(r); } @@ -7713,14 +7714,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * @param task The taskId to collect and move to the bottom. * @return Returns true if the move completed, false if not. */ - private final boolean moveTaskToBackLocked(int task, HistoryRecord reason) { + private final boolean moveTaskToBackLocked(int task, ActivityRecord reason) { Slog.i(TAG, "moveTaskToBack: " + task); // If we have a watcher, preflight the move before committing to it. First check // for *other* available tasks, but if none are available, then try again allowing the // current task to be selected. if (mController != null) { - HistoryRecord next = topRunningActivityLocked(null, task); + ActivityRecord next = topRunningActivityLocked(null, task); if (next == null) { next = topRunningActivityLocked(null, 0); } @@ -7750,7 +7751,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Shift all activities with this task down to the bottom // of the stack, keeping them in the same internal order. while (pos < N) { - HistoryRecord r = (HistoryRecord)mHistory.get(pos); + ActivityRecord r = (ActivityRecord)mHistory.get(pos); if (localLOGV) Slog.v( TAG, "At " + pos + " ckp " + r.task + ": " + r); if (r.task.taskId == task) { @@ -7766,7 +7767,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (reason != null && (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { mWindowManager.prepareAppTransition(WindowManagerPolicy.TRANSIT_NONE); - HistoryRecord r = topRunningActivityLocked(null); + ActivityRecord r = topRunningActivityLocked(null); if (r != null) { mNoAnimActivities.add(r); } @@ -7811,7 +7812,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen final int N = mHistory.size(); TaskRecord lastTask = null; for (int i=0; i<N; i++) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r == token) { if (!onlyRoot || lastTask != r.task) { return r.task.taskId; @@ -7828,7 +7829,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * Returns the top activity in any existing task matching the given * Intent. Returns null if no such task is found. */ - private HistoryRecord findTaskLocked(Intent intent, ActivityInfo info) { + private ActivityRecord findTaskLocked(Intent intent, ActivityInfo info) { ComponentName cls = intent.getComponent(); if (info.targetActivity != null) { cls = new ComponentName(info.packageName, info.targetActivity); @@ -7838,7 +7839,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen final int N = mHistory.size(); for (int i=(N-1); i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (!r.finishing && r.task != cp && r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE) { cp = r.task; @@ -7874,7 +7875,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * is the same as the given activity. Returns null if no such activity * is found. */ - private HistoryRecord findActivityLocked(Intent intent, ActivityInfo info) { + private ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { ComponentName cls = intent.getComponent(); if (info.targetActivity != null) { cls = new ComponentName(info.packageName, info.targetActivity); @@ -7882,7 +7883,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen final int N = mHistory.size(); for (int i=(N-1); i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (!r.finishing) { if (r.intent.getComponent().equals(cls)) { //Slog.i(TAG, "Found matching class!"); @@ -7903,7 +7904,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen int N = mHistory.size(); TaskRecord lastTask = null; for (int i=0; i<N; i++) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r.realActivity.equals(className) && r != token && lastTask != r.task) { if (finishActivityLocked(r, i, Activity.RESULT_CANCELED, @@ -7931,7 +7932,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen Binder.restoreCallingIdentity(origId); } - final void sendPendingThumbnail(HistoryRecord r, IBinder token, + final void sendPendingThumbnail(ActivityRecord r, IBinder token, Bitmap thumbnail, CharSequence description, boolean always) { TaskRecord task = null; ArrayList receivers = null; @@ -7944,7 +7945,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { return; } - r = (HistoryRecord)mHistory.get(index); + r = (ActivityRecord)mHistory.get(index); } if (thumbnail == null) { thumbnail = r.thumbnail; @@ -8005,7 +8006,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen private final List generateApplicationProvidersLocked(ProcessRecord app) { List providers = null; try { - providers = ActivityThread.getPackageManager(). + providers = AppGlobals.getPackageManager(). queryContentProviders(app.processName, app.info.uid, STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS); } catch (RemoteException ex) { @@ -8147,7 +8148,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } else { try { - cpi = ActivityThread.getPackageManager(). + cpi = AppGlobals.getPackageManager(). resolveContentProvider(name, STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS); } catch (RemoteException ex) { @@ -8176,7 +8177,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (firstClass) { try { ApplicationInfo ai = - ActivityThread.getPackageManager(). + AppGlobals.getPackageManager(). getApplicationInfo( cpi.applicationInfo.packageName, STOCK_PM_FLAGS); @@ -8481,7 +8482,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen TAG, "Performing unhandledBack(): stack size = " + count); if (count > 1) { final long origId = Binder.clearCallingIdentity(); - finishActivityLocked((HistoryRecord)mHistory.get(count-1), + finishActivityLocked((ActivityRecord)mHistory.get(count-1), count-1, Activity.RESULT_CANCELED, null, "unhandled-back"); Binder.restoreCallingIdentity(origId); } @@ -8731,7 +8732,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { throw new IllegalArgumentException(); } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); r.immersive = immersive; } } @@ -8742,14 +8743,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (index < 0) { throw new IllegalArgumentException(); } - HistoryRecord r = (HistoryRecord)mHistory.get(index); + ActivityRecord r = (ActivityRecord)mHistory.get(index); return r.immersive; } } public boolean isTopActivityImmersive() { synchronized (this) { - HistoryRecord r = topRunningActivityLocked(null); + ActivityRecord r = topRunningActivityLocked(null); return (r != null) ? r.immersive : false; } } @@ -8760,7 +8761,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // and started launching other packages. if (!mSystemReady) { try { - ActivityThread.getPackageManager().enterSafeMode(); + AppGlobals.getPackageManager().enterSafeMode(); } catch (RemoteException e) { } @@ -9033,7 +9034,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen Intent intent = new Intent(Intent.ACTION_PRE_BOOT_COMPLETED); List<ResolveInfo> ris = null; try { - ris = ActivityThread.getPackageManager().queryIntentReceivers( + ris = AppGlobals.getPackageManager().queryIntentReceivers( intent, null, 0); } catch (RemoteException e) { } @@ -9152,7 +9153,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen synchronized (this) { if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { try { - List apps = ActivityThread.getPackageManager(). + List apps = AppGlobals.getPackageManager(). getPersistentApplications(STOCK_PM_FLAGS); if (apps != null) { int N = apps.size(); @@ -9175,7 +9176,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen mBooting = true; try { - if (ActivityThread.getPackageManager().hasSystemUidErrors()) { + if (AppGlobals.getPackageManager().hasSystemUidErrors()) { Message msg = Message.obtain(); msg.what = SHOW_UID_ERROR_MSG; mHandler.sendMessage(msg); @@ -9272,7 +9273,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen app.info.processName, app.info.uid); killServicesLocked(app, false); for (int i=mHistory.size()-1; i>=0; i--) { - HistoryRecord r = (HistoryRecord)mHistory.get(i); + ActivityRecord r = (ActivityRecord)mHistory.get(i); if (r.app == app) { Slog.w(TAG, " Force finishing activity " + r.intent.getComponent().flattenToShortString()); @@ -9294,7 +9295,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return false; } } else { - HistoryRecord r = topRunningActivityLocked(null); + ActivityRecord r = topRunningActivityLocked(null); if (r.app == app) { // If the top running activity is from this crashing // process, then terminate it to avoid getting in a loop. @@ -9308,7 +9309,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // re-start our crashing activity once it gets resumed again. index--; if (index >= 0) { - r = (HistoryRecord)mHistory.get(index); + r = (ActivityRecord)mHistory.get(index); if (r.state == ActivityState.RESUMED || r.state == ActivityState.PAUSING || r.state == ActivityState.PAUSED) { @@ -9506,7 +9507,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * @param crashInfo giving an application stack trace, null if absent */ public void addErrorToDropBox(String eventType, - ProcessRecord process, HistoryRecord activity, HistoryRecord parent, String subject, + ProcessRecord process, ActivityRecord activity, ActivityRecord parent, String subject, final String report, final File logFile, final ApplicationErrorReport.CrashInfo crashInfo) { // NOTE -- this must never acquire the ActivityManagerService lock, @@ -9536,7 +9537,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } if (process != null) { int flags = process.info.flags; - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); sb.append("Flags: 0x").append(Integer.toString(flags, 16)).append("\n"); for (String pkg : process.pkgList) { sb.append("Package: ").append(pkg); @@ -9840,8 +9841,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen currApp.importanceReasonCode = app.adjTypeCode; if (app.adjSource instanceof ProcessRecord) { currApp.importanceReasonPid = ((ProcessRecord)app.adjSource).pid; - } else if (app.adjSource instanceof HistoryRecord) { - HistoryRecord r = (HistoryRecord)app.adjSource; + } else if (app.adjSource instanceof ActivityRecord) { + ActivityRecord r = (ActivityRecord)app.adjSource; if (r.app != null) currApp.importanceReasonPid = r.app.pid; } if (app.adjTarget instanceof ComponentName) { @@ -9871,7 +9872,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } } - IPackageManager pm = ActivityThread.getPackageManager(); + IPackageManager pm = AppGlobals.getPackageManager(); for (String pkg : extList) { try { ApplicationInfo info = pm.getApplicationInfo(pkg, 0); @@ -10558,7 +10559,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen String prefix, String label, boolean complete) { TaskRecord lastTask = null; for (int i=list.size()-1; i>=0; i--) { - HistoryRecord r = (HistoryRecord)list.get(i); + ActivityRecord r = (ActivityRecord)list.get(i); final boolean full = complete || !r.inHistory; if (lastTask != r.task) { lastTask = r.task; @@ -11186,7 +11187,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (r == null) { try { ResolveInfo rInfo = - ActivityThread.getPackageManager().resolveService( + AppGlobals.getPackageManager().resolveService( service, resolvedType, 0); ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null; @@ -11243,7 +11244,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (r == null) { try { ResolveInfo rInfo = - ActivityThread.getPackageManager().resolveService( + AppGlobals.getPackageManager().resolveService( service, resolvedType, STOCK_PM_FLAGS); ServiceInfo sInfo = rInfo != null ? rInfo.serviceInfo : null; @@ -12014,14 +12015,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen + ") when binding service " + service); } - HistoryRecord activity = null; + ActivityRecord activity = null; if (token != null) { int aindex = indexOfTokenLocked(token); if (aindex < 0) { Slog.w(TAG, "Binding with unknown activity: " + token); return 0; } - activity = (HistoryRecord)mHistory.get(aindex); + activity = (ActivityRecord)mHistory.get(aindex); } int clientLabel = 0; @@ -12126,7 +12127,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } private void removeConnectionLocked( - ConnectionRecord c, ProcessRecord skipApp, HistoryRecord skipAct) { + ConnectionRecord c, ProcessRecord skipApp, ActivityRecord skipAct) { IBinder binder = c.conn.asBinder(); AppBindRecord b = c.binding; ServiceRecord s = b.service; @@ -12807,7 +12808,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen // Always okay. } else if (callerApp == null || !callerApp.persistent) { try { - if (ActivityThread.getPackageManager().isProtectedBroadcast( + if (AppGlobals.getPackageManager().isProtectedBroadcast( intent.getAction())) { String msg = "Permission Denial: not allowed to send broadcast " + intent.getAction() + " from pid=" @@ -12866,7 +12867,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen try { if (intent.getComponent() != null) { // Broadcast is going to one specific receiver class... - ActivityInfo ai = ActivityThread.getPackageManager(). + ActivityInfo ai = AppGlobals.getPackageManager(). getReceiverInfo(intent.getComponent(), STOCK_PM_FLAGS); if (ai != null) { receivers = new ArrayList(); @@ -12879,7 +12880,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if ((intent.getFlags()&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) { receivers = - ActivityThread.getPackageManager().queryIntentReceivers( + AppGlobals.getPackageManager().queryIntentReceivers( intent, resolvedType, STOCK_PM_FLAGS); } registeredReceivers = mReceiverResolver.queryIntent(intent, resolvedType, false); @@ -13631,7 +13632,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (r.callingUid != Process.SYSTEM_UID && r.requiredPermission != null) { try { - perm = ActivityThread.getPackageManager(). + perm = AppGlobals.getPackageManager(). checkPermission(r.requiredPermission, info.activityInfo.applicationInfo.packageName); } catch (RemoteException e) { @@ -13888,7 +13889,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * configuration. */ public boolean updateConfigurationLocked(Configuration values, - HistoryRecord starting) { + ActivityRecord starting) { int changes = 0; boolean kept = true; @@ -13979,7 +13980,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return kept; } - private final boolean relaunchActivityLocked(HistoryRecord r, + private final boolean relaunchActivityLocked(ActivityRecord r, int changes, boolean andResume) { List<ResultInfo> results = null; List<Intent> newIntents = null; @@ -14023,7 +14024,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * for whatever reason. Ensures the HistoryRecord is updated with the * correct configuration and all other bookkeeping is handled. */ - private final boolean ensureActivityConfigurationLocked(HistoryRecord r, + private final boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges) { if (mConfigWillChange) { if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, @@ -14357,7 +14358,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } } - HistoryRecord a = cr.activity; + ActivityRecord a = cr.activity; //if (a != null) { // Slog.i(TAG, "Connection to " + a ": state=" + a.state); //} @@ -14658,8 +14659,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen return true; } - private final HistoryRecord resumedAppLocked() { - HistoryRecord resumedActivity = mResumedActivity; + private final ActivityRecord resumedAppLocked() { + ActivityRecord resumedActivity = mResumedActivity; if (resumedActivity == null || resumedActivity.app == null) { resumedActivity = mPausingActivity; if (resumedActivity == null || resumedActivity.app == null) { @@ -14670,7 +14671,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } private final boolean updateOomAdjLocked(ProcessRecord app) { - final HistoryRecord TOP_ACT = resumedAppLocked(); + final ActivityRecord TOP_ACT = resumedAppLocked(); final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null; int curAdj = app.curAdj; final boolean wasHidden = app.curAdj >= HIDDEN_APP_MIN_ADJ @@ -14693,7 +14694,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen private final boolean updateOomAdjLocked() { boolean didOomAdj = true; - final HistoryRecord TOP_ACT = resumedAppLocked(); + final ActivityRecord TOP_ACT = resumedAppLocked(); final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null; if (false) { @@ -14875,7 +14876,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (Config.LOGV) Slog.v( TAG, "Looking to quit " + app.processName); for (j=0; j<NUMA && canQuit; j++) { - HistoryRecord r = app.activities.get(j); + ActivityRecord r = app.activities.get(j); if (Config.LOGV) Slog.v( TAG, " " + r.intent.getComponent().flattenToShortString() + ": frozen=" + r.haveState + ", visible=" + r.visible); @@ -14885,7 +14886,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (canQuit) { // Finish all of the activities, and then the app itself. for (j=0; j<NUMA; j++) { - HistoryRecord r = app.activities.get(j); + ActivityRecord r = app.activities.get(j); if (!r.finishing) { destroyActivityLocked(r, false); } @@ -14927,8 +14928,8 @@ public final class ActivityManagerService extends ActivityManagerNative implemen i<mLRUActivities.size() && mLRUActivities.size() > curMaxActivities; i++) { - final HistoryRecord r - = (HistoryRecord)mLRUActivities.get(i); + final ActivityRecord r + = (ActivityRecord)mLRUActivities.get(i); // We can finish this one if we have its icicle saved and // it is not persistent. diff --git a/services/java/com/android/server/am/HistoryRecord.java b/services/java/com/android/server/am/ActivityRecord.java index fb5c8aa..22ac58d 100644 --- a/services/java/com/android/server/am/HistoryRecord.java +++ b/services/java/com/android/server/am/ActivityRecord.java @@ -42,7 +42,7 @@ import java.util.HashSet; /** * An entry in the history stack, representing an activity. */ -class HistoryRecord extends IApplicationToken.Stub { +class ActivityRecord extends IApplicationToken.Stub { final ActivityManagerService service; // owner final ActivityInfo info; // all about me final int launchedFromUid; // always the uid who started the activity. @@ -68,7 +68,7 @@ class HistoryRecord extends IApplicationToken.Stub { long startTime; // when we starting launching this activity long cpuTimeAtResume; // the cpu time of host process at the time of resuming activity Configuration configuration; // configuration activity was last running in - HistoryRecord resultTo; // who started this entry, so will get our reply + ActivityRecord resultTo; // who started this entry, so will get our reply final String resultWho; // additional identifier for use by resultTo. final int requestCode; // code given by requester (resultTo) ArrayList results; // pending ActivityResult objs we have received @@ -175,10 +175,10 @@ class HistoryRecord extends IApplicationToken.Stub { } } - HistoryRecord(ActivityManagerService _service, ProcessRecord _caller, + ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromUid, Intent _intent, String _resolvedType, ActivityInfo aInfo, Configuration _configuration, - HistoryRecord _resultTo, String _resultWho, int _reqCode, + ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified) { service = _service; info = aInfo; @@ -297,7 +297,7 @@ class HistoryRecord extends IApplicationToken.Stub { } } - void addResultLocked(HistoryRecord from, String resultWho, + void addResultLocked(ActivityRecord from, String resultWho, int requestCode, int resultCode, Intent resultData) { ActivityResult r = new ActivityResult(from, resultWho, @@ -308,7 +308,7 @@ class HistoryRecord extends IApplicationToken.Stub { results.add(r); } - void removeResultsLocked(HistoryRecord from, String resultWho, + void removeResultsLocked(ActivityRecord from, String resultWho, int requestCode) { if (results != null) { for (int i=results.size()-1; i>=0; i--) { @@ -418,7 +418,7 @@ class HistoryRecord extends IApplicationToken.Stub { final int N = service.mWaitingVisibleActivities.size(); if (N > 0) { for (int i=0; i<N; i++) { - HistoryRecord r = (HistoryRecord) + ActivityRecord r = (ActivityRecord) service.mWaitingVisibleActivities.get(i); r.waitingVisible = false; if (ActivityManagerService.DEBUG_SWITCH) Log.v( @@ -442,11 +442,11 @@ class HistoryRecord extends IApplicationToken.Stub { nowVisible = false; } - private HistoryRecord getWaitingHistoryRecordLocked() { + private ActivityRecord getWaitingHistoryRecordLocked() { // First find the real culprit... if we are waiting // for another app to start, then we have paused dispatching // for this activity. - HistoryRecord r = this; + ActivityRecord r = this; if (r.waitingVisible) { // Hmmm, who might we be waiting for? r = service.mResumedActivity; @@ -463,7 +463,7 @@ class HistoryRecord extends IApplicationToken.Stub { } public boolean keyDispatchingTimedOut() { - HistoryRecord r; + ActivityRecord r; ProcessRecord anrApp = null; synchronized(service) { r = getWaitingHistoryRecordLocked(); @@ -501,7 +501,7 @@ class HistoryRecord extends IApplicationToken.Stub { /** Returns the key dispatching timeout for this application token. */ public long getKeyDispatchingTimeout() { synchronized(service) { - HistoryRecord r = getWaitingHistoryRecordLocked(); + ActivityRecord r = getWaitingHistoryRecordLocked(); if (r == null || r.app == null || r.app.instrumentationClass == null) { return ActivityManagerService.KEY_DISPATCHING_TIMEOUT; diff --git a/services/java/com/android/server/am/ActivityResult.java b/services/java/com/android/server/am/ActivityResult.java index 3cc2725..12eba34 100644 --- a/services/java/com/android/server/am/ActivityResult.java +++ b/services/java/com/android/server/am/ActivityResult.java @@ -24,9 +24,9 @@ import android.os.Bundle; * Pending result information to send back to an activity. */ class ActivityResult extends ResultInfo { - final HistoryRecord mFrom; + final ActivityRecord mFrom; - public ActivityResult(HistoryRecord from, String resultWho, + public ActivityResult(ActivityRecord from, String resultWho, int requestCode, int resultCode, Intent data) { super(resultWho, requestCode, resultCode, data); mFrom = from; diff --git a/services/java/com/android/server/am/AppNotRespondingDialog.java b/services/java/com/android/server/am/AppNotRespondingDialog.java index 9702f91..b2737dc 100644 --- a/services/java/com/android/server/am/AppNotRespondingDialog.java +++ b/services/java/com/android/server/am/AppNotRespondingDialog.java @@ -40,7 +40,7 @@ class AppNotRespondingDialog extends BaseErrorDialog { private final ProcessRecord mProc; public AppNotRespondingDialog(ActivityManagerService service, Context context, - ProcessRecord app, HistoryRecord activity) { + ProcessRecord app, ActivityRecord activity) { super(context); mService = service; diff --git a/services/java/com/android/server/am/ConnectionRecord.java b/services/java/com/android/server/am/ConnectionRecord.java index f613b00..22acda9 100644 --- a/services/java/com/android/server/am/ConnectionRecord.java +++ b/services/java/com/android/server/am/ConnectionRecord.java @@ -26,7 +26,7 @@ import java.io.PrintWriter; */ class ConnectionRecord { final AppBindRecord binding; // The application/service binding. - final HistoryRecord activity; // If non-null, the owning activity. + final ActivityRecord activity; // If non-null, the owning activity. final IServiceConnection conn; // The client connection. final int flags; // Binding options. final int clientLabel; // String resource labeling this client. @@ -42,7 +42,7 @@ class ConnectionRecord { + " flags=0x" + Integer.toHexString(flags)); } - ConnectionRecord(AppBindRecord _binding, HistoryRecord _activity, + ConnectionRecord(AppBindRecord _binding, ActivityRecord _activity, IServiceConnection _conn, int _flags, int _clientLabel, PendingIntent _clientIntent) { binding = _binding; diff --git a/services/java/com/android/server/am/PendingIntentRecord.java b/services/java/com/android/server/am/PendingIntentRecord.java index 847e91b..e7e9130 100644 --- a/services/java/com/android/server/am/PendingIntentRecord.java +++ b/services/java/com/android/server/am/PendingIntentRecord.java @@ -42,7 +42,7 @@ class PendingIntentRecord extends IIntentSender.Stub { final static class Key { final int type; final String packageName; - final HistoryRecord activity; + final ActivityRecord activity; final String who; final int requestCode; final Intent requestIntent; @@ -52,7 +52,7 @@ class PendingIntentRecord extends IIntentSender.Stub { private static final int ODD_PRIME_NUMBER = 37; - Key(int _t, String _p, HistoryRecord _a, String _w, + Key(int _t, String _p, ActivityRecord _a, String _w, int _r, Intent _i, String _it, int _f) { type = _t; packageName = _p; diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/java/com/android/server/am/ProcessRecord.java index 9dda1df..18fd9d6 100644 --- a/services/java/com/android/server/am/ProcessRecord.java +++ b/services/java/com/android/server/am/ProcessRecord.java @@ -86,7 +86,7 @@ class ProcessRecord implements Watchdog.PssRequestor { Object adjTarget; // Debugging: target component impacting oom_adj. // contains HistoryRecord objects - final ArrayList<HistoryRecord> activities = new ArrayList<HistoryRecord>(); + final ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); // all ServiceRecord running in this process final HashSet<ServiceRecord> services = new HashSet<ServiceRecord>(); // services that are currently executing code (need to remain foreground). @@ -248,7 +248,7 @@ class ProcessRecord implements Watchdog.PssRequestor { public boolean isInterestingToUserLocked() { final int size = activities.size(); for (int i = 0 ; i < size ; i++) { - HistoryRecord r = activities.get(i); + ActivityRecord r = activities.get(i); if (r.isInterestingToUserLocked()) { return true; } diff --git a/services/java/com/android/server/am/UriPermission.java b/services/java/com/android/server/am/UriPermission.java index ffa8a2a..81450c5 100644 --- a/services/java/com/android/server/am/UriPermission.java +++ b/services/java/com/android/server/am/UriPermission.java @@ -27,8 +27,8 @@ class UriPermission { final Uri uri; int modeFlags = 0; int globalModeFlags = 0; - final HashSet<HistoryRecord> readActivities = new HashSet<HistoryRecord>(); - final HashSet<HistoryRecord> writeActivities = new HashSet<HistoryRecord>(); + final HashSet<ActivityRecord> readActivities = new HashSet<ActivityRecord>(); + final HashSet<ActivityRecord> writeActivities = new HashSet<ActivityRecord>(); String stringName; @@ -42,7 +42,7 @@ class UriPermission { globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION; modeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION; if (readActivities.size() > 0) { - for (HistoryRecord r : readActivities) { + for (ActivityRecord r : readActivities) { r.readUriPermissions.remove(this); if (r.readUriPermissions.size() == 0) { r.readUriPermissions = null; @@ -55,7 +55,7 @@ class UriPermission { globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION; modeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION; if (readActivities.size() > 0) { - for (HistoryRecord r : readActivities) { + for (ActivityRecord r : readActivities) { r.writeUriPermissions.remove(this); if (r.writeUriPermissions.size() == 0) { r.writeUriPermissions = null; |