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

The following examples show how to use android.util.ArrayMap#get() . 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: SnoozeHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the notification record so the most up to date information is shown on re-post.
 */
protected void update(int userId, NotificationRecord record) {
    ArrayMap<String, ArrayMap<String, NotificationRecord>> records =
            mSnoozedNotifications.get(userId);
    if (records == null) {
        return;
    }
    ArrayMap<String, NotificationRecord> pkgRecords = records.get(record.sbn.getPackageName());
    if (pkgRecords == null) {
        return;
    }
    NotificationRecord existing = pkgRecords.get(record.getKey());
    if (existing != null && existing.isCanceled) {
        return;
    }
    pkgRecords.put(record.getKey(), record);
}
 
Example 2
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@GuardedBy("mCache")
private void invalidateCacheLocked(int userId, String providerPackageName, Uri uri) {
    ArrayMap<String, ArrayMap<Pair<String, Uri>, Bundle>> userCache = mCache.get(userId);
    if (userCache == null) return;

    ArrayMap<Pair<String, Uri>, Bundle> packageCache = userCache.get(providerPackageName);
    if (packageCache == null) return;

    if (uri != null) {
        for (int i = 0; i < packageCache.size();) {
            final Pair<String, Uri> key = packageCache.keyAt(i);
            if (key.second != null && key.second.toString().startsWith(uri.toString())) {
                if (DEBUG) Slog.d(TAG, "Invalidating cache for key " + key);
                packageCache.removeAt(i);
            } else {
                i++;
            }
        }
    } else {
        if (DEBUG) Slog.d(TAG, "Invalidating cache for package " + providerPackageName);
        packageCache.clear();
    }
}
 
Example 3
Source File: ManagedServices.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
protected void addApprovedList(String approved, int userId, boolean isPrimary) {
    if (TextUtils.isEmpty(approved)) {
        approved = "";
    }
    ArrayMap<Boolean, ArraySet<String>> approvedByType = mApproved.get(userId);
    if (approvedByType == null) {
        approvedByType = new ArrayMap<>();
        mApproved.put(userId, approvedByType);
    }

    ArraySet<String> approvedList = approvedByType.get(isPrimary);
    if (approvedList == null) {
        approvedList = new ArraySet<>();
        approvedByType.put(isPrimary, approvedList);
    }

    String[] approvedArray = approved.split(ENABLED_SERVICES_SEPARATOR);
    for (String pkgOrComponent : approvedArray) {
        String approvedItem = getApprovedValue(pkgOrComponent);
        if (approvedItem != null) {
            approvedList.add(approvedItem);
        }
    }
}
 
Example 4
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@GuardedBy("mCache")
private void invalidateCacheLocked(int userId, String providerPackageName, Uri uri) {
    ArrayMap<String, ArrayMap<Pair<String, Uri>, Bundle>> userCache = mCache.get(userId);
    if (userCache == null) return;

    ArrayMap<Pair<String, Uri>, Bundle> packageCache = userCache.get(providerPackageName);
    if (packageCache == null) return;

    if (uri != null) {
        for (int i = 0; i < packageCache.size();) {
            final Pair<String, Uri> key = packageCache.keyAt(i);
            if (key.second != null && key.second.toString().startsWith(uri.toString())) {
                if (DEBUG) Slog.d(TAG, "Invalidating cache for key " + key);
                packageCache.removeAt(i);
            } else {
                i++;
            }
        }
    } else {
        if (DEBUG) Slog.d(TAG, "Invalidating cache for package " + providerPackageName);
        packageCache.clear();
    }
}
 
Example 5
Source File: LoadedApk.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
public final IServiceConnection getServiceDispatcher(ServiceConnection c,
        Context context, Handler handler, int flags) {
    synchronized (mServices) {
        LoadedApk.ServiceDispatcher sd = null;
        ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> map = mServices.get(context);
        if (map != null) {
            if (DEBUG) Slog.d(TAG, "Returning existing dispatcher " + sd + " for conn " + c);
            sd = map.get(c);
        }
        if (sd == null) {
            sd = new ServiceDispatcher(c, context, handler, flags);
            if (DEBUG) Slog.d(TAG, "Creating new dispatcher " + sd + " for conn " + c);
            if (map == null) {
                map = new ArrayMap<>();
                mServices.put(context, map);
            }
            map.put(c, sd);
        } else {
            sd.validate(context, handler);
        }
        return sd.getIServiceConnection();
    }
}
 
