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

Commit 1c66301b authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Adjust method access levels in InputMethodUtils

This is a mechanical refactoring that adjusts access levels for
methods in InputMethodUtils.

With a recent CL [1], which moved InputMethodUtils to services.jar,
some of methods in InputMethodUtils can now have strict access level
than before.

 [1]: I37594096151d77adb6741a41d7985a4506f96ccb
      e6b6e0e7

Bug: 123379418
Test: make -j checkbuild
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: Iaf737787426d3a67df8ad6595c2b094fad139619
parent 4792bc1d
Loading
Loading
Loading
Loading
+45 −49
Original line number Diff line number Diff line
@@ -66,9 +66,9 @@ import java.util.Locale;
 */
final class InputMethodUtils {
    public static final boolean DEBUG = false;
    public static final int NOT_A_SUBTYPE_ID = -1;
    public static final String SUBTYPE_MODE_ANY = null;
    public static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
    static final int NOT_A_SUBTYPE_ID = -1;
    private static final String SUBTYPE_MODE_ANY = null;
    static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
    private static final String TAG = "InputMethodUtils";
    private static final Locale ENGLISH_LOCALE = new Locale("en");
    private static final String NOT_A_SUBTYPE_ID_STR = String.valueOf(NOT_A_SUBTYPE_ID);
@@ -108,7 +108,7 @@ final class InputMethodUtils {

    // ----------------------------------------------------------------------
    // Utilities for debug
    public static String getApiCallStack() {
    static String getApiCallStack() {
        String apiCallStack = "";
        try {
            throw new RuntimeException();
@@ -131,7 +131,7 @@ final class InputMethodUtils {
    }
    // ----------------------------------------------------------------------

    public static boolean isSystemImeThatHasSubtypeOf(InputMethodInfo imi, Context context,
    private static boolean isSystemImeThatHasSubtypeOf(InputMethodInfo imi, Context context,
            boolean checkDefaultAttribute, @Nullable Locale requiredLocale, boolean checkCountry,
            String requiredSubtypeMode) {
        if (!imi.isSystem()) {
@@ -147,7 +147,7 @@ final class InputMethodUtils {
    }

    @Nullable
    public static Locale getFallbackLocaleForDefaultIme(ArrayList<InputMethodInfo> imis,
    private static Locale getFallbackLocaleForDefaultIme(ArrayList<InputMethodInfo> imis,
            Context context) {
        // At first, find the fallback locale from the IMEs that are declared as "default" in the
        // current locale.  Note that IME developers can declare an IME as "default" only for
@@ -197,7 +197,7 @@ final class InputMethodUtils {
        return false;
    }

    public static Locale getSystemLocaleFromContext(Context context) {
    private static Locale getSystemLocaleFromContext(Context context) {
        try {
            return context.getResources().getConfiguration().locale;
        } catch (Resources.NotFoundException ex) {
@@ -211,7 +211,7 @@ final class InputMethodUtils {
        @NonNull
        private final LinkedHashSet<InputMethodInfo> mInputMethodSet = new LinkedHashSet<>();

        public InputMethodListBuilder fillImes(ArrayList<InputMethodInfo> imis, Context context,
        InputMethodListBuilder fillImes(ArrayList<InputMethodInfo> imis, Context context,
                boolean checkDefaultAttribute, @Nullable Locale locale, boolean checkCountry,
                String requiredSubtypeMode) {
            for (int i = 0; i < imis.size(); ++i) {
@@ -226,8 +226,7 @@ final class InputMethodUtils {

        // TODO: The behavior of InputMethodSubtype#overridesImplicitlyEnabledSubtype() should be
        // documented more clearly.
        public InputMethodListBuilder fillAuxiliaryImes(ArrayList<InputMethodInfo> imis,
                Context context) {
        InputMethodListBuilder fillAuxiliaryImes(ArrayList<InputMethodInfo> imis, Context context) {
            // If one or more auxiliary input methods are available, OK to stop populating the list.
            for (final InputMethodInfo imi : mInputMethodSet) {
                if (imi.isAuxiliaryIme()) {
@@ -315,7 +314,7 @@ final class InputMethodUtils {
        return builder;
    }

    public static ArrayList<InputMethodInfo> getDefaultEnabledImes(
    static ArrayList<InputMethodInfo> getDefaultEnabledImes(
            Context context, ArrayList<InputMethodInfo> imis, boolean onlyMinimum) {
        final Locale fallbackLocale = getFallbackLocaleForDefaultIme(imis, context);
        // We will primarily rely on the system locale, but also keep relying on the fallback locale
@@ -334,12 +333,12 @@ final class InputMethodUtils {
        return builder.build();
    }

    public static ArrayList<InputMethodInfo> getDefaultEnabledImes(
    static ArrayList<InputMethodInfo> getDefaultEnabledImes(
            Context context, ArrayList<InputMethodInfo> imis) {
        return getDefaultEnabledImes(context, imis, false /* onlyMinimum */);
    }

    public static boolean containsSubtypeOf(InputMethodInfo imi, @Nullable Locale locale,
    static boolean containsSubtypeOf(InputMethodInfo imi, @Nullable Locale locale,
            boolean checkCountry, String mode) {
        if (locale == null) {
            return false;
@@ -369,7 +368,7 @@ final class InputMethodUtils {
        return false;
    }

    public static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) {
    static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) {
        ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        final int subtypeCount = imi.getSubtypeCount();
        for (int i = 0; i < subtypeCount; ++i) {
@@ -378,7 +377,7 @@ final class InputMethodUtils {
        return subtypes;
    }

    public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) {
    static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) {
        if (enabledImes == null || enabledImes.isEmpty()) {
            return null;
        }
@@ -402,11 +401,11 @@ final class InputMethodUtils {
        return enabledImes.get(Math.max(firstFoundSystemIme, 0));
    }

    public static boolean isValidSubtypeId(InputMethodInfo imi, int subtypeHashCode) {
    static boolean isValidSubtypeId(InputMethodInfo imi, int subtypeHashCode) {
        return getSubtypeIdFromHashCode(imi, subtypeHashCode) != NOT_A_SUBTYPE_ID;
    }

    public static int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) {
    static int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) {
        if (imi != null) {
            final int subtypeCount = imi.getSubtypeCount();
            for (int i = 0; i < subtypeCount; ++i) {
@@ -428,7 +427,7 @@ final class InputMethodUtils {
            };

    @VisibleForTesting
    public static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLocked(
    static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLocked(
            Resources res, InputMethodInfo imi) {
        final LocaleList systemLocales = res.getConfiguration().getLocales();

@@ -562,7 +561,7 @@ final class InputMethodUtils {
     * it will return the first subtype matched with mode
     * @return the most applicable subtypeId
     */
    public static InputMethodSubtype findLastResortApplicableSubtypeLocked(
    static InputMethodSubtype findLastResortApplicableSubtypeLocked(
            Resources res, List<InputMethodSubtype> subtypes, String mode, String locale,
            boolean canIgnoreLocaleAsLastResort) {
        if (subtypes == null || subtypes.size() == 0) {
@@ -613,14 +612,13 @@ final class InputMethodUtils {
        return applicableSubtype;
    }

    public static boolean canAddToLastInputMethod(InputMethodSubtype subtype) {
    static boolean canAddToLastInputMethod(InputMethodSubtype subtype) {
        if (subtype == null) return true;
        return !subtype.isAuxiliary();
    }

    public static void setNonSelectedSystemImesDisabledUntilUsed(
            IPackageManager packageManager, List<InputMethodInfo> enabledImis,
            int userId, String callingPackage) {
    static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager,
            List<InputMethodInfo> enabledImis, @UserIdInt int userId, String callingPackage) {
        if (DEBUG) {
            Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
        }
@@ -708,7 +706,7 @@ final class InputMethodUtils {
        }
    }

    public static CharSequence getImeAndSubtypeDisplayName(Context context, InputMethodInfo imi,
    static CharSequence getImeAndSubtypeDisplayName(Context context, InputMethodInfo imi,
            InputMethodSubtype subtype) {
        final CharSequence imiLabel = imi.loadLabel(context.getPackageManager());
        return subtype != null
@@ -728,7 +726,7 @@ final class InputMethodUtils {
     * @param packageName the package name.
     * @return {@code true} if the package name belongs to the UID.
     */
    public static boolean checkIfPackageBelongsToUid(AppOpsManager appOpsManager,
    static boolean checkIfPackageBelongsToUid(AppOpsManager appOpsManager,
            @UserIdInt int uid, String packageName) {
        try {
            appOpsManager.checkPackage(uid, packageName);
@@ -800,8 +798,7 @@ final class InputMethodUtils {
            return imsList;
        }

        public InputMethodSettings(
                Resources res, ContentResolver resolver,
        InputMethodSettings(Resources res, ContentResolver resolver,
                ArrayMap<String, InputMethodInfo> methodMap, ArrayList<InputMethodInfo> methodList,
                @UserIdInt int userId, boolean copyOnWrite) {
            mRes = res;
@@ -818,7 +815,7 @@ final class InputMethodUtils {
         * (e.g. {@link Settings.Secure#ACTION_INPUT_METHOD_SUBTYPE_SETTINGS}) we use the actual
         * settings on the {@link Settings.Secure} until we do the first write operation.
         */
        public void switchCurrentUser(@UserIdInt int userId, boolean copyOnWrite) {
        void switchCurrentUser(@UserIdInt int userId, boolean copyOnWrite) {
            if (DEBUG) {
                Slog.d(TAG, "--- Switch the current user from " + mCurrentUserId + " to " + userId);
            }
@@ -891,12 +888,12 @@ final class InputMethodUtils {
            }
        }

        public ArrayList<InputMethodInfo> getEnabledInputMethodListLocked() {
        ArrayList<InputMethodInfo> getEnabledInputMethodListLocked() {
            return createEnabledInputMethodListLocked(
                    getEnabledInputMethodsAndSubtypeListLocked());
        }

        public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(
        List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(
                Context context, InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
            List<InputMethodSubtype> enabledSubtypes =
                    getEnabledInputMethodSubtypeListLocked(imi);
@@ -907,8 +904,7 @@ final class InputMethodUtils {
            return InputMethodSubtype.sort(context, 0, imi, enabledSubtypes);
        }

        public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(
                InputMethodInfo imi) {
        List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(InputMethodInfo imi) {
            List<Pair<String, ArrayList<String>>> imsList =
                    getEnabledInputMethodsAndSubtypeListLocked();
            ArrayList<InputMethodSubtype> enabledSubtypes = new ArrayList<>();
@@ -932,13 +928,13 @@ final class InputMethodUtils {
            return enabledSubtypes;
        }

        public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() {
        List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() {
            return buildInputMethodsAndSubtypeList(getEnabledInputMethodsStr(),
                    mInputMethodSplitter,
                    mSubtypeSplitter);
        }

        public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) {
        void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) {
            if (reloadInputMethodStr) {
                getEnabledInputMethodsStr();
            }
@@ -955,7 +951,7 @@ final class InputMethodUtils {
         * Build and put a string of EnabledInputMethods with removing specified Id.
         * @return the specified id was removed or not.
         */
        public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked(
        boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked(
                StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) {
            boolean isRemoved = false;
            boolean needsAppendSeparator = false;
@@ -1010,7 +1006,7 @@ final class InputMethodUtils {
        }

        @NonNull
        public String getEnabledInputMethodsStr() {
        String getEnabledInputMethodsStr() {
            mEnabledInputMethodsStrCache = getString(Settings.Secure.ENABLED_INPUT_METHODS, "");
            if (DEBUG) {
                Slog.d(TAG, "getEnabledInputMethodsStr: " + mEnabledInputMethodsStrCache
@@ -1078,12 +1074,12 @@ final class InputMethodUtils {
            }
        }

        public Pair<String, String> getLastInputMethodAndSubtypeLocked() {
        Pair<String, String> getLastInputMethodAndSubtypeLocked() {
            // Gets the first one from the history
            return getLastSubtypeForInputMethodLockedInternal(null);
        }

        public String getLastSubtypeForInputMethodLocked(String imeId) {
        String getLastSubtypeForInputMethodLocked(String imeId) {
            Pair<String, String> ime = getLastSubtypeForInputMethodLockedInternal(imeId);
            if (ime != null) {
                return ime.second;
@@ -1201,7 +1197,7 @@ final class InputMethodUtils {
            return history;
        }

        public void putSelectedInputMethod(String imeId) {
        void putSelectedInputMethod(String imeId) {
            if (DEBUG) {
                Slog.d(TAG, "putSelectedInputMethodStr: " + imeId + ", "
                        + mCurrentUserId);
@@ -1209,7 +1205,7 @@ final class InputMethodUtils {
            putString(Settings.Secure.DEFAULT_INPUT_METHOD, imeId);
        }

        public void putSelectedSubtype(int subtypeId) {
        void putSelectedSubtype(int subtypeId) {
            if (DEBUG) {
                Slog.d(TAG, "putSelectedInputMethodSubtypeStr: " + subtypeId + ", "
                        + mCurrentUserId);
@@ -1218,7 +1214,7 @@ final class InputMethodUtils {
        }

        @Nullable
        public String getSelectedInputMethod() {
        String getSelectedInputMethod() {
            final String imi = getString(Settings.Secure.DEFAULT_INPUT_METHOD, null);
            if (DEBUG) {
                Slog.d(TAG, "getSelectedInputMethodStr: " + imi);
@@ -1226,7 +1222,7 @@ final class InputMethodUtils {
            return imi;
        }

        public boolean isSubtypeSelected() {
        boolean isSubtypeSelected() {
            return getSelectedInputMethodSubtypeHashCode() != NOT_A_SUBTYPE_ID;
        }

@@ -1234,11 +1230,11 @@ final class InputMethodUtils {
            return getInt(Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID);
        }

        public boolean isShowImeWithHardKeyboardEnabled() {
        boolean isShowImeWithHardKeyboardEnabled() {
            return getBoolean(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, false);
        }

        public void setShowImeWithHardKeyboard(boolean show) {
        void setShowImeWithHardKeyboard(boolean show) {
            putBoolean(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, show);
        }

@@ -1247,7 +1243,7 @@ final class InputMethodUtils {
            return mCurrentUserId;
        }

        public int getSelectedInputMethodSubtypeId(String selectedImiId) {
        int getSelectedInputMethodSubtypeId(String selectedImiId) {
            final InputMethodInfo imi = mMethodMap.get(selectedImiId);
            if (imi == null) {
                return NOT_A_SUBTYPE_ID;
@@ -1256,8 +1252,8 @@ final class InputMethodUtils {
            return getSubtypeIdFromHashCode(imi, subtypeHashCode);
        }

        public void saveCurrentInputMethodAndSubtypeToHistory(
                String curMethodId, InputMethodSubtype currentSubtype) {
        void saveCurrentInputMethodAndSubtypeToHistory(String curMethodId,
                InputMethodSubtype currentSubtype) {
            String subtypeId = NOT_A_SUBTYPE_ID_STR;
            if (currentSubtype != null) {
                subtypeId = String.valueOf(currentSubtype.hashCode());
@@ -1275,8 +1271,8 @@ final class InputMethodUtils {
        }
    }

    public static boolean isSoftInputModeStateVisibleAllowed(
            int targetSdkVersion, @StartInputFlags int startInputFlags) {
    static boolean isSoftInputModeStateVisibleAllowed(int targetSdkVersion,
            @StartInputFlags int startInputFlags) {
        if (targetSdkVersion < Build.VERSION_CODES.P) {
            // for compatibility.
            return true;