Java Code Examples for android.util.SparseIntArray#clear()

The following examples show how to use android.util.SparseIntArray#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkManagementService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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));
        }
    }
}
 
Example 2
Source File: CpuFrequencyMetricsCollector.java    From Battery-Metrics with MIT License 6 votes vote down vote up
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;
}
 
Example 3
Source File: RootWindowContainer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 4
Source File: FlexboxHelper.java    From Collection-Android with MIT License 5 votes vote down vote up
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;
}
 
Example 5
Source File: CpuFrequencyMetrics.java    From Battery-Metrics with MIT License 4 votes vote down vote up
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));
  }
}