Java Code Examples for android.util.ArrayMap#containsKey()

The following examples show how to use android.util.ArrayMap#containsKey() . 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: ConditionProviders.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private Condition[] removeDuplicateConditions(String pkg, Condition[] conditions) {
    if (conditions == null || conditions.length == 0) return null;
    final int N = conditions.length;
    final ArrayMap<Uri, Condition> valid = new ArrayMap<Uri, Condition>(N);
    for (int i = 0; i < N; i++) {
        final Uri id = conditions[i].id;
        if (valid.containsKey(id)) {
            Slog.w(TAG, "Ignoring condition from " + pkg + " for duplicate id: " + id);
            continue;
        }
        valid.put(id, conditions[i]);
    }
    if (valid.size() == 0) return null;
    if (valid.size() == N) return conditions;
    final Condition[] rt = new Condition[valid.size()];
    for (int i = 0; i < rt.length; i++) {
        rt[i] = valid.valueAt(i);
    }
    return rt;
}
 
Example 2
Source File: Transition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * This is called internally once all animations have been set up by the
 * transition hierarchy.
 *
 * @hide
 */
protected void runAnimators() {
    if (DBG) {
        Log.d(LOG_TAG, "runAnimators() on " + this);
    }
    start();
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    // Now start every Animator that was previously created for this transition
    for (Animator anim : mAnimators) {
        if (DBG) {
            Log.d(LOG_TAG, "  anim: " + anim);
        }
        if (runningAnimators.containsKey(anim)) {
            start();
            runAnimator(anim, runningAnimators);
        }
    }
    mAnimators.clear();
    end();
}
 
Example 3
Source File: SyncStorageEngine.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
boolean isAuthorityValid(String authority, int userId) {
    ArrayMap<String, Boolean> authorityMap = mProvidersPerUserCache.get(userId);
    if (authorityMap == null) {
        authorityMap = new ArrayMap<>();
        mProvidersPerUserCache.put(userId, authorityMap);
    }
    if (!authorityMap.containsKey(authority)) {
        authorityMap.put(authority, mPackageManager.resolveContentProviderAsUser(authority,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId) != null);
    }
    return authorityMap.get(authority);
}
 
Example 4
Source File: KeySetManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * addScannedPackageLPw directly modifies the package metadata in  pm.Settings
 * at a point of no-return.  We need to make sure that the scanned package does
 * not contain bad keyset meta-data that could generate an incorrect
 * PackageSetting. Verify that there is a signing keyset, there are no issues
 * with null objects, and the upgrade and defined keysets match.
 *
 * Returns true if the package can safely be added to the keyset metadata.
 */
public void assertScannedPackageValid(PackageParser.Package pkg)
        throws PackageManagerException {
    if (pkg == null || pkg.packageName == null) {
        throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                "Passed invalid package to keyset validation.");
    }
    ArraySet<PublicKey> signingKeys = pkg.mSigningDetails.publicKeys;
    if (signingKeys == null || !(signingKeys.size() > 0) || signingKeys.contains(null)) {
        throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                "Package has invalid signing-key-set.");
    }
    ArrayMap<String, ArraySet<PublicKey>> definedMapping = pkg.mKeySetMapping;
    if (definedMapping != null) {
        if (definedMapping.containsKey(null) || definedMapping.containsValue(null)) {
            throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                    "Package has null defined key set.");
        }
        int defMapSize = definedMapping.size();
        for (int i = 0; i < defMapSize; i++) {
            if (!(definedMapping.valueAt(i).size() > 0)
                    || definedMapping.valueAt(i).contains(null)) {
                throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                        "Package has null/no public keys for defined key-sets.");
            }
        }
    }
    ArraySet<String> upgradeAliases = pkg.mUpgradeKeySets;
    if (upgradeAliases != null) {
        if (definedMapping == null || !(definedMapping.keySet().containsAll(upgradeAliases))) {
            throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                    "Package has upgrade-key-sets without corresponding definitions.");
        }
    }
}
 
