Search in sources :

Example 81 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 82 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 83 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)

Example 84 with SparseIntArray

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

the class NetworkManagementService method setFirewallUidRules.

@Override
public void setFirewallUidRules(int chain, int[] uids, int[] rules) {
    enforceSystemUid();
    synchronized (mQuotaLock) {
        SparseIntArray uidFirewallRules = getUidFirewallRules(chain);
        SparseIntArray newRules = new SparseIntArray();
        // apply new set of rules
        for (int index = uids.length - 1; index >= 0; --index) {
            int uid = uids[index];
            int rule = rules[index];
            updateFirewallUidRuleLocked(chain, uid, rule);
            newRules.put(uid, rule);
        }
        // collect the rules to remove.
        SparseIntArray rulesToRemove = new SparseIntArray();
        for (int index = uidFirewallRules.size() - 1; index >= 0; --index) {
            int uid = uidFirewallRules.keyAt(index);
            if (newRules.indexOfKey(uid) < 0) {
                rulesToRemove.put(uid, FIREWALL_RULE_DEFAULT);
            }
        }
        // remove dead rules
        for (int index = rulesToRemove.size() - 1; index >= 0; --index) {
            int uid = rulesToRemove.keyAt(index);
            updateFirewallUidRuleLocked(chain, uid, FIREWALL_RULE_DEFAULT);
        }
        try {
            switch(chain) {
                case FIREWALL_CHAIN_DOZABLE:
                    mNetdService.firewallReplaceUidChain("fw_dozable", true, uids);
                    break;
                case FIREWALL_CHAIN_STANDBY:
                    mNetdService.firewallReplaceUidChain("fw_standby", false, uids);
                    break;
                case FIREWALL_CHAIN_POWERSAVE:
                    mNetdService.firewallReplaceUidChain("fw_powersave", true, uids);
                    break;
                case FIREWALL_CHAIN_NONE:
                default:
                    Slog.d(TAG, "setFirewallUidRules() called on invalid chain: " + chain);
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Error flushing firewall chain " + chain, e);
        }
    }
}
Also used : SparseIntArray(android.util.SparseIntArray) RemoteException(android.os.RemoteException)

Example 85 with SparseIntArray

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

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)

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