下面列出了android.util.SparseIntArray#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void syncFirewallChainLocked(int chain, String name) {
SparseIntArray rules;
synchronized (mRulesLock) {
final SparseIntArray uidFirewallRules = getUidFirewallRulesLR(chain);
// Make a copy of the current rules, and then clear them. This is because
// setFirewallUidRuleInternal only pushes down rules to the native daemon if they
// are different from the current rules stored in the mUidFirewall*Rules array for
// the specified chain. If we don't clear the rules, setFirewallUidRuleInternal
// will do nothing.
rules = uidFirewallRules.clone();
uidFirewallRules.clear();
}
if (rules.size() > 0) {
// Now push the rules. setFirewallUidRuleInternal will push each of these down to the
// native daemon, and also add them to the mUidFirewall*Rules array for the specified
// chain.
if (DBG) Slog.d(TAG, "Pushing " + rules.size() + " active firewall "
+ name + "UID rules");
for (int i = 0; i < rules.size(); i++) {
setFirewallUidRuleLocked(chain, rules.keyAt(i), rules.valueAt(i));
}
}
}
private synchronized boolean readCoreStats(SparseIntArray array, ProcFileReader reader) {
array.clear();
// A failure is mostly expected because files become inaccessible in case of
// the core being taken offline.
if (!reader.isValid()) {
return false;
}
try {
while (reader.hasNext()) {
long frequency = reader.readNumber();
reader.skipSpaces();
long timeInState = reader.readNumber() / CpuMetricsCollector.getClockTicksPerSecond();
reader.skipLine();
array.put((int) frequency, (int) timeInState);
}
} catch (ProcFileReader.ParseException pe) {
return false;
}
return true;
}
/**
* Get an array with display ids ordered by focus priority - last items should be given
* focus first. Sparse array just maps position to displayId.
*/
void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder) {
displaysInFocusOrder.clear();
final int size = mChildren.size();
for (int i = 0; i < size; ++i) {
final DisplayContent displayContent = mChildren.get(i);
if (displayContent.isRemovalDeferred()) {
// Don't report displays that are going to be removed soon.
continue;
}
displaysInFocusOrder.put(i, displayContent.getDisplayId());
}
}
private int[] sortOrdersIntoReorderedIndices(int childCount, List<Order> orders,
SparseIntArray orderCache) {
Collections.sort(orders);
orderCache.clear();
int[] reorderedIndices = new int[childCount];
int i = 0;
for (Order order : orders) {
reorderedIndices[i] = order.index;
orderCache.append(order.index, order.order);
i++;
}
return reorderedIndices;
}
private static void copyArrayInto(SparseIntArray source, SparseIntArray destination) {
destination.clear();
for (int i = 0; i < source.size(); i++) {
destination.append(source.keyAt(i), source.valueAt(i));
}
}