Example 5
Source File: SnoozeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
protected void repostGroupSummary(String pkg, int userId, String groupKey) {
    if (mSnoozedNotifications.containsKey(userId)) {
        ArrayMap<String, ArrayMap<String, NotificationRecord>> keysByPackage
                = mSnoozedNotifications.get(userId);

        if (keysByPackage != null && keysByPackage.containsKey(pkg)) {
            ArrayMap<String, NotificationRecord> recordsByKey = keysByPackage.get(pkg);

            if (recordsByKey != null) {
                String groupSummaryKey = null;
                int N = recordsByKey.size();
                for (int i = 0; i < N; i++) {
                    final NotificationRecord potentialGroupSummary = recordsByKey.valueAt(i);
                    if (potentialGroupSummary.sbn.isGroup()
                            && potentialGroupSummary.getNotification().isGroupSummary()
                            && groupKey.equals(potentialGroupSummary.getGroupKey())) {
                        groupSummaryKey = potentialGroupSummary.getKey();
                        break;
                    }
                }

                if (groupSummaryKey != null) {
                    NotificationRecord record = recordsByKey.remove(groupSummaryKey);
                    mPackages.remove(groupSummaryKey);
                    mUsers.remove(groupSummaryKey);

                    if (record != null && !record.isCanceled) {
                        MetricsLogger.action(record.getLogMaker()
                                .setCategory(MetricsProto.MetricsEvent.NOTIFICATION_SNOOZED)
                                .setType(MetricsProto.MetricsEvent.TYPE_OPEN));
                        mCallback.repost(userId, record);
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * A utility to retain only the mappings in {@code nameOverrides} that have a value
 * that has a key in {@code namedViews}. This is a useful equivalent to
 * {@link ArrayMap#retainAll(Collection)} for values.
 */
private static void retainValues(ArrayMap<String, String> nameOverrides,
        ArrayMap<String, View> namedViews) {
    for (int i = nameOverrides.size() - 1; i >= 0; i--) {
        final String targetName = nameOverrides.valueAt(i);
        if (!namedViews.containsKey(targetName)) {
            nameOverrides.removeAt(i);
        }
    }
}
 
Example 7
Source File: SyncAdaptersCache.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public String[] getSyncAdapterPackagesForAuthority(String authority, int userId) {
    synchronized (mServicesLock) {
        ArrayMap<String,String[]> adapterMap = mAuthorityToSyncAdapters.get(userId);
        if (adapterMap == null) {
            adapterMap = new ArrayMap<>();
            mAuthorityToSyncAdapters.put(userId, adapterMap);
        }
        // If the mapping exists, return it
        if (adapterMap.containsKey(authority)) {
            return adapterMap.get(authority);
        }
        // Create the mapping and cache it
        String[] syncAdapterPackages;
        final Collection<RegisteredServicesCache.ServiceInfo<SyncAdapterType>> serviceInfos;
        serviceInfos = getAllServices(userId);
        ArrayList<String> packages = new ArrayList<>();
        for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> serviceInfo : serviceInfos) {
            if (authority.equals(serviceInfo.type.authority)
                    && serviceInfo.componentName != null) {
                packages.add(serviceInfo.componentName.getPackageName());
            }
        }
        syncAdapterPackages = new String[packages.size()];
        packages.toArray(syncAdapterPackages);
        adapterMap.put(authority, syncAdapterPackages);

        return syncAdapterPackages;
    }
}
 
Example 8
Source File: Versatile.java    From Synapse with Apache License 2.0 5 votes vote down vote up
/**
 * Solve TransitionManager leak problem
 */
public static void removeActivityFromTransitionManager(Activity activity) {
    final Class transitionManagerClass = TransitionManager.class;

    try {
        final Field runningTransitionsField = transitionManagerClass.getDeclaredField("sRunningTransitions");

        if (runningTransitionsField == null) {
            return;
        }

        runningTransitionsField.setAccessible(true);

        //noinspection unchecked
        final ThreadLocal<WeakReference<ArrayMap<ViewGroup, ArrayList<Transition>>>> runningTransitions
                = (ThreadLocal<WeakReference<ArrayMap<ViewGroup, ArrayList<Transition>>>>)
                runningTransitionsField.get(transitionManagerClass);

        if (runningTransitions == null
                || runningTransitions.get() == null
                || runningTransitions.get().get() == null) {
            return;
        }

        final ArrayMap map = runningTransitions.get().get();
        final View decorView = activity.getWindow().getDecorView();

        if (map.containsKey(decorView)) {
            map.remove(decorView);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}