Example 6
Source File: EnterTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private ArrayMap<String, View> mapNamedElements(ArrayList<String> accepted,
        ArrayList<String> localNames) {
    ArrayMap<String, View> sharedElements = new ArrayMap<String, View>();
    ViewGroup decorView = getDecor();
    if (decorView != null) {
        decorView.findNamedViews(sharedElements);
    }
    if (accepted != null) {
        for (int i = 0; i < localNames.size(); i++) {
            String localName = localNames.get(i);
            String acceptedName = accepted.get(i);
            if (localName != null && !localName.equals(acceptedName)) {
                View view = sharedElements.get(localName);
                if (view != null) {
                    sharedElements.put(acceptedName, view);
                }
            }
        }
    }
    return sharedElements;
}
 
Example 7
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
private void invalidateCacheLocked(int userId, String providerPackageName, Uri uri) {
    ArrayMap<String, ArrayMap<Pair<String, Uri>, Bundle>> userCache = mCache.get(userId);
    if (userCache == null) return;

    ArrayMap<Pair<String, Uri>, Bundle> packageCache = userCache.get(providerPackageName);
    if (packageCache == null) return;

    if (uri != null) {
        for (int i = 0; i < packageCache.size();) {
            final Pair<String, Uri> key = packageCache.keyAt(i);
            if (key.second != null && key.second.toString().startsWith(uri.toString())) {
                if (DEBUG) Slog.d(TAG, "Invalidating cache for key " + key);
                packageCache.removeAt(i);
            } else {
                i++;
            }
        }
    } else {
        if (DEBUG) Slog.d(TAG, "Invalidating cache for package " + providerPackageName);
        packageCache.clear();
    }
}
 
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 item ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startItemIds and endItemIds as a guide for which Views have unique item IDs.
 */
private void matchItemIds(ArrayMap<View, TransitionValues> unmatchedStart,
        ArrayMap<View, TransitionValues> unmatchedEnd,
        LongSparseArray<View> startItemIds, LongSparseArray<View> endItemIds) {
    int numStartIds = startItemIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startItemIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endItemIds.get(startItemIds.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: UsageStatsManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * A convenience method that queries for all stats in the given range (using the best interval
 * for that range), merges the resulting data, and keys it by package name.
 * See {@link #queryUsageStats(int, long, long)}.
 * <p> The caller must have {@link android.Manifest.permission#PACKAGE_USAGE_STATS} </p>
 *
 * @param beginTime The inclusive beginning of the range of stats to include in the results.
 * @param endTime The exclusive end of the range of stats to include in the results.
 * @return A {@link java.util.Map} keyed by package name
 */
public Map<String, UsageStats> queryAndAggregateUsageStats(long beginTime, long endTime) {
    List<UsageStats> stats = queryUsageStats(INTERVAL_BEST, beginTime, endTime);
    if (stats.isEmpty()) {
        return Collections.emptyMap();
    }

    ArrayMap<String, UsageStats> aggregatedStats = new ArrayMap<>();
    final int statCount = stats.size();
    for (int i = 0; i < statCount; i++) {
        UsageStats newStat = stats.get(i);
        UsageStats existingStat = aggregatedStats.get(newStat.getPackageName());
        if (existingStat == null) {
            aggregatedStats.put(newStat.mPackageName, newStat);
        } else {
            existingStat.add(newStat);
        }
    }
    return aggregatedStats;
}
 
Example 10
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 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(File file, int mode) {
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        sp = cache.get(file);
        if (sp == null) {
            checkMode(mode);
            if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) {
                if (isCredentialProtectedStorage()
                        && !getSystemService(UserManager.class)
                                .isUserUnlockingOrUnlocked(UserHandle.myUserId())) {
                    throw new IllegalStateException("SharedPreferences in credential encrypted "
                            + "storage are not available until after user is unlocked");
                }
            }
            sp = new SharedPreferencesImpl(file, mode);
            cache.put(file, sp);
            return sp;
        }
    }
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
Example 12
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(File file, int mode) {
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        sp = cache.get(file); // 先从缓存中尝试获取 sp
        if (sp == null) { // 如果获取缓存失败
            checkMode(mode); // 检查 mode
            if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) {
                if (isCredentialProtectedStorage()
                        && !getSystemService(UserManager.class)
                                .isUserUnlockingOrUnlocked(UserHandle.myUserId())) {
                    throw new IllegalStateException("SharedPreferences in credential encrypted "
                            + "storage are not available until after user is unlocked");
                }
            }
            sp = new SharedPreferencesImpl(file, mode); // 创建 SharedPreferencesImpl
            cache.put(file, sp);
            return sp;
        }
    }

    // mode 为 MODE_MULTI_PROCESS 时,文件可能被其他进程修改,则重新加载
    // 显然这并不足以保证跨进程安全
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
Example 13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(File file, int mode) {
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        sp = cache.get(file);
        if (sp == null) {
            checkMode(mode);
            if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) {
                if (isCredentialProtectedStorage()
                        && !getSystemService(UserManager.class)
                                .isUserUnlockingOrUnlocked(UserHandle.myUserId())) {
                    throw new IllegalStateException("SharedPreferences in credential encrypted "
                            + "storage are not available until after user is unlocked");
                }
            }
            sp = new SharedPreferencesImpl(file, mode);
            cache.put(file, sp);
            return sp;
        }
    }
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
Example 14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(File file, int mode) {
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        sp = cache.get(file);
        if (sp == null) {
            checkMode(mode);
            if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) {
                if (isCredentialProtectedStorage()
                        && !getSystemService(UserManager.class)
                                .isUserUnlockingOrUnlocked(UserHandle.myUserId())) {
                    throw new IllegalStateException("SharedPreferences in credential encrypted "
                            + "storage are not available until after user is unlocked");
                }
            }
            sp = new SharedPreferencesImpl(file, mode);
            cache.put(file, sp);
            return sp;
        }
    }
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
Example 15
Source File: LoadedApk.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public IIntentReceiver getReceiverDispatcher(BroadcastReceiver r,
        Context context, Handler handler,
        Instrumentation instrumentation, boolean registered) {
    synchronized (mReceivers) {
        LoadedApk.ReceiverDispatcher rd = null;
        ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher> map = null;
        if (registered) {
            map = mReceivers.get(context);
            if (map != null) {
                rd = map.get(r);
            }
        }
        if (rd == null) {
            rd = new ReceiverDispatcher(r, context, handler,
                    instrumentation, registered);
            if (registered) {
                if (map == null) {
                    map = new ArrayMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>();
                    mReceivers.put(context, map);
                }
                map.put(r, rd);
            }
        } else {
            rd.validate(context, handler);
        }
        rd.mForgotten = false;
        return rd.getIIntentReceiver();
    }
}
 
