Search in sources :

Example 41 with SparseIntArray

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

the class TableRow method mapIndexAndColumns.

private void mapIndexAndColumns() {
    if (mColumnToChildIndex == null) {
        int virtualCount = 0;
        final int count = getChildCount();
        mColumnToChildIndex = new SparseIntArray();
        final SparseIntArray columnToChild = mColumnToChildIndex;
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            final LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
            if (layoutParams.column >= virtualCount) {
                virtualCount = layoutParams.column;
            }
            for (int j = 0; j < layoutParams.span; j++) {
                columnToChild.put(virtualCount++, i);
            }
        }
        mNumColumns = virtualCount;
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) View(android.view.View)

Example 42 with SparseIntArray

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

the class ExifInterface method getTagDefinitionsForTagId.

protected int[] getTagDefinitionsForTagId(short tagId) {
    int[] ifds = IfdData.getIfds();
    int[] defs = new int[ifds.length];
    int counter = 0;
    SparseIntArray infos = getTagInfo();
    for (int i : ifds) {
        int def = defineTag(i, tagId);
        if (infos.get(def) != DEFINITION_NULL) {
            defs[counter++] = def;
        }
    }
    if (counter == 0) {
        return null;
    }
    return Arrays.copyOfRange(defs, 0, counter);
}
Also used : SparseIntArray(android.util.SparseIntArray)

Example 43 with SparseIntArray

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

the class ExifInterface method getTagInfo.

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

Example 44 with SparseIntArray

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

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 45 with SparseIntArray

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

the class NetworkManagementService method closeSocketsForFirewallChainLocked.

private void closeSocketsForFirewallChainLocked(int chain, String chainName) {
    // UID ranges to close sockets on.
    UidRange[] ranges;
    // UID ranges whose sockets we won't touch.
    int[] exemptUids;
    final SparseIntArray rules = getUidFirewallRules(chain);
    int numUids = 0;
    if (getFirewallType(chain) == FIREWALL_TYPE_WHITELIST) {
        // Close all sockets on all non-system UIDs...
        ranges = new UidRange[] { // specify their ranges here.
        new UidRange(Process.FIRST_APPLICATION_UID, Integer.MAX_VALUE) };
        // ... except for the UIDs that have allow rules.
        exemptUids = new int[rules.size()];
        for (int i = 0; i < exemptUids.length; i++) {
            if (rules.valueAt(i) == NetworkPolicyManager.FIREWALL_RULE_ALLOW) {
                exemptUids[numUids] = rules.keyAt(i);
                numUids++;
            }
        }
        // fix setFirewallEnabled to grab mQuotaLock and clear rules.
        if (numUids != exemptUids.length) {
            exemptUids = Arrays.copyOf(exemptUids, numUids);
        }
    } else {
        // Close sockets for every UID that has a deny rule...
        ranges = new UidRange[rules.size()];
        for (int i = 0; i < ranges.length; i++) {
            if (rules.valueAt(i) == NetworkPolicyManager.FIREWALL_RULE_DENY) {
                int uid = rules.keyAt(i);
                ranges[numUids] = new UidRange(uid, uid);
                numUids++;
            }
        }
        // As above; usually numUids == ranges.length, but not always.
        if (numUids != ranges.length) {
            ranges = Arrays.copyOf(ranges, numUids);
        }
        // ... with no exceptions.
        exemptUids = new int[0];
    }
    try {
        mNetdService.socketDestroy(ranges, exemptUids);
    } catch (RemoteException | ServiceSpecificException e) {
        Slog.e(TAG, "Error closing sockets after enabling chain " + chainName + ": " + e);
    }
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) UidRange(android.net.UidRange) SparseIntArray(android.util.SparseIntArray) RemoteException(android.os.RemoteException)

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