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

The following examples show how to use android.util.ArrayMap#remove() . 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: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteSharedPreferences(String name) {
    synchronized (ContextImpl.class) {
        final File prefs = getSharedPreferencesPath(name);
        final File prefsBackup = SharedPreferencesImpl.makeBackupFile(prefs);

        // Evict any in-memory caches
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        cache.remove(prefs);

        prefs.delete();
        prefsBackup.delete();

        // We failed if files are still lingering
        return !(prefs.exists() || prefsBackup.exists());
    }
}
 
Example 2
Source File: LayoutInflaterCompat.java    From Neptune with Apache License 2.0 6 votes vote down vote up
/**
 * 处理Fragment的缓存
 */
private void resetFragmentClassMap(Context context, String fname) {
    if (isSupportFragmentClass(context, fname)) {
        resetSupportFragmentClassMap(context, fname);
        return;
    }

    ArrayMap<String, Class<?>> classMap = getFragmentClassMap();
    if (classMap != null) {
        Class<?> clazz = classMap.get(fname);
        if (clazz != null && !verifyClassLoader(context, clazz)) {
            PluginDebugLog.runtimeFormatLog(TAG, "find same app fragment class name in LayoutInflater cache and remove it %s", fname);
            clazz = null;
            classMap.remove(fname);
        }
    }
}
 
Example 3
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteSharedPreferences(String name) {
    synchronized (ContextImpl.class) {
        final File prefs = getSharedPreferencesPath(name);
        final File prefsBackup = SharedPreferencesImpl.makeBackupFile(prefs);

        // Evict any in-memory caches
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        cache.remove(prefs);

        prefs.delete();
        prefsBackup.delete();

        // We failed if files are still lingering
        return !(prefs.exists() || prefsBackup.exists());
    }
}
 
Example 4
Source File: ContentObserverController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void detachLocked() {
    final int N = mMyObservers.size();
    for (int i=0; i<N; i++) {
        final ObserverInstance obs = mMyObservers.get(i);
        obs.mJobs.remove(this);
        if (obs.mJobs.size() == 0) {
            if (DEBUG) {
                Slog.i(TAG, "Unregistering observer " + obs + " for " + obs.mUri.getUri());
            }
            mContext.getContentResolver().unregisterContentObserver(obs);
            ArrayMap<JobInfo.TriggerContentUri, ObserverInstance> observerOfUser =
                    mObservers.get(obs.mUserId);
            if (observerOfUser !=  null) {
                observerOfUser.remove(obs.mUri);
            }
        }
    }
}
 
Example 5
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteSharedPreferences(String name) {
    synchronized (ContextImpl.class) {
        final File prefs = getSharedPreferencesPath(name);
        final File prefsBackup = SharedPreferencesImpl.makeBackupFile(prefs);

        // Evict any in-memory caches
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        cache.remove(prefs);

        prefs.delete();
        prefsBackup.delete();

        // We failed if files are still lingering
        return !(prefs.exists() || prefsBackup.exists());
    }
}
 
Example 6
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
    synchronized (ContextImpl.class) {
        final File source = sourceContext.getSharedPreferencesPath(name);
        final File target = getSharedPreferencesPath(name);

        final int res = moveFiles(source.getParentFile(), target.getParentFile(),
                source.getName());
        if (res > 0) {
            // We moved at least one file, so evict any in-memory caches for
            // either location
            final ArrayMap<File, SharedPreferencesImpl> cache =
                    getSharedPreferencesCacheLocked();
            cache.remove(source);
            cache.remove(target);
        }
        return res != -1;
    }
}
 
Example 7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteSharedPreferences(String name) {
    synchronized (ContextImpl.class) {
        final File prefs = getSharedPreferencesPath(name);
        final File prefsBackup = SharedPreferencesImpl.makeBackupFile(prefs);

        // Evict any in-memory caches
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        cache.remove(prefs);

        prefs.delete();
        prefsBackup.delete();

        // We failed if files are still lingering
        return !(prefs.exists() || prefsBackup.exists());
    }
}
 
Example 8
Source File: Transition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Match start/end values by Adapter view ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startIds and endIds as a guide for which Views have unique IDs.
 */
