Search in sources :

Example 41 with SparseArray

use of android.util.SparseArray in project cornerstone by Onskreen.

the class ActivityManagerService method cleanUpRemovedTaskLocked.

private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
    final boolean killProcesses = (flags & ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
    Intent baseIntent = new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);
    ComponentName component = baseIntent.getComponent();
    if (component == null) {
        Slog.w(TAG, "Now component for base intent of task: " + tr);
        return;
    }
    // Find any running services associated with this app.
    ArrayList<ServiceRecord> services = new ArrayList<ServiceRecord>();
    for (ServiceRecord sr : mServiceMap.getAllServices(tr.userId)) {
        if (sr.packageName.equals(component.getPackageName())) {
            services.add(sr);
        }
    }
    // Take care of any running services associated with the app.
    for (int i = 0; i < services.size(); i++) {
        ServiceRecord sr = services.get(i);
        if (sr.startRequested) {
            if ((sr.serviceInfo.flags & ServiceInfo.FLAG_STOP_WITH_TASK) != 0) {
                Slog.i(TAG, "Stopping service " + sr.shortName + ": remove task");
                stopServiceLocked(sr);
            } else {
                sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true, sr.makeNextStartId(), baseIntent, null));
                if (sr.app != null && sr.app.thread != null) {
                    sendServiceArgsLocked(sr, false);
                }
            }
        }
    }
    if (killProcesses) {
        // Find any running processes associated with this app.
        final String pkg = component.getPackageName();
        ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
        HashMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
        for (SparseArray<ProcessRecord> uids : pmap.values()) {
            for (int i = 0; i < uids.size(); i++) {
                ProcessRecord proc = uids.valueAt(i);
                if (proc.userId != tr.userId) {
                    continue;
                }
                if (!proc.pkgList.contains(pkg)) {
                    continue;
                }
                procs.add(proc);
            }
        }
        // Kill the running processes.
        for (int i = 0; i < procs.size(); i++) {
            ProcessRecord pr = procs.get(i);
            if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
                Slog.i(TAG, "Killing " + pr.toShortString() + ": remove task");
                EventLog.writeEvent(EventLogTags.AM_KILL, pr.pid, pr.processName, pr.setAdj, "remove task");
                pr.killedBackground = true;
                Process.killProcessQuiet(pr.pid);
            } else {
                pr.waitingToKill = "remove task";
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SparseArray(android.util.SparseArray) ComponentName(android.content.ComponentName)

Example 42 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ParanoidAndroid.

the class ActivityManagerService method cleanUpRemovedTaskLocked.

private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
    final boolean killProcesses = (flags & ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
    Intent baseIntent = new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);
    ComponentName component = baseIntent.getComponent();
    if (component == null) {
        Slog.w(TAG, "Now component for base intent of task: " + tr);
        return;
    }
    // Find any running services associated with this app.
    mServices.cleanUpRemovedTaskLocked(tr, component, baseIntent);
    if (killProcesses) {
        // Find any running processes associated with this app.
        final String pkg = component.getPackageName();
        ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
        HashMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
        for (SparseArray<ProcessRecord> uids : pmap.values()) {
            for (int i = 0; i < uids.size(); i++) {
                ProcessRecord proc = uids.valueAt(i);
                if (proc.userId != tr.userId) {
                    continue;
                }
                if (!proc.pkgList.contains(pkg)) {
                    continue;
                }
                procs.add(proc);
            }
        }
        // Kill the running processes.
        for (int i = 0; i < procs.size(); i++) {
            ProcessRecord pr = procs.get(i);
            if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
                Slog.i(TAG, "Killing " + pr.toShortString() + ": remove task");
                EventLog.writeEvent(EventLogTags.AM_KILL, pr.userId, pr.pid, pr.processName, pr.setAdj, "remove task");
                pr.killedBackground = true;
                Process.killProcessQuiet(pr.pid);
            } else {
                pr.waitingToKill = "remove task";
            }
        }
    }
}
Also used : SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 43 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ParanoidAndroid.

the class StringBlock method get.