Example 16
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(File file, int mode) {
    checkMode(mode);
    if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) {
        if (isCredentialProtectedStorage()
                && !getSystemService(StorageManager.class).isUserKeyUnlocked(
                        UserHandle.myUserId())
                && !isBuggy()) {
            throw new IllegalStateException("SharedPreferences in credential encrypted "
                    + "storage are not available until after user is unlocked");
        }
    }
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        final ArrayMap<File, SharedPreferencesImpl> cache = getSharedPreferencesCacheLocked();
        sp = cache.get(file);
        if (sp == null) {
            sp = new SharedPreferencesImpl(file, mode);
            cache.put(file, sp);
            return sp;
        }
    }
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
Example 17
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        if (sSharedPrefs == null) {
            sSharedPrefs = new ArrayMap<String, ArrayMap<String, SharedPreferencesImpl>>();
        }

        final String packageName = getPackageName();
        ArrayMap<String, SharedPreferencesImpl> packagePrefs = sSharedPrefs.get(packageName);
        if (packagePrefs == null) {
            packagePrefs = new ArrayMap<String, SharedPreferencesImpl>();
            sSharedPrefs.put(packageName, packagePrefs);
        }

        // At least one application in the world actually passes in a null
        // name.  This happened to work because when we generated the file name
        // we would stringify it to "null.xml".  Nice.
        if (mPackageInfo.getApplicationInfo().targetSdkVersion <
                Build.VERSION_CODES.KITKAT) {
            if (name == null) {
                name = "null";
            }
        }

        sp = packagePrefs.get(name);
        if (sp == null) {
            File prefsFile = getSharedPrefsFile(name);
            sp = new SharedPreferencesImpl(prefsFile, mode);
            packagePrefs.put(name, sp);
            return sp;
        }
    }
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
Example 18
Source File: AutofillManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) {
    synchronized (mLock) {
        if (sessionId != mSessionId) {
            return;
        }

        final AutofillClient client = getClient();
        if (client == null) {
            return;
        }

        final int itemCount = ids.size();
        int numApplied = 0;
        ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null;
        final View[] views = client.autofillClientFindViewsByAutofillIdTraversal(
                Helper.toArray(ids));

        ArrayList<AutofillId> failedIds = null;

        for (int i = 0; i < itemCount; i++) {
            final AutofillId id = ids.get(i);
            final AutofillValue value = values.get(i);
            final int viewId = id.getViewId();
            final View view = views[i];
            if (view == null) {
                // Most likely view has been removed after the initial request was sent to the
                // the service; this is fine, but we need to update the view status in the
                // server side so it can be triggered again.
                Log.d(TAG, "autofill(): no View with id " + id);
                if (failedIds == null) {
                    failedIds = new ArrayList<>();
                }
                failedIds.add(id);
                continue;
            }
            if (id.isVirtual()) {
                if (virtualValues == null) {
                    // Most likely there will be just one view with virtual children.
                    virtualValues = new ArrayMap<>(1);
                }
                SparseArray<AutofillValue> valuesByParent = virtualValues.get(view);
                if (valuesByParent == null) {
                    // We don't know the size yet, but usually it will be just a few fields...
                    valuesByParent = new SparseArray<>(5);
                    virtualValues.put(view, valuesByParent);
                }
                valuesByParent.put(id.getVirtualChildId(), value);
            } else {
                // Mark the view as to be autofilled with 'value'
                if (mLastAutofilledData == null) {
                    mLastAutofilledData = new ParcelableMap(itemCount - i);
                }
                mLastAutofilledData.put(id, value);

                view.autofill(value);

                // Set as autofilled if the values match now, e.g. when the value was updated
                // synchronously.
                // If autofill happens async, the view is set to autofilled in
                // notifyValueChanged.
                setAutofilledIfValuesIs(view, value);

                numApplied++;
            }
        }

        if (failedIds != null) {
            if (sVerbose) {
                Log.v(TAG, "autofill(): total failed views: " + failedIds);
            }
            try {
                mService.setAutofillFailure(mSessionId, failedIds, mContext.getUserId());
            } catch (RemoteException e) {
                // In theory, we could ignore this error since it's not a big deal, but
                // in reality, we rather crash the app anyways, as the failure could be
                // a consequence of something going wrong on the server side...
                e.rethrowFromSystemServer();
            }
        }

        if (virtualValues != null) {
            for (int i = 0; i < virtualValues.size(); i++) {
                final View parent = virtualValues.keyAt(i);
                final SparseArray<AutofillValue> childrenValues = virtualValues.valueAt(i);
                parent.autofill(childrenValues);
                numApplied += childrenValues.size();
                // TODO: we should provide a callback so the parent can call failures; something
                // like notifyAutofillFailed(View view, int[] childrenIds);
            }
        }

        mMetricsLogger.write(newLog(MetricsEvent.AUTOFILL_DATASET_APPLIED)
                .addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, itemCount)
                .addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, numApplied));
    }
}
 