private void matchIds(ArrayMap<View, TransitionValues> unmatchedStart,
        ArrayMap<View, TransitionValues> unmatchedEnd,
        SparseArray<View> startIds, SparseArray<View> endIds) {
    int numStartIds = startIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endIds.get(startIds.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}
 
Example 9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
    synchronized (ContextImpl.class) {
        final File source = sourceContext.getSharedPreferencesPath(name);
        final File target = getSharedPreferencesPath(name);

        final int res = moveFiles(source.getParentFile(), target.getParentFile(),
                source.getName());
        if (res > 0) {
            // We moved at least one file, so evict any in-memory caches for
            // either location
            final ArrayMap<File, SharedPreferencesImpl> cache =
                    getSharedPreferencesCacheLocked();
            cache.remove(source);
            cache.remove(target);
        }
        return res != -1;
    }
}
 
Example 10
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteSharedPreferences(String name) {
    synchronized (ContextImpl.class) {
        final File prefs = getSharedPreferencesPath(name);
        final File prefsBackup = SharedPreferencesImpl.makeBackupFile(prefs);

        // Evict any in-memory caches
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        cache.remove(prefs);

        prefs.delete();
        prefsBackup.delete();

        // We failed if files are still lingering
        return !(prefs.exists() || prefsBackup.exists());
    }
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
    synchronized (ContextImpl.class) {
        final File source = sourceContext.getSharedPreferencesPath(name);
        final File target = getSharedPreferencesPath(name);

        final int res = moveFiles(source.getParentFile(), target.getParentFile(),
                source.getName());
        if (res > 0) {
            // We moved at least one file, so evict any in-memory caches for
            // either location
            final ArrayMap<File, SharedPreferencesImpl> cache =
                    getSharedPreferencesCacheLocked();
            cache.remove(source);
            cache.remove(target);
        }
        return res != -1;
    }
}
 
Example 12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteSharedPreferences(String name) {
    synchronized (ContextImpl.class) {
        final File prefs = getSharedPreferencesPath(name);
        final File prefsBackup = SharedPreferencesImpl.makeBackupFile(prefs);

        // Evict any in-memory caches
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        cache.remove(prefs);

        prefs.delete();
        prefsBackup.delete();

        // We failed if files are still lingering
        return !(prefs.exists() || prefsBackup.exists());
    }
}
 
Example 13
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void pruneOp(Op op, int uid, String packageName) {
    if (!op.hasAnyTime()) {
        Ops ops = getOpsRawLocked(uid, packageName, false /* edit */,
                false /* uidMismatchExpected */);
        if (ops != null) {
            ops.remove(op.op);
            if (ops.size() <= 0) {
                UidState uidState = ops.uidState;
                ArrayMap<String, Ops> pkgOps = uidState.pkgOps;
                if (pkgOps != null) {
                    pkgOps.remove(ops.packageName);
                    if (pkgOps.isEmpty()) {
                        uidState.pkgOps = null;
                    }
                    if (uidState.isDefault()) {
                        mUidStates.remove(uid);
                    }
                }
            }
        }
    }
}
 
Example 14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
    synchronized (ContextImpl.class) {
        final File source = sourceContext.getSharedPreferencesPath(name);
        final File target = getSharedPreferencesPath(name);

        final int res = moveFiles(source.getParentFile(), target.getParentFile(),
                source.getName());
        if (res > 0) {
            // We moved at least one file, so evict any in-memory caches for
            // either location
            final ArrayMap<File, SharedPreferencesImpl> cache =
                    getSharedPreferencesCacheLocked();
            cache.remove(source);
            cache.remove(target);
        }
        return res != -1;
    }
}
 
Example 15
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 16
Source File: IntentResolver.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private final void remove_all_objects(ArrayMap<String, F[]> map, String name,
        Object object) {
    F[] array = map.get(name);
    if (array != null) {
        int LAST = array.length-1;
        while (LAST >= 0 && array[LAST] == null) {
            LAST--;
        }
        for (int idx=LAST; idx>=0; idx--) {
            if (array[idx] == object) {
                final int remain = LAST - idx;
                if (remain > 0) {
                    System.arraycopy(array, idx+1, array, idx, remain);
                }
                array[LAST] = null;
                LAST--;
            }
        }
        if (LAST < 0) {
            map.remove(name);
        } else if (LAST < (array.length/2)) {
            F[] newa = newArray(LAST+2);
            System.arraycopy(array, 0, newa, 0, LAST+1);
            map.put(name, newa);
        }
    }
}
 