public CharSequence get(int idx) {
    synchronized (this) {
        if (mStrings != null) {
            CharSequence res = mStrings[idx];
            if (res != null) {
                return res;
            }
        } else if (mSparseStrings != null) {
            CharSequence res = mSparseStrings.get(idx);
            if (res != null) {
                return res;
            }
        } else {
            final int num = nativeGetSize(mNative);
            if (mUseSparse && num > 250) {
                mSparseStrings = new SparseArray<CharSequence>();
            } else {
                mStrings = new CharSequence[num];
            }
        }
        String str = nativeGetString(mNative, idx);
        CharSequence res = str;
        int[] style = nativeGetStyle(mNative, idx);
        if (localLOGV)
            Log.v(TAG, "Got string: " + str);
        if (localLOGV)
            Log.v(TAG, "Got styles: " + Arrays.toString(style));
        if (style != null) {
            if (mStyleIDs == null) {
                mStyleIDs = new StyleIDs();
            }
            // the magic constant 3.
            for (int styleIndex = 0; styleIndex < style.length; styleIndex += 3) {
                int styleId = style[styleIndex];
                if (styleId == mStyleIDs.boldId || styleId == mStyleIDs.italicId || styleId == mStyleIDs.underlineId || styleId == mStyleIDs.ttId || styleId == mStyleIDs.bigId || styleId == mStyleIDs.smallId || styleId == mStyleIDs.subId || styleId == mStyleIDs.supId || styleId == mStyleIDs.strikeId || styleId == mStyleIDs.listItemId || styleId == mStyleIDs.marqueeId) {
                    // id already found skip to next style
                    continue;
                }
                String styleTag = nativeGetString(mNative, styleId);
                if (styleTag.equals("b")) {
                    mStyleIDs.boldId = styleId;
                } else if (styleTag.equals("i")) {
                    mStyleIDs.italicId = styleId;
                } else if (styleTag.equals("u")) {
                    mStyleIDs.underlineId = styleId;
                } else if (styleTag.equals("tt")) {
                    mStyleIDs.ttId = styleId;
                } else if (styleTag.equals("big")) {
                    mStyleIDs.bigId = styleId;
                } else if (styleTag.equals("small")) {
                    mStyleIDs.smallId = styleId;
                } else if (styleTag.equals("sup")) {
                    mStyleIDs.supId = styleId;
                } else if (styleTag.equals("sub")) {
                    mStyleIDs.subId = styleId;
                } else if (styleTag.equals("strike")) {
                    mStyleIDs.strikeId = styleId;
                } else if (styleTag.equals("li")) {
                    mStyleIDs.listItemId = styleId;
                } else if (styleTag.equals("marquee")) {
                    mStyleIDs.marqueeId = styleId;
                }
            }
            res = applyStyles(str, style, mStyleIDs);
        }
        if (mStrings != null)
            mStrings[idx] = res;
        else
            mSparseStrings.put(idx, res);
        return res;
    }
}
Also used : SparseArray(android.util.SparseArray) Paint(android.graphics.Paint)

Example 44 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ParanoidAndroid.

the class BatteryStats method dumpCheckinLocked.

@SuppressWarnings("unused")
public void dumpCheckinLocked(PrintWriter pw, String[] args, List<ApplicationInfo> apps) {
    prepareForDumpLocked();
    boolean isUnpluggedOnly = false;
    for (String arg : args) {
        if ("-u".equals(arg)) {
            if (LOCAL_LOGV)
                Log.v("BatteryStats", "Dumping unplugged data");
            isUnpluggedOnly = true;
        }
    }
    if (apps != null) {
        SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
        for (int i = 0; i < apps.size(); i++) {
            ApplicationInfo ai = apps.get(i);
            ArrayList<String> pkgs = uids.get(ai.uid);
            if (pkgs == null) {
                pkgs = new ArrayList<String>();
                uids.put(ai.uid, pkgs);
            }
            pkgs.add(ai.packageName);
        }
        SparseArray<? extends Uid> uidStats = getUidStats();
        final int NU = uidStats.size();
        String[] lineArgs = new String[2];
        for (int i = 0; i < NU; i++) {
            int uid = uidStats.keyAt(i);
            ArrayList<String> pkgs = uids.get(uid);
            if (pkgs != null) {
                for (int j = 0; j < pkgs.size(); j++) {
                    lineArgs[0] = Integer.toString(uid);
                    lineArgs[1] = pkgs.get(j);
                    dumpLine(pw, 0, /* uid */
                    "i", /* category */
                    UID_DATA, (Object[]) lineArgs);
                }
            }
        }
    }
    if (isUnpluggedOnly) {
        dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
    } else {
        dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1);
        dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
    }
}
Also used : SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 45 with SparseArray

