use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.
the class StreamConfigurationMap method getPublicFormats.
/** Get the list of publically visible output formats; does not include IMPL_DEFINED */
private int[] getPublicFormats(boolean output) {
int[] formats = new int[getPublicFormatCount(output)];
int i = 0;
SparseIntArray map = getFormatsMap(output);
for (int j = 0; j < map.size(); j++) {
int format = map.keyAt(j);
formats[i++] = imageFormatToPublic(format);
}
if (output) {
for (int j = 0; j < mDepthOutputFormats.size(); j++) {
formats[i++] = depthFormatToPublic(mDepthOutputFormats.keyAt(j));
}
}
if (formats.length != i) {
throw new AssertionError("Too few formats " + i + ", expected " + formats.length);
}
return formats;
}
use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.
the class UsageStatsService method getIdleUidsForUser.
int[] getIdleUidsForUser(int userId) {
if (!mAppIdleEnabled) {
return new int[0];
}
final long elapsedRealtime = SystemClock.elapsedRealtime();
List<ApplicationInfo> apps;
try {
ParceledListSlice<ApplicationInfo> slice = AppGlobals.getPackageManager().getInstalledApplications(/* flags= */
0, userId);
if (slice == null) {
return new int[0];
}
apps = slice.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
// State of each uid. Key is the uid. Value lower 16 bits is the number of apps
// associated with that uid, upper 16 bits is the number of those apps that is idle.
SparseIntArray uidStates = new SparseIntArray();
// we find for each uid and how many of those are idle.
for (int i = apps.size() - 1; i >= 0; i--) {
ApplicationInfo ai = apps.get(i);
// Check whether this app is idle.
boolean idle = isAppIdleFiltered(ai.packageName, UserHandle.getAppId(ai.uid), userId, elapsedRealtime);
int index = uidStates.indexOfKey(ai.uid);
if (index < 0) {
uidStates.put(ai.uid, 1 + (idle ? 1 << 16 : 0));
} else {
int value = uidStates.valueAt(index);
uidStates.setValueAt(index, value + 1 + (idle ? 1 << 16 : 0));
}
}
if (DEBUG) {
Slog.d(TAG, "getIdleUids took " + (SystemClock.elapsedRealtime() - elapsedRealtime));
}
int numIdle = 0;
for (int i = uidStates.size() - 1; i >= 0; i--) {
int value = uidStates.valueAt(i);
if ((value & 0x7fff) == (value >> 16)) {
numIdle++;
}
}
int[] res = new int[numIdle];
numIdle = 0;
for (int i = uidStates.size() - 1; i >= 0; i--) {
int value = uidStates.valueAt(i);
if ((value & 0x7fff) == (value >> 16)) {
res[numIdle] = uidStates.keyAt(i);
numIdle++;
}
}
return res;
}
use of android.util.SparseIntArray in project AndroidChromium by JackyAndroid.
the class TabPersistentStore method mergeState.
/**
* Merge the tabs of the other Chrome instance into this instance by reading its tab metadata
* file and tab state files.
*
* This method should be called after a change in activity state indicates that a merge is
* necessary. #loadState() will take care of merging states on application cold start if needed.
*
* If there is currently a merge or load in progress then this method will return early.
*/
public void mergeState() {
if (mLoadInProgress || mPersistencePolicy.isMergeInProgress() || !mTabsToRestore.isEmpty()) {
Log.e(TAG, "Tab load still in progress when merge was attempted.");
return;
}
// Initialize variables.
mCancelNormalTabLoads = false;
mCancelIncognitoTabLoads = false;
mNormalTabsRestored = new SparseIntArray();
mIncognitoTabsRestored = new SparseIntArray();
try {
long time = SystemClock.uptimeMillis();
// Read the tab state metadata file.
DataInputStream stream = startFetchTabListTask(AsyncTask.SERIAL_EXECUTOR, mPersistencePolicy.getStateToBeMergedFileName()).get();
// to merge.
if (stream == null)
return;
logExecutionTime("MergeStateInternalFetchTime", time);
mPersistencePolicy.setMergeInProgress(true);
readSavedStateFile(stream, createOnTabStateReadCallback(mTabModelSelector.isIncognitoSelected(), true), null, true);
logExecutionTime("MergeStateInternalTime", time);
} catch (Exception e) {
// Catch generic exception to prevent a corrupted state from crashing app.
Log.d(TAG, "meregeState exception: " + e.toString(), e);
}
// Restore the tabs from the second activity asynchronously.
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
mMergeTabCount = mTabsToRestore.size();
mRestoreMergedTabsStartTime = SystemClock.uptimeMillis();
restoreTabs(false);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of android.util.SparseIntArray in project AndroidChromium by JackyAndroid.
the class TabPersistentStore method restoreTab.
private void restoreTab(TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
// If we don't have enough information about the Tab, bail out.
boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
if (tabState == null) {
if (tabToRestore.isIncognito == null) {
Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
return;
} else if (isIncognito) {
Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
return;
}
}
TabModel model = mTabModelSelector.getModel(isIncognito);
SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
int restoredIndex = 0;
if (tabToRestore.fromMerge) {
// Put any tabs being merged into this list at the end.
restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
} else if (restoredTabs.size() > 0 && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
// If the tab's index is too large, restore it at the end of the list.
restoredIndex = restoredTabs.size();
} else {
// Otherwise try to find the tab we should restore before, if any.
for (int i = 0; i < restoredTabs.size(); i++) {
if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
break;
}
}
}
int tabId = tabToRestore.id;
if (tabState != null) {
mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(tabState, tabToRestore.id, restoredIndex);
} else {
Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
tabId = fallbackTab.getId();
model.moveTab(tabId, restoredIndex);
}
// was selected in the other model before the merge should be selected after the merge.
if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();
TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
// view on tablets).
if (tabToRestore.fromMerge && wasIncognitoTabModelSelected != isIncognitoTabModelSelected && selectedModelTabCount != 0) {
mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
}
}
restoredTabs.put(tabToRestore.originalIndex, tabId);
}
use of android.util.SparseIntArray in project android_frameworks_base by crdroidandroid.
the class CursorWindow method printStats.
private String printStats() {
StringBuilder buff = new StringBuilder();
int myPid = Process.myPid();
int total = 0;
SparseIntArray pidCounts = new SparseIntArray();
synchronized (sWindowToPidMap) {
int size = sWindowToPidMap.size();
if (size == 0) {
// this means we are not in the ContentProvider.
return "";
}
for (int indx = 0; indx < size; indx++) {
int pid = sWindowToPidMap.valueAt(indx);
int value = pidCounts.get(pid);
pidCounts.put(pid, ++value);
}
}
int numPids = pidCounts.size();
for (int i = 0; i < numPids; i++) {
buff.append(" (# cursors opened by ");
int pid = pidCounts.keyAt(i);
if (pid == myPid) {
buff.append("this proc=");
} else {
buff.append("pid " + pid + "=");
}
int num = pidCounts.get(pid);
buff.append(num + ")");
total += num;
}
// limit the returned string size to 1000
String s = (buff.length() > 980) ? buff.substring(0, 980) : buff.toString();
return "# Open Cursors=" + total + s;
}
Aggregations