Search in sources :

Example 56 with SparseBooleanArray

use of android.util.SparseBooleanArray in project platform_frameworks_base by android.

the class NetworkPolicyManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    mContext.enforceCallingOrSelfPermission(DUMP, TAG);
    final IndentingPrintWriter fout = new IndentingPrintWriter(writer, "  ");
    final ArraySet<String> argSet = new ArraySet<String>(args.length);
    for (String arg : args) {
        argSet.add(arg);
    }
    synchronized (mUidRulesFirstLock) {
        synchronized (mNetworkPoliciesSecondLock) {
            if (argSet.contains("--unsnooze")) {
                for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
                    mNetworkPolicy.valueAt(i).clearSnooze();
                }
                normalizePoliciesNL();
                updateNetworkEnabledNL();
                updateNetworkRulesNL();
                updateNotificationsNL();
                writePolicyAL();
                fout.println("Cleared snooze timestamps");
                return;
            }
            fout.print("System ready: ");
            fout.println(mSystemReady);
            fout.print("Restrict background: ");
            fout.println(mRestrictBackground);
            fout.print("Restrict power: ");
            fout.println(mRestrictPower);
            fout.print("Device idle: ");
            fout.println(mDeviceIdleMode);
            fout.println("Network policies:");
            fout.increaseIndent();
            for (int i = 0; i < mNetworkPolicy.size(); i++) {
                fout.println(mNetworkPolicy.valueAt(i).toString());
            }
            fout.decreaseIndent();
            fout.print("Metered ifaces: ");
            fout.println(String.valueOf(mMeteredIfaces));
            fout.println("Policy for UIDs:");
            fout.increaseIndent();
            int size = mUidPolicy.size();
            for (int i = 0; i < size; i++) {
                final int uid = mUidPolicy.keyAt(i);
                final int policy = mUidPolicy.valueAt(i);
                fout.print("UID=");
                fout.print(uid);
                fout.print(" policy=");
                fout.print(DebugUtils.flagsToString(NetworkPolicyManager.class, "POLICY_", policy));
                fout.println();
            }
            fout.decreaseIndent();
            size = mPowerSaveWhitelistExceptIdleAppIds.size();
            if (size > 0) {
                fout.println("Power save whitelist (except idle) app ids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mPowerSaveWhitelistExceptIdleAppIds.keyAt(i));
                    fout.print(": ");
                    fout.print(mPowerSaveWhitelistExceptIdleAppIds.valueAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mPowerSaveWhitelistAppIds.size();
            if (size > 0) {
                fout.println("Power save whitelist app ids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mPowerSaveWhitelistAppIds.keyAt(i));
                    fout.print(": ");
                    fout.print(mPowerSaveWhitelistAppIds.valueAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mRestrictBackgroundWhitelistUids.size();
            if (size > 0) {
                fout.println("Restrict background whitelist uids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mRestrictBackgroundWhitelistUids.keyAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mDefaultRestrictBackgroundWhitelistUids.size();
            if (size > 0) {
                fout.println("Default restrict background whitelist uids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mDefaultRestrictBackgroundWhitelistUids.keyAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mRestrictBackgroundWhitelistRevokedUids.size();
            if (size > 0) {
                fout.println("Default restrict background whitelist uids revoked by users:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mRestrictBackgroundWhitelistRevokedUids.keyAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            final SparseBooleanArray knownUids = new SparseBooleanArray();
            collectKeys(mUidState, knownUids);
            collectKeys(mUidRules, knownUids);
            fout.println("Status for all known UIDs:");
            fout.increaseIndent();
            size = knownUids.size();
            for (int i = 0; i < size; i++) {
                final int uid = knownUids.keyAt(i);
                fout.print("UID=");
                fout.print(uid);
                final int state = mUidState.get(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
                fout.print(" state=");
                fout.print(state);
                if (state <= ActivityManager.PROCESS_STATE_TOP) {
                    fout.print(" (fg)");
                } else {
                    fout.print(state <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE ? " (fg svc)" : " (bg)");
                }
                final int uidRules = mUidRules.get(uid, RULE_NONE);
                fout.print(" rules=");
                fout.print(uidRulesToString(uidRules));
                fout.println();
            }
            fout.decreaseIndent();
            fout.println("Status for just UIDs with rules:");
            fout.increaseIndent();
            size = mUidRules.size();
            for (int i = 0; i < size; i++) {
                final int uid = mUidRules.keyAt(i);
                fout.print("UID=");
                fout.print(uid);
                final int uidRules = mUidRules.get(uid, RULE_NONE);
                fout.print(" rules=");
                fout.print(uidRulesToString(uidRules));
                fout.println();
            }
            fout.decreaseIndent();
        }
    }
}
Also used : ArraySet(android.util.ArraySet) NetworkPolicyManager(android.net.NetworkPolicyManager) INetworkPolicyManager(android.net.INetworkPolicyManager) SparseBooleanArray(android.util.SparseBooleanArray) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 57 with SparseBooleanArray

use of android.util.SparseBooleanArray in project platform_frameworks_base by android.

the class PermissionsState method updatePermissionFlags.

/**
     * Update the flags associated with a given permission.
     * @param permission The permission whose flags to update.
     * @param userId The user for which to update.
     * @param flagMask Mask for which flags to change.
     * @param flagValues New values for the mask flags.
     * @return Whether the permission flags changed.
     */
public boolean updatePermissionFlags(BasePermission permission, int userId, int flagMask, int flagValues) {
    enforceValidUserId(userId);
    final boolean mayChangeFlags = flagValues != 0 || flagMask != 0;
    if (mPermissions == null) {
        if (!mayChangeFlags) {
            return false;
        }
        ensurePermissionData(permission);
    }
    PermissionData permissionData = mPermissions.get(permission.name);
    if (permissionData == null) {
        if (!mayChangeFlags) {
            return false;
        }
        permissionData = ensurePermissionData(permission);
    }
    final int oldFlags = permissionData.getFlags(userId);
    final boolean updated = permissionData.updateFlags(userId, flagMask, flagValues);
    if (updated) {
        final int newFlags = permissionData.getFlags(userId);
        if ((oldFlags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) == 0 && (newFlags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) != 0) {
            if (mPermissionReviewRequired == null) {
                mPermissionReviewRequired = new SparseBooleanArray();
            }
            mPermissionReviewRequired.put(userId, true);
        } else if ((oldFlags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) != 0 && (newFlags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) == 0) {
            if (mPermissionReviewRequired != null) {
                mPermissionReviewRequired.delete(userId);
                if (mPermissionReviewRequired.size() <= 0) {
                    mPermissionReviewRequired = null;
                }
            }
        }
    }
    return updated;
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray)

Example 58 with SparseBooleanArray

use of android.util.SparseBooleanArray in project platform_frameworks_base by android.

the class PermissionsState method copyFrom.

/**
     * Initialized this instance from another one.
     *
     * @param other The other instance.
     */
public void copyFrom(PermissionsState other) {
    if (other == this) {
        return;
    }
    if (mPermissions != null) {
        if (other.mPermissions == null) {
            mPermissions = null;
        } else {
            mPermissions.clear();
        }
    }
    if (other.mPermissions != null) {
        if (mPermissions == null) {
            mPermissions = new ArrayMap<>();
        }
        final int permissionCount = other.mPermissions.size();
        for (int i = 0; i < permissionCount; i++) {
            String name = other.mPermissions.keyAt(i);
            PermissionData permissionData = other.mPermissions.valueAt(i);
            mPermissions.put(name, new PermissionData(permissionData));
        }
    }
    mGlobalGids = NO_GIDS;
    if (other.mGlobalGids != NO_GIDS) {
        mGlobalGids = Arrays.copyOf(other.mGlobalGids, other.mGlobalGids.length);
    }
    if (mPermissionReviewRequired != null) {
        if (other.mPermissionReviewRequired == null) {
            mPermissionReviewRequired = null;
        } else {
            mPermissionReviewRequired.clear();
        }
    }
    if (other.mPermissionReviewRequired != null) {
        if (mPermissionReviewRequired == null) {
            mPermissionReviewRequired = new SparseBooleanArray();
        }
        final int userCount = other.mPermissionReviewRequired.size();
        for (int i = 0; i < userCount; i++) {
            final boolean reviewRequired = other.mPermissionReviewRequired.valueAt(i);
            mPermissionReviewRequired.put(i, reviewRequired);
        }
    }
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray)

Example 59 with SparseBooleanArray

use of android.util.SparseBooleanArray in project platform_frameworks_base by android.

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 60 with SparseBooleanArray

use of android.util.SparseBooleanArray in project platform_frameworks_base by android.

the class AccountManagerService method getUidsOfInstalledOrUpdatedPackagesAsUser.

private SparseBooleanArray getUidsOfInstalledOrUpdatedPackagesAsUser(int userId) {
    // Get the UIDs of all apps that might have data on the device. We want
    // to preserve user data if the app might otherwise be storing data.
    List<PackageInfo> pkgsWithData = mPackageManager.getInstalledPackagesAsUser(PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
    SparseBooleanArray knownUids = new SparseBooleanArray(pkgsWithData.size());
    for (PackageInfo pkgInfo : pkgsWithData) {
        if (pkgInfo.applicationInfo != null && (pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
            knownUids.put(pkgInfo.applicationInfo.uid, true);
        }
    }
    return knownUids;
}
Also used : PackageInfo(android.content.pm.PackageInfo) SparseBooleanArray(android.util.SparseBooleanArray)

Aggregations

SparseBooleanArray (android.util.SparseBooleanArray)283 ArrayList (java.util.ArrayList)43 View (android.view.View)32 Selection (com.android.documentsui.dirlist.MultiSelectManager.Selection)30 Point (android.graphics.Point)28 ViewGroup (android.view.ViewGroup)20 ListView (android.widget.ListView)15 HashMap (java.util.HashMap)15 Paint (android.graphics.Paint)13 Intent (android.content.Intent)11 Map (java.util.Map)11 File (java.io.File)10 SparseArray (android.util.SparseArray)8 SuppressLint (android.annotation.SuppressLint)7 SparseIntArray (android.util.SparseIntArray)7 AdapterView (android.widget.AdapterView)7 Cursor (android.database.Cursor)6 ActionMenuChildView (com.actionbarsherlock.internal.view.menu.ActionMenuView.ActionMenuChildView)6 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)6 List (java.util.List)6