Search in sources :

Example 36 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.

the class CpuVideoTrackDecoder method findDecoderCodec.

/**
     * Looks for a codec with the specified requirements.
     *
     * The set of codecs will be filtered down to those that meet the following requirements:
     * <ol>
     *   <li>The codec is a decoder.</li>
     *   <li>The codec can decode a video of the specified format.</li>
     *   <li>The codec can decode to one of the specified color formats.</li>
     * </ol>
     * If multiple codecs are found, the one with the preferred color-format is taken. Color format
     * preference is determined by the order of their appearance in the color format array.
     *
     * @param format The format the codec must decode.
     * @param requiredColorFormats Array of target color spaces ordered by preference.
     * @return A codec that meets the requirements, or null if no such codec was found.
     */
private static MediaCodec findDecoderCodec(MediaFormat format, int[] requiredColorFormats) {
    TreeMap<Integer, String> candidateCodecs = new TreeMap<Integer, String>();
    SparseIntArray colorPriorities = intArrayToPriorityMap(requiredColorFormats);
    for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
        // Get next codec
        MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
        // Check that this is a decoder
        if (info.isEncoder()) {
            continue;
        }
        // Check if this codec can decode the video in question
        String requiredType = format.getString(MediaFormat.KEY_MIME);
        String[] supportedTypes = info.getSupportedTypes();
        Set<String> typeSet = new HashSet<String>(Arrays.asList(supportedTypes));
        // Check if it can decode to one of the required color formats
        if (typeSet.contains(requiredType)) {
            CodecCapabilities capabilities = info.getCapabilitiesForType(requiredType);
            for (int supportedColorFormat : capabilities.colorFormats) {
                if (colorPriorities.indexOfKey(supportedColorFormat) >= 0) {
                    int priority = colorPriorities.get(supportedColorFormat);
                    candidateCodecs.put(priority, info.getName());
                }
            }
        }
    }
    // Pick the best codec (with the highest color priority)
    if (candidateCodecs.isEmpty()) {
        return null;
    } else {
        String bestCodec = candidateCodecs.firstEntry().getValue();
        try {
            return MediaCodec.createByCodecName(bestCodec);
        } catch (IOException e) {
            throw new RuntimeException("failed to create codec for " + bestCodec, e);
        }
    }
}
Also used : IOException(java.io.IOException) TreeMap(java.util.TreeMap) SparseIntArray(android.util.SparseIntArray) MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) HashSet(java.util.HashSet)

Example 37 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.

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;
}
Also used : SparseIntArray(android.util.SparseIntArray)

Example 38 with SparseIntArray

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;
}
Also used : SparseIntArray(android.util.SparseIntArray) Cursor(android.database.Cursor)

Example 39 with SparseIntArray

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);
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) UserInfo(android.content.pm.UserInfo)

Example 40 with SparseIntArray

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);
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) UserInfo(android.content.pm.UserInfo)

Aggregations

SparseIntArray (android.util.SparseIntArray)367 RemoteException (android.os.RemoteException)40 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)22 Context (android.content.Context)19 IAppOpsCallback (com.android.internal.app.IAppOpsCallback)15 SparseArray (android.util.SparseArray)13 IOException (java.io.IOException)13 HistoryItem (android.os.BatteryStats.HistoryItem)12 UsageView (com.android.settings.graph.UsageView)12 Point (android.graphics.Point)11 Map (java.util.Map)11 UserInfo (android.content.pm.UserInfo)10 Paint (android.graphics.Paint)10 ArraySet (android.util.ArraySet)10 HashSet (java.util.HashSet)9 Cursor (android.database.Cursor)8 NetworkStatsHistory (android.net.NetworkStatsHistory)7 SparseBooleanArray (android.util.SparseBooleanArray)7