Example 19
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
    SharedPreferencesImpl sp;
    synchronized (ContextImpl.class) {
        if (sSharedPrefs == null) {
            sSharedPrefs = new ArrayMap<String, ArrayMap<String, SharedPreferencesImpl>>();
        }

        final String packageName = getPackageName();
        ArrayMap<String, SharedPreferencesImpl> packagePrefs = sSharedPrefs.get(packageName);
        if (packagePrefs == null) {
            packagePrefs = new ArrayMap<String, SharedPreferencesImpl>();
            sSharedPrefs.put(packageName, packagePrefs);
        }

        // At least one application in the world actually passes in a null
        // name.  This happened to work because when we generated the file name
        // we would stringify it to "null.xml".  Nice.
        if (mPackageInfo.getApplicationInfo().targetSdkVersion <
                Build.VERSION_CODES.KITKAT) {
            if (name == null) {
                name = "null";
            }
        }

        sp = packagePrefs.get(name);
        if (sp == null) {
            File prefsFile = getSharedPrefsFile(name);
            sp = new SharedPreferencesImpl(prefsFile, mode);
            packagePrefs.put(name, sp);
            return sp;
        }
    }
    if ((mode & Context.MODE_MULTI_PROCESS) != 0 ||
        getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
        // If somebody else (some other process) changed the prefs
        // file behind our back, we reload it.  This has been the
        // historical (if undocumented) behavior.
        sp.startReloadIfChangedUnexpectedly();
    }
    return sp;
}
 
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;
}