Search in sources :

Example 81 with ArraySet

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

the class KeySetManagerServiceTest method testAddDefinedKSToPackageOrthoUpgr.

/* upgrd defined keyset ortho (make sure previous is removed for pkg) */
public void testAddDefinedKSToPackageOrthoUpgr() throws ReflectiveOperationException {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add */
    ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
    ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys.add(keyA);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    /* now upgrade to different defined key-set */
    keys = new ArraySet<PublicKey>();
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    keys.add(keyB);
    definedKS.remove("aliasA");
    definedKS.put("aliasB", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 2));
    assertEquals(keyB, KeySetUtils.getPubKey(mKsms, 2));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    ArraySet<Long> mapping = ksMapping.get(2);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(2)));
    assertNull(ps.keySetData.getAliases().get("aliasA"));
    assertNotNull(ps.keySetData.getAliases().get("aliasB"));
    assertEquals(new Long(2), ps.keySetData.getAliases().get("aliasB"));
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 82 with ArraySet

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

the class KeySetManagerServiceTest method testAddUpgradeKSToPackageWrong.

/* add upgrade keyset for non-existing defined and check that it compains */
public void testAddUpgradeKSToPackageWrong() {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add and try to specify bogus upgrade keyset */
    ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
    ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    keys.add(keyA);
    definedKS.put("aliasA", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    ArraySet<String> upgradeKS = new ArraySet<String>();
    upgradeKS.add("aliasB");
    try {
        mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
    } catch (IllegalArgumentException e) {
        /* should have been caught in packagemanager, so exception thrown */
        return;
    }
    fail("Expected IllegalArgumentException when adding undefined upgrade keyset!!");
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 83 with ArraySet

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

the class UserController method dispatchUserSwitch.

void dispatchUserSwitch(final UserState uss, final int oldUserId, final int newUserId) {
    Slog.d(TAG, "Dispatch onUserSwitching oldUser #" + oldUserId + " newUser #" + newUserId);
    final int observerCount = mUserSwitchObservers.beginBroadcast();
    if (observerCount > 0) {
        final ArraySet<String> curWaitingUserSwitchCallbacks = new ArraySet<>();
        synchronized (mService) {
            uss.switching = true;
            mCurWaitingUserSwitchCallbacks = curWaitingUserSwitchCallbacks;
        }
        final AtomicInteger waitingCallbacksCount = new AtomicInteger(observerCount);
        final long dispatchStartedTime = SystemClock.elapsedRealtime();
        for (int i = 0; i < observerCount; i++) {
            try {
                // Prepend with unique prefix to guarantee that keys are unique
                final String name = "#" + i + " " + mUserSwitchObservers.getBroadcastCookie(i);
                synchronized (mService) {
                    curWaitingUserSwitchCallbacks.add(name);
                }
                final IRemoteCallback callback = new IRemoteCallback.Stub() {

                    @Override
                    public void sendResult(Bundle data) throws RemoteException {
                        synchronized (mService) {
                            long delay = SystemClock.elapsedRealtime() - dispatchStartedTime;
                            if (delay > USER_SWITCH_TIMEOUT) {
                                Slog.wtf(TAG, "User switch timeout: observer " + name + " sent result after " + delay + " ms");
                            }
                            // Early return if this session is no longer valid
                            if (curWaitingUserSwitchCallbacks != mCurWaitingUserSwitchCallbacks) {
                                return;
                            }
                            curWaitingUserSwitchCallbacks.remove(name);
                            // Continue switching if all callbacks have been notified
                            if (waitingCallbacksCount.decrementAndGet() == 0) {
                                sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
                            }
                        }
                    }
                };
                mUserSwitchObservers.getBroadcastItem(i).onUserSwitching(newUserId, callback);
            } catch (RemoteException e) {
            }
        }
    } else {
        synchronized (mService) {
            sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
        }
    }
    mUserSwitchObservers.finishBroadcast();
}
Also used : ArraySet(android.util.ArraySet) IRemoteCallback(android.os.IRemoteCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Bundle(android.os.Bundle) RemoteException(android.os.RemoteException)

Example 84 with ArraySet

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

the class Vpn method createUserAndRestrictedProfilesRanges.

/**
     * Creates a {@link Set} of non-intersecting {@link UidRange} objects including all UIDs
     * associated with one user, and any restricted profiles attached to that user.
     *
     * <p>If one of {@param allowedApplications} or {@param disallowedApplications} is provided,
     * the UID ranges will match the app whitelist or blacklist specified there. Otherwise, all UIDs
     * in each user and profile will be included.
     *
     * @param userHandle The userId to create UID ranges for along with any of its restricted
     *                   profiles.
     * @param allowedApplications (optional) whitelist of applications to include.
     * @param disallowedApplications (optional) blacklist of applications to exclude.
     */
@VisibleForTesting
Set<UidRange> createUserAndRestrictedProfilesRanges(@UserIdInt int userHandle, @Nullable List<String> allowedApplications, @Nullable List<String> disallowedApplications) {
    final Set<UidRange> ranges = new ArraySet<>();
    // Assign the top-level user to the set of ranges
    addUserToRanges(ranges, userHandle, allowedApplications, disallowedApplications);
    // If the user can have restricted profiles, assign all its restricted profiles too
    if (canHaveRestrictedProfile(userHandle)) {
        final long token = Binder.clearCallingIdentity();
        List<UserInfo> users;
        try {
            users = UserManager.get(mContext).getUsers(true);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        for (UserInfo user : users) {
            if (user.isRestricted() && (user.restrictedProfileParentId == userHandle)) {
                addUserToRanges(ranges, user.id, allowedApplications, disallowedApplications);
            }
        }
    }
    return ranges;
}
Also used : ArraySet(android.util.ArraySet) UidRange(android.net.UidRange) UserInfo(android.content.pm.UserInfo) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 85 with ArraySet

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

the class KeySetManagerServiceTest method testRemoveAppKSDataDup.

/* remove package and validate that keysets remain if defined elsewhere but
     * have refcounts decreased. */
public void testRemoveAppKSDataDup() throws ReflectiveOperationException {
    /* create PackageSettings and add to Settings mPackages */
    PackageSetting ps1 = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps1.name, ps1);
    PackageSetting ps2 = generateFakePackageSetting("packageB");
    mPackagesMap.put(ps2.name, ps2);
    /* collect signing key and add for both packages */
    ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    signingKeys.add(keyA);
    mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
    mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys);
    /* remove references from first package */
    mKsms.removeAppKeySetDataLPw(ps1.name);
    assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    assertEquals(PackageKeySetData.KEYSET_UNASSIGNED, ps1.keySetData.getProperSigningKeySet());
    assertEquals(1, ps2.keySetData.getProperSigningKeySet());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey)

Aggregations

ArraySet (android.util.ArraySet)521 PublicKey (java.security.PublicKey)94 ArrayList (java.util.ArrayList)87 ComponentName (android.content.ComponentName)82 ArrayMap (android.util.ArrayMap)73 Pair (android.util.Pair)47 RemoteException (android.os.RemoteException)43 ResolveInfo (android.content.pm.ResolveInfo)39 Intent (android.content.Intent)38 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)35 File (java.io.File)33 SSLContext (javax.net.ssl.SSLContext)32 IOException (java.io.IOException)31 PackageManager (android.content.pm.PackageManager)29 UserInfo (android.content.pm.UserInfo)28 ApplicationInfo (android.content.pm.ApplicationInfo)24 Point (android.graphics.Point)24 X509Certificate (java.security.cert.X509Certificate)20 PackageInfo (android.content.pm.PackageInfo)19 Test (org.junit.Test)19