use of android.util.SparseArray in project KeepScore by nolanlawson.

the class HistoryTimelineFragment method smoothData.

private SparseArray<SparseArray<Long>> smoothData(Game game) {
    long roundedStartTimeInMs = Math.round(Math.floor(game.getDateStarted() * 1.0 / TIMELINE_ROUNDING_IN_MS)) * TIMELINE_ROUNDING_IN_MS;
    // first, plot all players' deltas with their timestamps on the same timeline (x axis), rounded to
    // the nearest ten seconds
    SparseArray<SparseArray<Long>> timeline = new SparseArray<SparseArray<Long>>();
    for (int i = 0; i < game.getPlayerScores().size(); i++) {
        PlayerScore playerScore = game.getPlayerScores().get(i);
        // have to include the starting score as well
        long startingScore = playerScore.getScore() - CollectionUtil.sum(CollectionUtil.transform(playerScore.getHistory(), Delta.GET_VALUE));
        timeline.put(0, SparseArrays.create(i, startingScore));
        long runningTally = startingScore;
        for (Delta delta : playerScore.getHistory()) {
            runningTally += delta.getValue();
            long timeSinceStartInMs = delta.getTimestamp() - roundedStartTimeInMs;
            int roundedTimeSinceStartInSecs = (int) TimeUnit.MILLISECONDS.toSeconds(Math.round(Math.floor(timeSinceStartInMs * 1.0 / TIMELINE_ROUNDING_IN_MS)) * TIMELINE_ROUNDING_IN_MS);
            if (roundedTimeSinceStartInSecs == 0) {
                // just in case someone was actually fast enough to log the first score in <5 seconds, bump
                // it up to the first mark instead
                roundedTimeSinceStartInSecs = (int) TimeUnit.MILLISECONDS.toSeconds(TIMELINE_ROUNDING_IN_MS);
            }
            log.d("roundedStartTimeInMs: %s, timeSinceStartInMs: %s, roundedTimeSinceStartInSecs: %s", roundedStartTimeInMs, timeSinceStartInMs, roundedTimeSinceStartInSecs);
            SparseArray<Long> existingScoresAtThisTime = timeline.get(roundedTimeSinceStartInSecs);
            if (existingScoresAtThisTime == null) {
                timeline.put(roundedTimeSinceStartInSecs, SparseArrays.create(i, runningTally));
            } else {
                // If the same player updated his score twice within the same rounded span,
                // then just add the two values together
                existingScoresAtThisTime.put(i, runningTally);
            }
        }
    }
    return timeline;
}
Also used : SparseArray(android.util.SparseArray) Delta(com.nolanlawson.keepscore.db.Delta) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Aggregations

SparseArray (android.util.SparseArray)250 ArrayList (java.util.ArrayList)74 ProcessState (com.android.internal.app.procstats.ProcessState)41 Parcelable (android.os.Parcelable)37 View (android.view.View)35 ServiceState (com.android.internal.app.procstats.ServiceState)31 RemoteException (android.os.RemoteException)24 Point (android.graphics.Point)19 ArraySet (android.util.ArraySet)17 HashMap (java.util.HashMap)17 ComponentName (android.content.ComponentName)15 ProcessStats (com.android.internal.app.procstats.ProcessStats)15 UserHandle (android.os.UserHandle)14 ArrayMap (android.util.ArrayMap)14 UserInfo (android.content.pm.UserInfo)13 Paint (android.graphics.Paint)13 Bitmap (android.graphics.Bitmap)12 IOException (java.io.IOException)12 ApplicationInfo (android.content.pm.ApplicationInfo)11 SparseIntArray (android.util.SparseIntArray)11