Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99f41490 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Clean up some temporary allocations."

parents 511c369f 390517be
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.os;

import android.util.ArrayMap;

import java.util.HashMap;

/**
@@ -47,8 +49,8 @@ import java.util.HashMap;
 * implements the {@link #onCallbackDied} method.
 */
public class RemoteCallbackList<E extends IInterface> {
    /*package*/ HashMap<IBinder, Callback> mCallbacks
            = new HashMap<IBinder, Callback>();
    /*package*/ ArrayMap<IBinder, Callback> mCallbacks
            = new ArrayMap<IBinder, Callback>();
    private Object[] mActiveBroadcast;
    private int mBroadcastCount = -1;
    private boolean mKilled = false;
@@ -159,7 +161,8 @@ public class RemoteCallbackList<E extends IInterface> {
     */
    public void kill() {
        synchronized (mCallbacks) {
            for (Callback cb : mCallbacks.values()) {
            for (int cbi=mCallbacks.size()-1; cbi>=0; cbi--) {
                Callback cb = mCallbacks.valueAt(cbi);
                cb.mCallback.asBinder().unlinkToDeath(cb, 0);
            }
            mCallbacks.clear();
@@ -238,11 +241,10 @@ public class RemoteCallbackList<E extends IInterface> {
            if (active == null || active.length < N) {
                mActiveBroadcast = active = new Object[N];
            }
            int i=0;
            for (Callback cb : mCallbacks.values()) {
                active[i++] = cb;
            for (int i=0; i<N; i++) {
                active[i] = mCallbacks.valueAt(i);
            }
            return i;
            return N;
        }
    }

+9 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Printer;
import android.util.Singleton;
@@ -1069,7 +1070,7 @@ public final class StrictMode {
        // Map from violation stacktrace hashcode -> uptimeMillis of
        // last violation.  No locking needed, as this is only
        // accessed by the same thread.
        private final HashMap<Integer, Long> mLastViolationTime = new HashMap<Integer, Long>();
        private ArrayMap<Integer, Long> mLastViolationTime;

        public AndroidBlockGuardPolicy(final int policyMask) {
            mPolicyMask = policyMask;
@@ -1279,8 +1280,13 @@ public final class StrictMode {
            // Not perfect, but fast and good enough for dup suppression.
            Integer crashFingerprint = info.hashCode();
            long lastViolationTime = 0;
            if (mLastViolationTime.containsKey(crashFingerprint)) {
                lastViolationTime = mLastViolationTime.get(crashFingerprint);
            if (mLastViolationTime != null) {
                Long vtime = mLastViolationTime.get(crashFingerprint);
                if (vtime != null) {
                    lastViolationTime = vtime;
                }
            } else {
                mLastViolationTime = new ArrayMap<Integer, Long>(1);
            }
            long now = SystemClock.uptimeMillis();
            mLastViolationTime.put(crashFingerprint, now);
+9 −7
Original line number Diff line number Diff line
@@ -212,11 +212,13 @@ public final class ArrayMap<K, V> implements Map<K, V> {
     */
    @Override
    public void clear() {
        if (mSize != 0) {
            freeArrays(mHashes, mArray, mSize);
            mHashes = SparseArray.EMPTY_INTS;
            mArray = SparseArray.EMPTY_OBJECTS;
            mSize = 0;
        }
    }

    /**
     * Ensure the array map can hold at least <var>minimumCapacity</var>
@@ -227,9 +229,9 @@ public final class ArrayMap<K, V> implements Map<K, V> {
            int[] ohashes = mHashes;
            Object[] oarray = mArray;
            allocArrays(minimumCapacity);
            if (mHashes.length > 0) {
                System.arraycopy(ohashes, 0, mHashes, 0, mHashes.length);
                System.arraycopy(oarray, 0, mArray, 0, mArray.length);
            if (mSize > 0) {
                System.arraycopy(ohashes, 0, mHashes, 0, mSize);
                System.arraycopy(oarray, 0, mArray, 0, mSize<<1);
            }
            freeArrays(ohashes, oarray, mSize);
        }
+37 −38
Original line number Diff line number Diff line
@@ -351,12 +351,11 @@ class AlarmManagerService extends IAlarmManager.Stub {
        }

        // iterator over the list removing any it where the intent match
        Iterator<Alarm> it = alarmList.iterator();
        
        while (it.hasNext()) {
            Alarm alarm = it.next();
        for (int i=0; i<alarmList.size(); i++) {
            Alarm alarm = alarmList.get(i);
            if (alarm.operation.equals(operation)) {
                it.remove();
                alarmList.remove(i);
                i--;
            }
        }
    }
@@ -375,12 +374,11 @@ class AlarmManagerService extends IAlarmManager.Stub {
        }

        // iterator over the list removing any it where the intent match
        Iterator<Alarm> it = alarmList.iterator();
        
        while (it.hasNext()) {
            Alarm alarm = it.next();
        for (int i=0; i<alarmList.size(); i++) {
            Alarm alarm = alarmList.get(i);
            if (alarm.operation.getTargetPackage().equals(packageName)) {
                it.remove();
                alarmList.remove(i);
                i--;
            }
        }
    }
@@ -398,12 +396,11 @@ class AlarmManagerService extends IAlarmManager.Stub {
        }

        // iterator over the list removing any it where the intent match
        Iterator<Alarm> it = alarmList.iterator();

        while (it.hasNext()) {
            Alarm alarm = it.next();
        for (int i=0; i<alarmList.size(); i++) {
            Alarm alarm = alarmList.get(i);
            if (UserHandle.getUserId(alarm.operation.getCreatorUid()) == userHandle) {
                it.remove();
                alarmList.remove(i);
                i--;
            }
        }
    }
@@ -666,12 +663,10 @@ class AlarmManagerService extends IAlarmManager.Stub {
                                     ArrayList<Alarm> triggerList,
                                     long now)
    {
        Iterator<Alarm> it = alarmList.iterator();
        ArrayList<Alarm> repeats = new ArrayList<Alarm>();
        ArrayList<Alarm> repeats = null;

        while (it.hasNext())
        {
            Alarm alarm = it.next();
        for (int i=0; i<alarmList.size(); i++) {
            Alarm alarm = alarmList.get(i);

            if (localLOGV) Slog.v(TAG, "Checking active alarm when=" + alarm.when + " " + alarm);

@@ -702,21 +697,26 @@ class AlarmManagerService extends IAlarmManager.Stub {
            triggerList.add(alarm);
            
            // remove the alarm from the list
            it.remove();
            alarmList.remove(i);
            i--;

            // if it repeats queue it up to be read-added to the list
            if (alarm.repeatInterval > 0) {
                if (repeats == null) {
                    repeats = new ArrayList<Alarm>();
                }
                repeats.add(alarm);
            }
        }

        // reset any repeating alarms.
        it = repeats.iterator();
        while (it.hasNext()) {
            Alarm alarm = it.next();
        if (repeats != null) {
            for (int i=0; i<repeats.size(); i++) {
                Alarm alarm = repeats.get(i);
                alarm.when += alarm.count * alarm.repeatInterval;
                addAlarmLocked(alarm);
            }
        }
        
        if (alarmList.size() > 0) {
            setLocked(alarmList.get(0));
@@ -785,11 +785,13 @@ class AlarmManagerService extends IAlarmManager.Stub {
        
        public void run()
        {
            ArrayList<Alarm> triggerList = new ArrayList<Alarm>();

            while (true)
            {
                int result = waitForAlarm(mDescriptor);

                ArrayList<Alarm> triggerList = new ArrayList<Alarm>();
                triggerList.clear();

                if ((result & TIME_CHANGED_MASK) != 0) {
                    remove(mTimeTickSender);
@@ -820,9 +822,8 @@ class AlarmManagerService extends IAlarmManager.Stub {
                        triggerAlarmsLocked(mElapsedRealtimeAlarms, triggerList, nowELAPSED);
                    
                    // now trigger the alarms
                    Iterator<Alarm> it = triggerList.iterator();
                    while (it.hasNext()) {
                        Alarm alarm = it.next();
                    for (int i=0; i<triggerList.size(); i++) {
                        Alarm alarm = triggerList.get(i);
                        try {
                            if (localLOGV) Slog.v(TAG, "sending alarm " + alarm);
                            alarm.operation.send(mContext, 0,
@@ -913,10 +914,8 @@ class AlarmManagerService extends IAlarmManager.Stub {
                }
                
                // now trigger the alarms without the lock held
                Iterator<Alarm> it = triggerList.iterator();
                while (it.hasNext())
                {
                    Alarm alarm = it.next();
                for (int i=0; i<triggerList.size(); i++) {
                    Alarm alarm = triggerList.get(i);
                    try {
                        alarm.operation.send();
                    } catch (PendingIntent.CanceledException e) {
+84 −94
Original line number Diff line number Diff line
@@ -574,11 +574,8 @@ public class ActiveServices {
                    b.binder = service;
                    b.requested = true;
                    b.received = true;
                    if (r.connections.size() > 0) {
                        Iterator<ArrayList<ConnectionRecord>> it
                                = r.connections.values().iterator();
                        while (it.hasNext()) {
                            ArrayList<ConnectionRecord> clist = it.next();
                    for (int conni=r.connections.size()-1; conni>=0; conni--) {
                        ArrayList<ConnectionRecord> clist = r.connections.valueAt(conni);
                        for (int i=0; i<clist.size(); i++) {
                            ConnectionRecord c = clist.get(i);
                            if (!filter.equals(c.binding.intent.intent)) {
@@ -601,7 +598,6 @@ public class ActiveServices {
                        }
                    }
                }
                }

                serviceDoneExecutingLocked(r, mStoppingServices.contains(r));
            }
@@ -1064,10 +1060,9 @@ public class ActiveServices {
    }

    private final void requestServiceBindingsLocked(ServiceRecord r) {
        Iterator<IntentBindRecord> bindings = r.bindings.values().iterator();
        while (bindings.hasNext()) {
            IntentBindRecord i = bindings.next();
            if (!requestServiceBindingLocked(r, i, false)) {
        for (int i=r.bindings.size()-1; i>=0; i--) {
            IntentBindRecord ibr = r.bindings.valueAt(i);
            if (!requestServiceBindingLocked(r, ibr, false)) {
                break;
            }
        }
@@ -1179,13 +1174,11 @@ public class ActiveServices {
        if (!force && r.startRequested) {
            return;
        }
        if (r.connections.size() > 0) {
        if (!force) {
            // XXX should probably keep a count of the number of auto-create
            // connections directly in the service.
                Iterator<ArrayList<ConnectionRecord>> it = r.connections.values().iterator();
                while (it.hasNext()) {
                    ArrayList<ConnectionRecord> cr = it.next();
            for (int conni=r.connections.size()-1; conni>=0; conni--) {
                ArrayList<ConnectionRecord> cr = r.connections.valueAt(conni);
                for (int i=0; i<cr.size(); i++) {
                    if ((cr.get(i).flags&Context.BIND_AUTO_CREATE) != 0) {
                        return;
@@ -1196,9 +1189,8 @@ public class ActiveServices {

        // Report to all of the connections that the service is no longer
        // available.
            Iterator<ArrayList<ConnectionRecord>> it = r.connections.values().iterator();
            while (it.hasNext()) {
                ArrayList<ConnectionRecord> c = it.next();
        for (int conni=r.connections.size()-1; conni>=0; conni--) {
            ArrayList<ConnectionRecord> c = r.connections.valueAt(conni);
            for (int i=0; i<c.size(); i++) {
                ConnectionRecord cr = c.get(i);
                // There is still a connection to the service that is
@@ -1213,16 +1205,14 @@ public class ActiveServices {
                }
            }
        }
        }

        // Tell the service that it has been unbound.
        if (r.bindings.size() > 0 && r.app != null && r.app.thread != null) {
            Iterator<IntentBindRecord> it = r.bindings.values().iterator();
            while (it.hasNext()) {
                IntentBindRecord ibr = it.next();
        if (r.app != null && r.app.thread != null) {
            for (int i=r.bindings.size()-1; i>=0; i--) {
                IntentBindRecord ibr = r.bindings.valueAt(i);
                if (DEBUG_SERVICE) Slog.v(TAG, "Bringing down binding " + ibr
                        + ": hasBound=" + ibr.hasBound);
                if (r.app != null && r.app.thread != null && ibr.hasBound) {
                if (ibr.hasBound) {
                    try {
                        bumpServiceExecutingLocked(r, "bring down unbind");
                        mAm.updateOomAdjLocked(r.app);
@@ -1595,11 +1585,8 @@ public class ActiveServices {
                Iterator<ServiceRecord> it = app.services.iterator();
                while (it.hasNext()) {
                    ServiceRecord r = it.next();
                    if (r.connections.size() > 0) {
                        Iterator<ArrayList<ConnectionRecord>> jt
                                = r.connections.values().iterator();
                        while (jt.hasNext()) {
                            ArrayList<ConnectionRecord> cl = jt.next();
                    for (int conni=r.connections.size()-1; conni>=0; conni--) {
                        ArrayList<ConnectionRecord> cl = r.connections.valueAt(conni);
                        for (int i=0; i<cl.size(); i++) {
                            ConnectionRecord c = cl.get(i);
                            if (c.binding.client != app) {
@@ -1617,7 +1604,6 @@ public class ActiveServices {
                }
            }
        }
        }

        // Clean up any connections this application has to other services.
        if (app.connections.size() > 0) {
@@ -1645,18 +1631,14 @@ public class ActiveServices {
                    if (DEBUG_SERVICE) Slog.v(TAG, "killServices remove stopping " + sr);
                }

                boolean hasClients = sr.bindings.size() > 0;
                if (hasClients) {
                    Iterator<IntentBindRecord> bindings
                            = sr.bindings.values().iterator();
                    while (bindings.hasNext()) {
                        IntentBindRecord b = bindings.next();
                final int numClients = sr.bindings.size();
                for (int bindingi=numClients-1; bindingi>=0; bindingi--) {
                    IntentBindRecord b = sr.bindings.valueAt(bindingi);
                    if (DEBUG_SERVICE) Slog.v(TAG, "Killing binding " + b
                            + ": shouldUnbind=" + b.hasBound);
                    b.binder = null;
                    b.requested = b.received = b.hasBound = false;
                }
                }

                if (sr.crashCount >= 2 && (sr.serviceInfo.applicationInfo.flags
                        &ApplicationInfo.FLAG_PERSISTENT) == 0) {
@@ -1676,7 +1658,7 @@ public class ActiveServices {
                    if (sr.startRequested && (sr.stopIfKilled || canceled)) {
                        if (sr.pendingStarts.size() == 0) {
                            sr.startRequested = false;
                            if (!hasClients) {
                            if (numClients > 0) {
                                // Whoops, no reason to restart!
                                bringDownServiceLocked(sr, true);
                            }
@@ -1732,7 +1714,8 @@ public class ActiveServices {
            info.flags |= ActivityManager.RunningServiceInfo.FLAG_PERSISTENT_PROCESS;
        }

        for (ArrayList<ConnectionRecord> connl : r.connections.values()) {
        for (int conni=r.connections.size()-1; conni>=0; conni--) {
            ArrayList<ConnectionRecord> connl = r.connections.valueAt(conni);
            for (int i=0; i<connl.size(); i++) {
                ConnectionRecord conn = connl.get(i);
                if (conn.clientLabel != 0) {
@@ -1805,7 +1788,8 @@ public class ActiveServices {
        int userId = UserHandle.getUserId(Binder.getCallingUid());
        ServiceRecord r = mServiceMap.getServiceByName(name, userId);
        if (r != null) {
            for (ArrayList<ConnectionRecord> conn : r.connections.values()) {
            for (int conni=r.connections.size()-1; conni>=0; conni--) {
                ArrayList<ConnectionRecord> conn = r.connections.valueAt(conni);
                for (int i=0; i<conn.size(); i++) {
                    if (conn.get(i).clientIntent != null) {
                        return conn.get(i).clientIntent;
@@ -1859,6 +1843,7 @@ public class ActiveServices {
    boolean dumpServicesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) {
        boolean needSep = false;
        boolean needSepResult = false;

        ItemMatcher matcher = new ItemMatcher();
        matcher.build(args, opti);
@@ -1881,6 +1866,7 @@ public class ActiveServices {
                        if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
                            continue;
                        }
                        needSepResult = true;
                        if (!printed) {
                            if (user != 0) {
                                pw.println();
@@ -1907,7 +1893,8 @@ public class ActiveServices {
                            pw.println(r.connections.size());
                            if (r.connections.size() > 0) {
                                pw.println("    Connections:");
                                for (ArrayList<ConnectionRecord> clist : r.connections.values()) {
                                for (int conni=0; conni<=r.connections.size(); conni++) {
                                    ArrayList<ConnectionRecord> clist = r.connections.valueAt(conni);
                                    for (int i = 0; i < clist.size(); i++) {
                                        ConnectionRecord conn = clist.get(i);
                                        pw.print("      ");
@@ -1960,6 +1947,7 @@ public class ActiveServices {
                if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
                    continue;
                }
                needSepResult = true;
                if (!printed) {
                    if (needSep) pw.println(" ");
                    needSep = true;
@@ -1982,6 +1970,7 @@ public class ActiveServices {
                if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
                    continue;
                }
                needSepResult = true;
                if (!printed) {
                    if (needSep) pw.println(" ");
                    needSep = true;
@@ -2004,6 +1993,7 @@ public class ActiveServices {
                if (dumpPackage != null && !dumpPackage.equals(r.appInfo.packageName)) {
                    continue;
                }
                needSepResult = true;
                if (!printed) {
                    if (needSep) pw.println(" ");
                    needSep = true;
@@ -2032,6 +2022,7 @@ public class ActiveServices {
                                || !dumpPackage.equals(cr.binding.client.info.packageName))) {
                            continue;
                        }
                        needSepResult = true;
                        if (!printed) {
                            if (needSep) pw.println(" ");
                            needSep = true;
@@ -2042,11 +2033,10 @@ public class ActiveServices {
                        cr.dump(pw, "    ");
                    }
                }
                needSep = true;
            }
        }

        return needSep;
        return needSepResult;
    }

    /**
Loading