use of android.util.SparseArray in project cornerstone by Onskreen.
the class ActivityManagerService method dumpHeap.
public boolean dumpHeap(String process, boolean managed, String path, ParcelFileDescriptor fd) throws RemoteException {
try {
synchronized (this) {
// its own permission (same as profileControl).
if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) != PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires permission " + android.Manifest.permission.SET_ACTIVITY_WATCHER);
}
if (fd == null) {
throw new IllegalArgumentException("null fd");
}
ProcessRecord proc = null;
try {
int pid = Integer.parseInt(process);
synchronized (mPidsSelfLocked) {
proc = mPidsSelfLocked.get(pid);
}
} catch (NumberFormatException e) {
}
if (proc == null) {
HashMap<String, SparseArray<ProcessRecord>> all = mProcessNames.getMap();
SparseArray<ProcessRecord> procs = all.get(process);
if (procs != null && procs.size() > 0) {
proc = procs.valueAt(0);
}
}
if (proc == null || proc.thread == null) {
throw new IllegalArgumentException("Unknown process: " + process);
}
boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
if (!isDebuggable) {
if ((proc.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
throw new SecurityException("Process not debuggable: " + proc);
}
}
proc.thread.dumpHeap(managed, path, fd);
fd = null;
return true;
}
} catch (RemoteException e) {
throw new IllegalStateException("Process disappeared");
} finally {
if (fd != null) {
try {
fd.close();
} catch (IOException e) {
}
}
}
}
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";
}
}
}
}
use of android.util.SparseArray in project SmartAndroidSource by jaychou2012.
the class MenuBuilder method dispatchSaveInstanceState.
private void dispatchSaveInstanceState(Bundle outState) {
if (mPresenters.isEmpty())
return;
SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
final int id = presenter.getId();
if (id > 0) {
final Parcelable state = presenter.onSaveInstanceState();
if (state != null) {
presenterStates.put(id, state);
}
}
}
}
outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
}
use of android.util.SparseArray in project android-parcelable-intellij-plugin by mcharmas.
the class SparseParcelable method create.
public static SparseParcelable create() {
SparseArray<String> sampleSparseArray = new SparseArray<String>(10);
sampleSparseArray.put(10, "abcd");
SparseBooleanArray sparseBooleanArray = new SparseBooleanArray();
sparseBooleanArray.put(1, false);
return new SparseParcelable(sampleSparseArray, sparseBooleanArray);
}
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;
}
Aggregations