use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class AlphabetIndexer method getPositionForSection.
/**
* Performs a binary search or cache lookup to find the first row that
* matches a given section's starting letter.
* @param sectionIndex the section to search for
* @return the row index of the first occurrence, or the nearest next letter.
* For instance, if searching for "T" and no "T" is found, then the first
* row starting with "U" or any higher letter is returned. If there is no
* data following "T" at all, then the list size is returned.
*/
public int getPositionForSection(int sectionIndex) {
final SparseIntArray alphaMap = mAlphaMap;
final Cursor cursor = mDataCursor;
if (cursor == null || mAlphabet == null) {
return 0;
}
// Check bounds
if (sectionIndex <= 0) {
return 0;
}
if (sectionIndex >= mAlphabetLength) {
sectionIndex = mAlphabetLength - 1;
}
int savedCursorPos = cursor.getPosition();
int count = cursor.getCount();
int start = 0;
int end = count;
int pos;
char letter = mAlphabet.charAt(sectionIndex);
String targetLetter = Character.toString(letter);
int key = letter;
// Check map
if (Integer.MIN_VALUE != (pos = alphaMap.get(key, Integer.MIN_VALUE))) {
// position.
if (pos < 0) {
pos = -pos;
end = pos;
} else {
// Not approximate, this is the confirmed start of section, return it
return pos;
}
}
// Do we have the position of the previous section?
if (sectionIndex > 0) {
int prevLetter = mAlphabet.charAt(sectionIndex - 1);
int prevLetterPos = alphaMap.get(prevLetter, Integer.MIN_VALUE);
if (prevLetterPos != Integer.MIN_VALUE) {
start = Math.abs(prevLetterPos);
}
}
// Now that we have a possibly optimized start and end, let's binary search
pos = (end + start) / 2;
while (pos < end) {
// Get letter at pos
cursor.moveToPosition(pos);
String curName = cursor.getString(mColumnIndex);
if (curName == null) {
if (pos == 0) {
break;
} else {
pos--;
continue;
}
}
int diff = compare(curName, targetLetter);
if (diff != 0) {
// if (mCollator.compare(startingLetter, targetLetter) < 0) {
if (diff < 0) {
start = pos + 1;
if (start >= count) {
pos = count;
break;
}
} else {
end = pos;
}
} else {
// They're the same, but that doesn't mean it's the start
if (start == pos) {
// This is it
break;
} else {
// Need to go further lower to find the starting row
end = pos;
}
}
pos = (start + end) / 2;
}
alphaMap.put(key, pos);
cursor.moveToPosition(savedCursorPos);
return pos;
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyManagerService method updateRulesForAppIdleUL.
void updateRulesForAppIdleUL() {
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForAppIdleUL");
try {
final SparseIntArray uidRules = mUidFirewallStandbyRules;
uidRules.clear();
// Fully update the app idle firewall chain.
final List<UserInfo> users = mUserManager.getUsers();
for (int ui = users.size() - 1; ui >= 0; ui--) {
UserInfo user = users.get(ui);
int[] idleUids = mUsageStats.getIdleUidsForUser(user.id);
for (int uid : idleUids) {
if (!mPowerSaveTempWhitelistAppIds.get(UserHandle.getAppId(uid), false)) {
// with it here.
if (hasInternetPermissions(uid)) {
uidRules.put(uid, FIREWALL_RULE_DENY);
}
}
}
}
setUidFirewallRulesAsync(FIREWALL_CHAIN_STANDBY, uidRules, CHAIN_TOGGLE_NONE);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
}
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyManagerService method updateRulesForWhitelistedPowerSaveUL.
// NOTE: since both fw_dozable and fw_powersave uses the same map
// (mPowerSaveTempWhitelistAppIds) for whitelisting, we can reuse their logic in this method.
private void updateRulesForWhitelistedPowerSaveUL(boolean enabled, int chain, SparseIntArray rules) {
if (enabled) {
// Sync the whitelists before enabling the chain. We don't care about the rules if
// we are disabling the chain.
final SparseIntArray uidRules = rules;
uidRules.clear();
final List<UserInfo> users = mUserManager.getUsers();
for (int ui = users.size() - 1; ui >= 0; ui--) {
UserInfo user = users.get(ui);
for (int i = mPowerSaveTempWhitelistAppIds.size() - 1; i >= 0; i--) {
if (mPowerSaveTempWhitelistAppIds.valueAt(i)) {
int appId = mPowerSaveTempWhitelistAppIds.keyAt(i);
int uid = UserHandle.getUid(user.id, appId);
uidRules.put(uid, FIREWALL_RULE_ALLOW);
}
}
for (int i = mPowerSaveWhitelistAppIds.size() - 1; i >= 0; i--) {
int appId = mPowerSaveWhitelistAppIds.keyAt(i);
int uid = UserHandle.getUid(user.id, appId);
uidRules.put(uid, FIREWALL_RULE_ALLOW);
}
}
for (int i = mUidState.size() - 1; i >= 0; i--) {
if (isProcStateAllowedWhileIdleOrPowerSaveMode(mUidState.valueAt(i))) {
uidRules.put(mUidState.keyAt(i), FIREWALL_RULE_ALLOW);
}
}
setUidFirewallRulesAsync(chain, uidRules, CHAIN_TOGGLE_ENABLE);
} else {
setUidFirewallRulesAsync(chain, null, CHAIN_TOGGLE_DISABLE);
}
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class TableRow method mapIndexAndColumns.
private void mapIndexAndColumns() {
if (mColumnToChildIndex == null) {
int virtualCount = 0;
final int count = getChildCount();
mColumnToChildIndex = new SparseIntArray();
final SparseIntArray columnToChild = mColumnToChildIndex;
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
final LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
if (layoutParams.column >= virtualCount) {
virtualCount = layoutParams.column;
}
for (int j = 0; j < layoutParams.span; j++) {
columnToChild.put(virtualCount++, i);
}
}
mNumColumns = virtualCount;
}
}
use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.
the class ExifInterface method getTagDefinitionsForTagId.
protected int[] getTagDefinitionsForTagId(short tagId) {
int[] ifds = IfdData.getIfds();
int[] defs = new int[ifds.length];
int counter = 0;
SparseIntArray infos = getTagInfo();
for (int i : ifds) {
int def = defineTag(i, tagId);
if (infos.get(def) != DEFINITION_NULL) {
defs[counter++] = def;
}
}
if (counter == 0) {
return null;
}
return Arrays.copyOfRange(defs, 0, counter);
}
Aggregations