diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 222ad69c61e29..d9f9d61886d79 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -69,6 +69,7 @@ import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.util.AndroidRuntimeException; +import android.util.ArrayMap; import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; @@ -103,8 +104,6 @@ import java.lang.ref.WeakReference; import java.net.InetAddress; import java.security.Security; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -164,15 +163,15 @@ public final class ActivityThread { final ApplicationThread mAppThread = new ApplicationThread(); final Looper mLooper = Looper.myLooper(); final H mH = new H(); - final HashMap mActivities - = new HashMap(); + final ArrayMap mActivities + = new ArrayMap(); // 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 mServices - = new HashMap(); + final ArrayMap mServices + = new ArrayMap(); AppBindData mBoundApplication; Profiler mProfiler; int mCurDefaultDisplayDpi; @@ -183,7 +182,7 @@ public final class ActivityThread { final ArrayList mAllApplications = new ArrayList(); // set of instantiated backup agents, keyed by package name - final HashMap mBackupAgents = new HashMap(); + final ArrayMap mBackupAgents = new ArrayMap(); /** Reference to singleton {@link ActivityThread} */ private static ActivityThread sCurrentActivityThread; Instrumentation mInstrumentation; @@ -203,10 +202,10 @@ public final class ActivityThread { // which means this lock gets held while the activity and window managers // holds their own lock. Thus you MUST NEVER call back into the activity manager // or window manager or anything that depends on them while holding this lock. - final HashMap> mPackages - = new HashMap>(); - final HashMap> mResourcePackages - = new HashMap>(); + final ArrayMap> mPackages + = new ArrayMap>(); + final ArrayMap> mResourcePackages + = new ArrayMap>(); final ArrayList mRelaunchingActivities = new ArrayList(); Configuration mPendingConfiguration = null; @@ -238,17 +237,17 @@ public final class ActivityThread { } // The lock of mProviderMap protects the following variables. - final HashMap mProviderMap - = new HashMap(); - final HashMap mProviderRefCountMap - = new HashMap(); - final HashMap mLocalProviders - = new HashMap(); - final HashMap mLocalProvidersByName - = new HashMap(); + final ArrayMap mProviderMap + = new ArrayMap(); + final ArrayMap mProviderRefCountMap + = new ArrayMap(); + final ArrayMap mLocalProviders + = new ArrayMap(); + final ArrayMap mLocalProvidersByName + = new ArrayMap(); - final HashMap> mOnPauseListeners - = new HashMap>(); + final ArrayMap> mOnPauseListeners + = new ArrayMap>(); final GcIdler mGcIdler = new GcIdler(); boolean mGcIdlerScheduled = false; @@ -3702,47 +3701,45 @@ public final class ActivityThread { = new ArrayList(); synchronized (mResourcesManager) { - final int N = mAllApplications.size(); - for (int i=0; i 0) { - for (ActivityClientRecord ar : mActivities.values()) { - Activity a = ar.activity; - if (a != null) { - Configuration thisConfig = applyConfigCompatMainThread( - mCurDefaultDisplayDpi, newConfig, - ar.packageInfo.getCompatibilityInfo()); - if (!ar.activity.mFinished && (allActivities || !ar.paused)) { - // If the activity is currently resumed, its configuration - // needs to change right now. - callbacks.add(a); - } else if (thisConfig != null) { - // Otherwise, we will tell it about the change - // the next time it is resumed or shown. Note that - // the activity manager may, before then, decide the - // activity needs to be destroyed to handle its new - // configuration. - if (DEBUG_CONFIGURATION) { - Slog.v(TAG, "Setting activity " - + ar.activityInfo.name + " newConfig=" + thisConfig); - } - ar.newConfig = thisConfig; + final int NACT = mActivities.size(); + for (int i=0; i=0; i--) { + ResourceName nm = sIconCache.keyAt(i); + if (nm.packageName.equals(ssp)) { + //Log.i(TAG, "Removing cached drawable for " + nm); + sIconCache.removeAt(i); + needCleanup = true; } } - if (sStringCache.size() > 0) { - Iterator it = sStringCache.keySet().iterator(); - while (it.hasNext()) { - ResourceName nm = it.next(); - if (nm.packageName.equals(ssp)) { - //Log.i(TAG, "Removing cached string for " + nm); - it.remove(); - needCleanup = true; - } + for (int i=sStringCache.size()-1; i>=0; i--) { + ResourceName nm = sStringCache.keyAt(i); + if (nm.packageName.equals(ssp)) { + //Log.i(TAG, "Removing cached string for " + nm); + sStringCache.removeAt(i); + needCleanup = true; } } } @@ -1335,8 +1330,8 @@ final class ApplicationPackageManager extends PackageManager { private final IPackageManager mPM; private static final Object sSync = new Object(); - private static HashMap> sIconCache - = new HashMap>(); - private static HashMap> sStringCache - = new HashMap>(); + private static ArrayMap> sIconCache + = new ArrayMap>(); + private static ArrayMap> sStringCache + = new ArrayMap>(); } diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index 05d3a47ee98be..4239a5d8d0b76 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -16,6 +16,7 @@ package android.app; +import android.util.ArrayMap; import com.android.internal.util.ArrayUtils; import android.content.BroadcastReceiver; @@ -49,8 +50,6 @@ 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) { @@ -89,14 +88,14 @@ public final class LoadedApk { private ClassLoader mClassLoader; private Application mApplication; - private final HashMap> mReceivers - = new HashMap>(); - private final HashMap> mUnregisteredReceivers - = new HashMap>(); - private final HashMap> mServices - = new HashMap>(); - private final HashMap> mUnboundServices - = new HashMap>(); + private final ArrayMap> mReceivers + = new ArrayMap>(); + private final ArrayMap> mUnregisteredReceivers + = new ArrayMap>(); + private final ArrayMap> mServices + = new ArrayMap>(); + private final ArrayMap> mUnboundServices + = new ArrayMap>(); int mClientCount = 0; @@ -540,12 +539,11 @@ public final class LoadedApk { public void removeContextRegistrations(Context context, String who, String what) { final boolean reportRegistrationLeaks = StrictMode.vmRegistrationLeaksEnabled(); - HashMap rmap = - mReceivers.remove(context); + ArrayMap rmap = + mReceivers.remove(context); if (rmap != null) { - Iterator it = rmap.values().iterator(); - while (it.hasNext()) { - LoadedApk.ReceiverDispatcher rd = it.next(); + for (int i=0; i smap = + ArrayMap smap = mServices.remove(context); if (smap != null) { - Iterator it = smap.values().iterator(); - while (it.hasNext()) { - LoadedApk.ServiceDispatcher sd = it.next(); + for (int i=0; i map = null; + ArrayMap map = null; if (registered) { map = mReceivers.get(context); if (map != null) { @@ -610,7 +607,7 @@ public final class LoadedApk { instrumentation, registered); if (registered) { if (map == null) { - map = new HashMap(); + map = new ArrayMap(); mReceivers.put(context, map); } map.put(r, rd); @@ -626,7 +623,7 @@ public final class LoadedApk { public IIntentReceiver forgetReceiverDispatcher(Context context, BroadcastReceiver r) { synchronized (mReceivers) { - HashMap map = mReceivers.get(context); + ArrayMap map = mReceivers.get(context); LoadedApk.ReceiverDispatcher rd = null; if (map != null) { rd = map.get(r); @@ -636,10 +633,10 @@ public final class LoadedApk { mReceivers.remove(context); } if (r.getDebugUnregister()) { - HashMap holder + ArrayMap holder = mUnregisteredReceivers.get(context); if (holder == null) { - holder = new HashMap(); + holder = new ArrayMap(); mUnregisteredReceivers.put(context, holder); } RuntimeException ex = new IllegalArgumentException( @@ -652,7 +649,7 @@ public final class LoadedApk { return rd.getIIntentReceiver(); } } - HashMap holder + ArrayMap holder = mUnregisteredReceivers.get(context); if (holder != null) { rd = holder.get(r); @@ -868,14 +865,14 @@ public final class LoadedApk { Context context, Handler handler, int flags) { synchronized (mServices) { LoadedApk.ServiceDispatcher sd = null; - HashMap map = mServices.get(context); + ArrayMap 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(); + map = new ArrayMap(); mServices.put(context, map); } map.put(c, sd); @@ -889,7 +886,7 @@ public final class LoadedApk { public final IServiceConnection forgetServiceDispatcher(Context context, ServiceConnection c) { synchronized (mServices) { - HashMap map + ArrayMap map = mServices.get(context); LoadedApk.ServiceDispatcher sd = null; if (map != null) { @@ -901,10 +898,10 @@ public final class LoadedApk { mServices.remove(context); } if ((sd.getFlags()&Context.BIND_DEBUG_UNBIND) != 0) { - HashMap holder + ArrayMap holder = mUnboundServices.get(context); if (holder == null) { - holder = new HashMap(); + holder = new ArrayMap(); mUnboundServices.put(context, holder); } RuntimeException ex = new IllegalArgumentException( @@ -916,7 +913,7 @@ public final class LoadedApk { return sd.getIServiceConnection(); } } - HashMap holder + ArrayMap holder = mUnboundServices.get(context); if (holder != null) { sd = holder.get(c); @@ -969,8 +966,8 @@ public final class LoadedApk { } } - private final HashMap mActiveConnections - = new HashMap(); + private final ArrayMap mActiveConnections + = new ArrayMap(); ServiceDispatcher(ServiceConnection conn, Context context, Handler activityThread, int flags) { @@ -1000,9 +997,8 @@ public final class LoadedApk { void doForget() { synchronized(this) { - Iterator it = mActiveConnections.values().iterator(); - while (it.hasNext()) { - ServiceDispatcher.ConnectionInfo ci = it.next(); + for (int i=0; i > mActiveResources - = new HashMap >(); + final ArrayMap > mActiveResources + = new ArrayMap >(); final ArrayMap mDefaultDisplayMetrics = new ArrayMap(); @@ -257,19 +253,16 @@ public class ResourcesManager { Configuration tmpConfig = null; - Iterator>> it = - mActiveResources.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry> entry = it.next(); - Resources r = entry.getValue().get(); + for (int i=mActiveResources.size()-1; i>=0; i--) { + ResourcesKey key = mActiveResources.keyAt(i); + Resources r = mActiveResources.valueAt(i).get(); if (r != null) { if (DEBUG_CONFIGURATION) Slog.v(TAG, "Changing resources " + r + " config to: " + config); - int displayId = entry.getKey().mDisplayId; + int displayId = key.mDisplayId; boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY); DisplayMetrics dm = defaultDisplayMetrics; - ResourcesKey resourcesKey = entry.getKey(); - final boolean hasOverrideConfiguration = resourcesKey.hasOverrideConfiguration(); + final boolean hasOverrideConfiguration = key.hasOverrideConfiguration(); if (!isDefaultDisplay || hasOverrideConfiguration) { if (tmpConfig == null) { tmpConfig = new Configuration(); @@ -280,7 +273,7 @@ public class ResourcesManager { applyNonDefaultDisplayMetricsToConfigurationLocked(dm, tmpConfig); } if (hasOverrideConfiguration) { - tmpConfig.updateFrom(resourcesKey.mOverrideConfiguration); + tmpConfig.updateFrom(key.mOverrideConfiguration); } r.updateConfiguration(tmpConfig, dm, compat); } else { @@ -290,7 +283,7 @@ public class ResourcesManager { // + " " + r + ": " + r.getConfiguration()); } else { //Slog.i(TAG, "Removing old resources " + v.getKey()); - it.remove(); + mActiveResources.removeAt(i); } } diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 62c8d58c9dcb1..a954f59720d6f 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -16,6 +16,7 @@ package android.content; +import android.util.ArraySet; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -42,7 +43,6 @@ import java.io.IOException; import java.io.Serializable; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.Locale; import java.util.Set; @@ -3609,7 +3609,7 @@ public class Intent implements Parcelable, Cloneable { private String mPackage; private ComponentName mComponent; private int mFlags; - private HashSet mCategories; + private ArraySet mCategories; private Bundle mExtras; private Rect mSourceBounds; private Intent mSelector; @@ -3634,7 +3634,7 @@ public class Intent implements Parcelable, Cloneable { this.mComponent = o.mComponent; this.mFlags = o.mFlags; if (o.mCategories != null) { - this.mCategories = new HashSet(o.mCategories); + this.mCategories = new ArraySet(o.mCategories); } if (o.mExtras != null) { this.mExtras = new Bundle(o.mExtras); @@ -3662,7 +3662,7 @@ public class Intent implements Parcelable, Cloneable { this.mPackage = o.mPackage; this.mComponent = o.mComponent; if (o.mCategories != null) { - this.mCategories = new HashSet(o.mCategories); + this.mCategories = new ArraySet(o.mCategories); } } @@ -5226,7 +5226,7 @@ public class Intent implements Parcelable, Cloneable { */ public Intent addCategory(String category) { if (mCategories == null) { - mCategories = new HashSet(); + mCategories = new ArraySet(); } mCategories.add(category.intern()); return this; @@ -6370,7 +6370,7 @@ public class Intent implements Parcelable, Cloneable { if (other.mCategories != null && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) { if (other.mCategories != null) { - mCategories = new HashSet(other.mCategories); + mCategories = new ArraySet(other.mCategories); } changes |= FILL_IN_CATEGORIES; } @@ -6641,12 +6641,9 @@ public class Intent implements Parcelable, Cloneable { } first = false; b.append("cat=["); - Iterator i = mCategories.iterator(); - boolean didone = false; - while (i.hasNext()) { - if (didone) b.append(","); - didone = true; - b.append(i.next()); + for (int i=0; i 0) b.append(','); + b.append(mCategories.valueAt(i)); } b.append("]"); } @@ -6804,8 +6801,8 @@ public class Intent implements Parcelable, Cloneable { uri.append("action=").append(Uri.encode(mAction)).append(';'); } if (mCategories != null) { - for (String category : mCategories) { - uri.append("category=").append(Uri.encode(category)).append(';'); + for (int i=0; i