Search in sources :

Example 51 with SparseIntArray

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

the class ExifInterface method getTagInfo.

protected SparseIntArray getTagInfo() {
    if (mTagInfo == null) {
        mTagInfo = new SparseIntArray();
        initTagInfo();
    }
    return mTagInfo;
}
Also used : SparseIntArray(android.util.SparseIntArray)

Example 52 with SparseIntArray

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

the class NetworkManagementService method prepareNativeDaemon.

/**
     * Prepare native daemon once connected, enabling modules and pushing any
     * existing in-memory rules.
     */
private void prepareNativeDaemon() {
    mBandwidthControlEnabled = false;
    // only enable bandwidth control when support exists
    final boolean hasKernelSupport = new File("/proc/net/xt_qtaguid/ctrl").exists();
    if (hasKernelSupport) {
        Slog.d(TAG, "enabling bandwidth control");
        try {
            mConnector.execute("bandwidth", "enable");
            mBandwidthControlEnabled = true;
        } catch (NativeDaemonConnectorException e) {
            Log.wtf(TAG, "problem enabling bandwidth controls", e);
        }
    } else {
        Slog.i(TAG, "not enabling bandwidth control");
    }
    SystemProperties.set(PROP_QTAGUID_ENABLED, mBandwidthControlEnabled ? "1" : "0");
    if (mBandwidthControlEnabled) {
        try {
            getBatteryStats().noteNetworkStatsEnabled();
        } catch (RemoteException e) {
        }
    }
    try {
        mConnector.execute("strict", "enable");
        mStrictEnabled = true;
    } catch (NativeDaemonConnectorException e) {
        Log.wtf(TAG, "Failed strict enable", e);
    }
    // push any existing quota or UID rules
    synchronized (mQuotaLock) {
        setDataSaverModeEnabled(mDataSaverMode);
        int size = mActiveQuotas.size();
        if (size > 0) {
            if (DBG)
                Slog.d(TAG, "Pushing " + size + " active quota rules");
            final HashMap<String, Long> activeQuotas = mActiveQuotas;
            mActiveQuotas = Maps.newHashMap();
            for (Map.Entry<String, Long> entry : activeQuotas.entrySet()) {
                setInterfaceQuota(entry.getKey(), entry.getValue());
            }
        }
        size = mActiveAlerts.size();
        if (size > 0) {
            if (DBG)
                Slog.d(TAG, "Pushing " + size + " active alert rules");
            final HashMap<String, Long> activeAlerts = mActiveAlerts;
            mActiveAlerts = Maps.newHashMap();
            for (Map.Entry<String, Long> entry : activeAlerts.entrySet()) {
                setInterfaceAlert(entry.getKey(), entry.getValue());
            }
        }
        size = mUidRejectOnMetered.size();
        if (size > 0) {
            if (DBG)
                Slog.d(TAG, "Pushing " + size + " UIDs to metered whitelist rules");
            final SparseBooleanArray uidRejectOnQuota = mUidRejectOnMetered;
            mUidRejectOnMetered = new SparseBooleanArray();
            for (int i = 0; i < uidRejectOnQuota.size(); i++) {
                setUidMeteredNetworkBlacklist(uidRejectOnQuota.keyAt(i), uidRejectOnQuota.valueAt(i));
            }
        }
        size = mUidAllowOnMetered.size();
        if (size > 0) {
            if (DBG)
                Slog.d(TAG, "Pushing " + size + " UIDs to metered blacklist rules");
            final SparseBooleanArray uidAcceptOnQuota = mUidAllowOnMetered;
            mUidAllowOnMetered = new SparseBooleanArray();
            for (int i = 0; i < uidAcceptOnQuota.size(); i++) {
                setUidMeteredNetworkWhitelist(uidAcceptOnQuota.keyAt(i), uidAcceptOnQuota.valueAt(i));
            }
        }
        size = mUidCleartextPolicy.size();
        if (size > 0) {
            if (DBG)
                Slog.d(TAG, "Pushing " + size + " active UID cleartext policies");
            final SparseIntArray local = mUidCleartextPolicy;
            mUidCleartextPolicy = new SparseIntArray();
            for (int i = 0; i < local.size(); i++) {
                setUidCleartextNetworkPolicy(local.keyAt(i), local.valueAt(i));
            }
        }
        setFirewallEnabled(mFirewallEnabled || LockdownVpnTracker.isEnabled());
        syncFirewallChainLocked(FIREWALL_CHAIN_NONE, mUidFirewallRules, "");
        syncFirewallChainLocked(FIREWALL_CHAIN_STANDBY, mUidFirewallStandbyRules, "standby ");
        syncFirewallChainLocked(FIREWALL_CHAIN_DOZABLE, mUidFirewallDozableRules, "dozable ");
        syncFirewallChainLocked(FIREWALL_CHAIN_POWERSAVE, mUidFirewallPowerSaveRules, "powersave ");
        if (mFirewallChainStates.get(FIREWALL_CHAIN_STANDBY)) {
            setFirewallChainEnabled(FIREWALL_CHAIN_STANDBY, true);
        }
        if (mFirewallChainStates.get(FIREWALL_CHAIN_DOZABLE)) {
            setFirewallChainEnabled(FIREWALL_CHAIN_DOZABLE, true);
        }
        if (mFirewallChainStates.get(FIREWALL_CHAIN_POWERSAVE)) {
            setFirewallChainEnabled(FIREWALL_CHAIN_POWERSAVE, true);
        }
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) SparseBooleanArray(android.util.SparseBooleanArray) RemoteException(android.os.RemoteException) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 53 with SparseIntArray

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

the class UsageStatsService method getIdleUidsForUser.

int[] getIdleUidsForUser(int userId) {
    if (!mAppIdleEnabled) {
        return new int[0];
    }
    final long elapsedRealtime = SystemClock.elapsedRealtime();
    List<ApplicationInfo> apps;
    try {
        ParceledListSlice<ApplicationInfo> slice = AppGlobals.getPackageManager().getInstalledApplications(/* flags= */
        0, userId);
        if (slice == null) {
            return new int[0];
        }
        apps = slice.getList();
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    // State of each uid.  Key is the uid.  Value lower 16 bits is the number of apps
    // associated with that uid, upper 16 bits is the number of those apps that is idle.
    SparseIntArray uidStates = new SparseIntArray();
    // we find for each uid and how many of those are idle.
    for (int i = apps.size() - 1; i >= 0; i--) {
        ApplicationInfo ai = apps.get(i);
        // Check whether this app is idle.
        boolean idle = isAppIdleFiltered(ai.packageName, UserHandle.getAppId(ai.uid), userId, elapsedRealtime);
        int index = uidStates.indexOfKey(ai.uid);
        if (index < 0) {
            uidStates.put(ai.uid, 1 + (idle ? 1 << 16 : 0));
        } else {
            int value = uidStates.valueAt(index);
            uidStates.setValueAt(index, value + 1 + (idle ? 1 << 16 : 0));
        }
    }
    if (DEBUG) {
        Slog.d(TAG, "getIdleUids took " + (SystemClock.elapsedRealtime() - elapsedRealtime));
    }
    int numIdle = 0;
    for (int i = uidStates.size() - 1; i >= 0; i--) {
        int value = uidStates.valueAt(i);
        if ((value & 0x7fff) == (value >> 16)) {
            numIdle++;
        }
    }
    int[] res = new int[numIdle];
    numIdle = 0;
    for (int i = uidStates.size() - 1; i >= 0; i--) {
        int value = uidStates.valueAt(i);
        if ((value & 0x7fff) == (value >> 16)) {
            res[numIdle] = uidStates.keyAt(i);
            numIdle++;
        }
    }
    return res;
}
Also used : SparseIntArray(android.util.SparseIntArray) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 54 with SparseIntArray

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

the class BatteryStats method dumpHistoryLocked.

private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
    final HistoryPrinter hprinter = new HistoryPrinter();
    final HistoryItem rec = new HistoryItem();
    long lastTime = -1;
    long baseTime = -1;
    boolean printed = false;
    HistoryEventTracker tracker = null;
    while (getNextHistoryLocked(rec)) {
        lastTime = rec.time;
        if (baseTime < 0) {
            baseTime = lastTime;
        }
        if (rec.time >= histStart) {
            if (histStart >= 0 && !printed) {
                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET || rec.cmd == HistoryItem.CMD_START || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
                    printed = true;
                    hprinter.printNextItem(pw, rec, baseTime, checkin, (flags & DUMP_VERBOSE) != 0);
                    rec.cmd = HistoryItem.CMD_UPDATE;
                } else if (rec.currentTime != 0) {
                    printed = true;
                    byte cmd = rec.cmd;
                    rec.cmd = HistoryItem.CMD_CURRENT_TIME;
                    hprinter.printNextItem(pw, rec, baseTime, checkin, (flags & DUMP_VERBOSE) != 0);
                    rec.cmd = cmd;
                }
                if (tracker != null) {
                    if (rec.cmd != HistoryItem.CMD_UPDATE) {
                        hprinter.printNextItem(pw, rec, baseTime, checkin, (flags & DUMP_VERBOSE) != 0);
                        rec.cmd = HistoryItem.CMD_UPDATE;
                    }
                    int oldEventCode = rec.eventCode;
                    HistoryTag oldEventTag = rec.eventTag;
                    rec.eventTag = new HistoryTag();
                    for (int i = 0; i < HistoryItem.EVENT_COUNT; i++) {
                        HashMap<String, SparseIntArray> active = tracker.getStateForEvent(i);
                        if (active == null) {
                            continue;
                        }
                        for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) {
                            SparseIntArray uids = ent.getValue();
                            for (int j = 0; j < uids.size(); j++) {
                                rec.eventCode = i;
                                rec.eventTag.string = ent.getKey();
                                rec.eventTag.uid = uids.keyAt(j);
                                rec.eventTag.poolIdx = uids.valueAt(j);
                                hprinter.printNextItem(pw, rec, baseTime, checkin, (flags & DUMP_VERBOSE) != 0);
                                rec.wakeReasonTag = null;
                                rec.wakelockTag = null;
                            }
                        }
                    }
                    rec.eventCode = oldEventCode;
                    rec.eventTag = oldEventTag;
                    tracker = null;
                }
            }
            hprinter.printNextItem(pw, rec, baseTime, checkin, (flags & DUMP_VERBOSE) != 0);
        } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
            // printing real events.  It doesn't really work right, so is turned off.
            if (tracker == null) {
                tracker = new HistoryEventTracker();
            }
            tracker.updateState(rec.eventCode, rec.eventTag.string, rec.eventTag.uid, rec.eventTag.poolIdx);
        }
    }
    if (histStart >= 0) {
        commitCurrentHistoryBatchLocked();
        pw.print(checkin ? "NEXT: " : "  NEXT: ");
        pw.println(lastTime + 1);
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) HashMap(java.util.HashMap)

Example 55 with SparseIntArray

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

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)

Aggregations

SparseIntArray (android.util.SparseIntArray)249 RemoteException (android.os.RemoteException)40 ArrayList (java.util.ArrayList)28 HashMap (java.util.HashMap)20 IAppOpsCallback (com.android.internal.app.IAppOpsCallback)15 IOException (java.io.IOException)12 Point (android.graphics.Point)11 SparseArray (android.util.SparseArray)11 UserInfo (android.content.pm.UserInfo)10 ArraySet (android.util.ArraySet)10 Map (java.util.Map)10 HashSet (java.util.HashSet)9 Cursor (android.database.Cursor)8 View (android.view.View)7 SparseBooleanArray (android.util.SparseBooleanArray)6 ActivityManager (android.app.ActivityManager)5 Context (android.content.Context)5 ActivityInfo (android.content.pm.ActivityInfo)5 Configuration (android.content.res.Configuration)5 Resources (android.content.res.Resources)5