Java Code Examples for com.android.internal.util.ArrayUtils#appendInt()

The following examples show how to use com.android.internal.util.ArrayUtils#appendInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RescueParty.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static int[] getAllUserIds() {
    int[] userIds = { UserHandle.USER_SYSTEM };
    try {
        for (File file : FileUtils.listFilesOrEmpty(Environment.getDataSystemDeDirectory())) {
            try {
                final int userId = Integer.parseInt(file.getName());
                if (userId != UserHandle.USER_SYSTEM) {
                    userIds = ArrayUtils.appendInt(userIds, userId);
                }
            } catch (NumberFormatException ignored) {
            }
        }
    } catch (Throwable t) {
        Slog.w(TAG, "Trouble discovering users", t);
    }
    return userIds;
}
 
Example 2
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void unlockUserKey(int userId, int serialNumber, byte[] token, byte[] secret) {
    enforcePermission(android.Manifest.permission.STORAGE_INTERNAL);

    if (StorageManager.isFileEncryptedNativeOrEmulated()) {
        // When a user has secure lock screen, require secret to actually unlock.
        // This check is mostly in place for emulation mode.
        if (mLockPatternUtils.isSecure(userId) && ArrayUtils.isEmpty(secret)) {
            throw new IllegalStateException("Secret required to unlock secure user " + userId);
        }

        try {
            mVold.unlockUserKey(userId, serialNumber, encodeBytes(token),
                    encodeBytes(secret));
        } catch (Exception e) {
            Slog.wtf(TAG, e);
            return;
        }
    }

    synchronized (mLock) {
        mLocalUnlockedUsers = ArrayUtils.appendInt(mLocalUnlockedUsers, userId);
    }
}
 
Example 3
Source File: NetworkStatsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Clean up {@link #mUidRecorder} after user is removed.
 */
@GuardedBy("mStatsLock")
private void removeUserLocked(int userId) {
    if (LOGV) Slog.v(TAG, "removeUserLocked() for userId=" + userId);

    // Build list of UIDs that we should clean up
    int[] uids = new int[0];
    final List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(
            PackageManager.MATCH_ANY_USER
            | PackageManager.MATCH_DISABLED_COMPONENTS);
    for (ApplicationInfo app : apps) {
        final int uid = UserHandle.getUid(userId, app.uid);
        uids = ArrayUtils.appendInt(uids, uid);
    }

    removeUidsLocked(uids);
}
 
Example 4
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void onUnlockUser(int userId) {
    Slog.d(TAG, "onUnlockUser " + userId);

    // We purposefully block here to make sure that user-specific
    // staging area is ready so it's ready for zygote-forked apps to
    // bind mount against.
    try {
        mVold.onUserStarted(userId);
        mStoraged.onUserStarted(userId);
    } catch (Exception e) {
        Slog.wtf(TAG, e);
    }

    // Record user as started so newly mounted volumes kick off events
    // correctly, then synthesize events for any already-mounted volumes.
    synchronized (mLock) {
        for (int i = 0; i < mVolumes.size(); i++) {
            final VolumeInfo vol = mVolumes.valueAt(i);
            if (vol.isVisibleForRead(userId) && vol.isMountedReadable()) {
                final StorageVolume userVol = vol.buildStorageVolume(mContext, userId, false);
                mHandler.obtainMessage(H_VOLUME_BROADCAST, userVol).sendToTarget();

                final String envState = VolumeInfo.getEnvironmentForState(vol.getState());
                mCallbacks.notifyStorageStateChanged(userVol.getPath(), envState, envState);
            }
        }
        mSystemUnlockedUsers = ArrayUtils.appendInt(mSystemUnlockedUsers, userId);
    }
}
 
Example 5
Source File: PermissionsState.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static int[] appendInts(int[] current, int[] added) {
    if (current != null && added != null) {
        for (int guid : added) {
            current = ArrayUtils.appendInt(current, guid);
        }
    }
    return current;
}
 
Example 6
Source File: JobSchedulerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onStartUser(int userHandle) {
    mStartedUsers = ArrayUtils.appendInt(mStartedUsers, userHandle);
    // Let's kick any outstanding jobs for this user.
    mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
}
 
Example 7
Source File: Vpn.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static void applyUnderlyingCapabilities(
        ConnectivityManager cm,
        Network[] underlyingNetworks,
        NetworkCapabilities caps) {
    int[] transportTypes = new int[] { NetworkCapabilities.TRANSPORT_VPN };
    int downKbps = NetworkCapabilities.LINK_BANDWIDTH_UNSPECIFIED;
    int upKbps = NetworkCapabilities.LINK_BANDWIDTH_UNSPECIFIED;
    boolean metered = false;
    boolean roaming = false;
    boolean congested = false;

    boolean hadUnderlyingNetworks = false;
    if (null != underlyingNetworks) {
        for (Network underlying : underlyingNetworks) {
            // TODO(b/124469351): Get capabilities directly from ConnectivityService instead.
            final NetworkCapabilities underlyingCaps = cm.getNetworkCapabilities(underlying);
            if (underlyingCaps == null) continue;
            hadUnderlyingNetworks = true;
            for (int underlyingType : underlyingCaps.getTransportTypes()) {
                transportTypes = ArrayUtils.appendInt(transportTypes, underlyingType);
            }

            // When we have multiple networks, we have to assume the
            // worst-case link speed and restrictions.
            downKbps = NetworkCapabilities.minBandwidth(downKbps,
                    underlyingCaps.getLinkDownstreamBandwidthKbps());
            upKbps = NetworkCapabilities.minBandwidth(upKbps,
                    underlyingCaps.getLinkUpstreamBandwidthKbps());
            metered |= !underlyingCaps.hasCapability(NET_CAPABILITY_NOT_METERED);
            roaming |= !underlyingCaps.hasCapability(NET_CAPABILITY_NOT_ROAMING);
            congested |= !underlyingCaps.hasCapability(NET_CAPABILITY_NOT_CONGESTED);
        }
    }
    if (!hadUnderlyingNetworks) {
        // No idea what the underlying networks are; assume sane defaults
        metered = true;
        roaming = false;
        congested = false;
    }

    caps.setTransportTypes(transportTypes);
    caps.setLinkDownstreamBandwidthKbps(downKbps);
    caps.setLinkUpstreamBandwidthKbps(upKbps);
    caps.setCapability(NET_CAPABILITY_NOT_METERED, !metered);
    caps.setCapability(NET_CAPABILITY_NOT_ROAMING, !roaming);
    caps.setCapability(NET_CAPABILITY_NOT_CONGESTED, !congested);
}