com.google.android.collect.Lists Java Examples

The following examples show how to use com.google.android.collect.Lists. 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: NetworkStatsCollection.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any {@link NetworkStatsHistory} attributed to the requested UID,
 * moving any {@link NetworkStats#TAG_NONE} series to
 * {@link TrafficStats#UID_REMOVED}.
 */
public void removeUids(int[] uids) {
    final ArrayList<Key> knownKeys = Lists.newArrayList();
    knownKeys.addAll(mStats.keySet());

    // migrate all UID stats into special "removed" bucket
    for (Key key : knownKeys) {
        if (ArrayUtils.contains(uids, key.uid)) {
            // only migrate combined TAG_NONE history
            if (key.tag == TAG_NONE) {
                final NetworkStatsHistory uidHistory = mStats.get(key);
                final NetworkStatsHistory removedHistory = findOrCreateHistory(
                        key.ident, UID_REMOVED, SET_DEFAULT, TAG_NONE);
                removedHistory.recordEntireHistory(uidHistory);
            }
            mStats.remove(key);
            mDirty = true;
        }
    }
}
 
Example #2
Source File: NativeDaemonEvent.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Filter the given {@link NativeDaemonEvent} list, returning
 * {@link #getMessage()} for any events matching the requested code.
 */
public static String[] filterMessageList(NativeDaemonEvent[] events, int matchCode) {
    final ArrayList<String> result = Lists.newArrayList();
    for (NativeDaemonEvent event : events) {
        if (event.getCode() == matchCode) {
            result.add(event.getMessage());
        }
    }
    return result.toArray(new String[result.size()]);
}
 
Example #3
Source File: PacProxySelector.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public PacProxySelector() {
    mProxyService = IProxyService.Stub.asInterface(
            ServiceManager.getService(PROXY_SERVICE));
    if (mProxyService == null) {
        // Added because of b10267814 where mako is restarting.
        Log.e(TAG, "PacManager: no proxy service");
    }
    mDefaultList = Lists.newArrayList(java.net.Proxy.NO_PROXY);
}
 
Example #4
Source File: LockPatternUtils.java    From android-lockpattern with Apache License 2.0 5 votes vote down vote up
/**
 * Deserialize a pattern.
 * 
 * @param string
 *            The pattern serialized with {@link #patternToString}
 * @return The pattern.
 */
public static List<LockPatternViewEx.Cell> stringToPattern(String string) {
    List<LockPatternViewEx.Cell> result = Lists.newArrayList();

    final byte[] bytes = string.getBytes();
    for (int i = 0; i < bytes.length; i++) {
        byte b = bytes[i];
        result.add(LockPatternViewEx.Cell.of(b / 3, b % 3));
    }
    return result;
}
 
Example #5
Source File: TextUtilsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void stringSplitterTestHelper(String string, String[] expectedStrings) {
    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
    splitter.setString(string);
    List<String> strings = Lists.newArrayList();
    for (String s : splitter) {
        strings.add(s);
    }
    MoreAsserts.assertEquals(expectedStrings, strings.toArray(new String[]{}));
}
 
Example #6
Source File: NativeDaemonConnector.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Issue the given command to the native daemon and return any {@linke
 * NativeDaemonEvent@isClassContinue()} responses, including the final
 * terminal response. Note that the timeout does not count time in deep
 * sleep. Any arguments must be separated from base command so they can be
 * properly escaped.
 *
 * @throws NativeDaemonConnectorException when problem communicating with
 *             native daemon, or if the response matches
 *             {@link NativeDaemonEvent#isClassClientError()} or
 *             {@link NativeDaemonEvent#isClassServerError()}.
 */
public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args)
        throws NativeDaemonConnectorException {
    if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
        Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
                + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
    }

    final long startTime = SystemClock.elapsedRealtime();

    final ArrayList<NativeDaemonEvent> events = Lists.newArrayList();

    final StringBuilder rawBuilder = new StringBuilder();
    final StringBuilder logBuilder = new StringBuilder();
    final int sequenceNumber = mSequenceNumber.incrementAndGet();

    makeCommand(rawBuilder, logBuilder, sequenceNumber, cmd, args);

    final String rawCmd = rawBuilder.toString();
    final String logCmd = logBuilder.toString();

    log("SND -> {" + logCmd + "}");

    synchronized (mDaemonLock) {
        if (mOutputStream == null) {
            throw new NativeDaemonConnectorException("missing output stream");
        } else {
            try {
                mOutputStream.write(rawCmd.getBytes(StandardCharsets.UTF_8));
            } catch (IOException e) {
                throw new NativeDaemonConnectorException("problem sending command", e);
            }
        }
    }

    NativeDaemonEvent event = null;
    do {
        event = mResponseQueue.remove(sequenceNumber, timeoutMs, logCmd);
        if (event == null) {
            loge("timed-out waiting for response to " + logCmd);
            throw new NativeDaemonTimeoutException(logCmd, event);
        }
        if (VDBG) log("RMV <- {" + event + "}");
        events.add(event);
    } while (event.isClassContinue());

    final long endTime = SystemClock.elapsedRealtime();
    if (endTime - startTime > WARN_EXECUTE_DELAY_MS) {
        loge("NDC Command {" + logCmd + "} took too long (" + (endTime - startTime) + "ms)");
    }

    if (event.isClassClientError()) {
        throw new NativeDaemonArgumentException(logCmd, event);
    }
    if (event.isClassServerError()) {
        throw new NativeDaemonFailureException(logCmd, event);
    }

    return events.toArray(new NativeDaemonEvent[events.size()]);
}
 
Example #7
Source File: NetworkStatsCollection.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private ArrayList<Key> getSortedKeys() {
    final ArrayList<Key> keys = Lists.newArrayList();
    keys.addAll(mStats.keySet());
    Collections.sort(keys);
    return keys;
}