Example 17
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();
    }
}
 
Example 18
Source File: IntentResolver.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private final void remove_all_objects(ArrayMap<String, F[]> map, String name,
        Object object) {
    F[] array = map.get(name);
    if (array != null) {
        int LAST = array.length-1;
        while (LAST >= 0 && array[LAST] == null) {
            LAST--;
        }
        for (int idx=LAST; idx>=0; idx--) {
            if (array[idx] == object) {
                final int remain = LAST - idx;
                if (remain > 0) {
                    System.arraycopy(array, idx+1, array, idx, remain);
                }
                array[LAST] = null;
                LAST--;
            }
        }
        if (LAST < 0) {
            map.remove(name);
        } else if (LAST < (array.length/2)) {
            F[] newa = newArray(LAST+2);
            System.arraycopy(array, 0, newa, 0, LAST+1);
            map.put(name, newa);
        }
    }
}
 
Example 19
Source File: Transition.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Match start/end values by View instance. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd.
 */
private void matchInstances(ArrayMap<View, TransitionValues> unmatchedStart,
        ArrayMap<View, TransitionValues> unmatchedEnd) {
    for (int i = unmatchedStart.size() - 1; i >= 0; i--) {
        View view = unmatchedStart.keyAt(i);
        if (view != null && isValidTarget(view)) {
            TransitionValues end = unmatchedEnd.remove(view);
            if (end != null && end.view != null && isValidTarget(end.view)) {
                TransitionValues start = unmatchedStart.removeAt(i);
                mStartValuesList.add(start);
                mEndValuesList.add(end);
            }
        }
    }
}
 
Example 20
Source File: FragmentTransition.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Finds the shared elements in the outgoing fragment. It also calls
 * {@link SharedElementCallback#onMapSharedElements(List, Map)} to allow more control
 * of the shared element mapping. {@code nameOverrides} is updated to match the
 * actual transition name of the mapped shared elements.
 *
 * @param nameOverrides A map of the shared element names from the starting fragment to
 *                      the final fragment's Views as given in
 *                      {@link FragmentTransaction#addSharedElement(View, String)}.
 * @param sharedElementTransition The shared element transition
 * @param fragments A structure holding the transitioning fragments in this container.
 * @return The mapping of shared element names to the Views in the hierarchy or null
 * if there is no shared element transition.
 */
private static ArrayMap<String, View> captureOutSharedElements(
        ArrayMap<String, String> nameOverrides, TransitionSet sharedElementTransition,
        FragmentContainerTransition fragments) {
    if (nameOverrides.isEmpty() || sharedElementTransition == null) {
        nameOverrides.clear();
        return null;
    }
    final Fragment outFragment = fragments.firstOut;
    final ArrayMap<String, View> outSharedElements = new ArrayMap<>();
    outFragment.getView().findNamedViews(outSharedElements);

    final SharedElementCallback sharedElementCallback;
    final ArrayList<String> names;
    final BackStackRecord outTransaction = fragments.firstOutTransaction;
    if (fragments.firstOutIsPop) {
        sharedElementCallback = outFragment.getEnterTransitionCallback();
        names = outTransaction.mSharedElementTargetNames;
    } else {
        sharedElementCallback = outFragment.getExitTransitionCallback();
        names = outTransaction.mSharedElementSourceNames;
    }

    outSharedElements.retainAll(names);
    if (sharedElementCallback != null) {
        sharedElementCallback.onMapSharedElements(names, outSharedElements);
        for (int i = names.size() - 1; i >= 0; i--) {
            String name = names.get(i);
            View view = outSharedElements.get(name);
            if (view == null) {
                nameOverrides.remove(name);
            } else if (!name.equals(view.getTransitionName())) {
                String targetValue = nameOverrides.remove(name);
                nameOverrides.put(view.getTransitionName(), targetValue);
            }
        }
    } else {
        nameOverrides.retainAll(outSharedElements.keySet());
    }
    return outSharedElements;
}