Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit add8f231 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Merge IMMS#mMethod{List,Map} into IMMS#mSettings

With this CL the following fields

  InputMethodManagerService#mMethodList
  InputMethodManagerService#mMethodMap

will be effectively merged into

  InputMethodManagerService#mSettings

as immutable fields so that relevant data objects are always
consistent with each other.

There must be no observable behavior change.

Bug: 309837937
Fix: 309870347
Test: atest CtsInputMethodTestCases
Test: atest FrameworksServicesTests:InputMethodSettingsTest
Test: atest FrameworksServicesTests:InputMethodManagerServiceTests
Test: atest FrameworksInputMethodSystemServerTests
Change-Id: I512519ed83b28adb2878945bc3e6eaff9ba29f5e
parent 6d93e4f3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ final class AdditionalSubtypeUtils {
     * @param userId      The user ID to be associated with.
     */
    static void save(ArrayMap<String, List<InputMethodSubtype>> allSubtypes,
            ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId) {
            InputMethodMap methodMap, @UserIdInt int userId) {
        final File inputMethodDir = getInputMethodDir(userId);

        if (allSubtypes.isEmpty()) {
@@ -143,7 +143,7 @@ final class AdditionalSubtypeUtils {

    @VisibleForTesting
    static void saveToFile(ArrayMap<String, List<InputMethodSubtype>> allSubtypes,
            ArrayMap<String, InputMethodInfo> methodMap, AtomicFile subtypesFile) {
            InputMethodMap methodMap, AtomicFile subtypesFile) {
        // Safety net for the case that this function is called before methodMap is set.
        final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
        FileOutputStream fos = null;
+3 −5
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.util.ArrayMap;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;

@@ -44,16 +43,15 @@ final class HardwareKeyboardShortcutController {
        return mUserId;
    }

    HardwareKeyboardShortcutController(
            @NonNull ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId) {
    HardwareKeyboardShortcutController(@NonNull InputMethodMap methodMap, @UserIdInt int userId) {
        mUserId = userId;
        reset(methodMap);
    }

    @GuardedBy("ImfLock.class")
    void reset(@NonNull ArrayMap<String, InputMethodInfo> methodMap) {
    void reset(@NonNull InputMethodMap methodMap) {
        mSubtypeHandles.clear();
        final InputMethodSettings settings = new InputMethodSettings(methodMap, mUserId);
        final InputMethodSettings settings = InputMethodSettings.create(methodMap, mUserId);
        final List<InputMethodInfo> inputMethods = settings.getEnabledInputMethodListLocked();
        for (int i = 0; i < inputMethods.size(); ++i) {
            final InputMethodInfo imi = inputMethods.get(i);
+1 −2
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Slog;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
@@ -204,7 +203,7 @@ final class InputMethodInfoUtils {
     */
    @Nullable
    static InputMethodInfo chooseSystemVoiceIme(
            @NonNull ArrayMap<String, InputMethodInfo> methodMap,
            @NonNull InputMethodMap methodMap,
            @Nullable String systemSpeechRecognizerPackageName,
            @Nullable String currentDefaultVoiceImeId) {
        if (TextUtils.isEmpty(systemSpeechRecognizerPackageName)) {
+114 −134

File changed.

Preview size limit exceeded, changes collapsed.

+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.inputmethod;

import android.annotation.AnyThread;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.ArrayMap;
import android.view.inputmethod.InputMethodInfo;

import java.util.List;

/**
 * A map from IME ID to {@link InputMethodInfo}, which is guaranteed to be immutable thus
 * thread-safe.
 */
final class InputMethodMap {
    private static final ArrayMap<String, InputMethodInfo> EMPTY_MAP =
            new ArrayMap<>();

    private final ArrayMap<String, InputMethodInfo> mMap;

    static InputMethodMap emptyMap() {
        return new InputMethodMap(EMPTY_MAP);
    }

    static InputMethodMap of(@NonNull ArrayMap<String, InputMethodInfo> map) {
        return new InputMethodMap(map);
    }

    private InputMethodMap(@NonNull ArrayMap<String, InputMethodInfo> map) {
        mMap = map.isEmpty() ? EMPTY_MAP : new ArrayMap<>(map);
    }

    @AnyThread
    @Nullable
    InputMethodInfo get(@Nullable String imeId) {
        return mMap.get(imeId);
    }

    @AnyThread
    @NonNull
    List<InputMethodInfo> values() {
        return List.copyOf(mMap.values());
    }

    @AnyThread
    @Nullable
    InputMethodInfo valueAt(int index) {
        return mMap.valueAt(index);
    }

    @AnyThread
    boolean containsKey(@Nullable String imeId) {
        return mMap.containsKey(imeId);
    }

    @AnyThread
    @IntRange(from = 0)
    int size() {
        return mMap.size();
    }
}
Loading