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

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

Move 3 IMMS utility classes to services.jar

Short summary:

There is no need to have these 3 utility classes in frameworks.jar,
because these classes are used only from InputMethodManagerService
(IMMS) and its utility classes. We should move them to services.jar.

Long summary:

 * InputMethodSubtypeSwitchingController

This class was mistakenly placed in the current Java package since its
beginning [1].  This class is purely a state machine that is designed
to be used only from IMMS hence there has been no way for app
processes to use this class in a meaningful way.

 * LocaleUtils

This class was also mistakenly placed in the current Java package
since its beginning [2].  This class is purely a state machine that is
designed to be used only from IMMS hence there has been no way for app
processes to use this class in a meaningful way.

 * InputMethodUtils

The situation of InputMethodUtils is a bit different.  It was
introduced in the right place actually [3], because the original
purpose of this class was to share some utility methods between IMMS
and the Settings application.  For that purpose, having this class
under frameworks/base/core/java instead of frameworks/base/services/
totally made sense.

What was unfortunate is that we have kept adding more and more utility
methods into InputMethodUtils since then, even though most of methods
have been used only from IMMS.  To make things worse, more and more
random components started depending on this utility class.  When we
realized it, we were in the situation where we could not even easily
refactor methods in InputMethodUtils without updating a bunch of
call-sites across repositories, including multiple platform-specific
Settings app and SetupWizards.

This is basically why I decided to stop allowing Settings apps and
SetupWizard to use InputMethodUtils, and decided to let them depend on
SettingsLib [4] instead.  After many cleanup CLs [5], we have finally
achieved the state where InputMethodUtils is used only from the system
server process.

 * A special bonus

With my previous CL [6], we can even make these 3 utility classes
package-private, which guarantees that only IMMS and its utility
classes directly depends on these utility classes.

 * Risk

Now that this is purely a mechanical refactoring of an implementation
detail within frameworks/base, there should be no observable behavior
difference.

 [1]: I11ed9a767588f8080753cd9bce011dac7db579ad
      d7443c83
 [2]: I315cf3722a06e00bdbfac284c4949578da8fe78d
      102ff072
 [3]: I0bc9954f163a3ec38d08b9ba842a8a31176eb6a6
      8e303cc5
 [4]: frameworks/base/packages/SettingsLib
 [5]: CLs that have Bug 77730201 in their commit messages
 [6]: I023d8f2863601ee54f304988117d8ea750770f70
      603f4d00

Bug: 77730201
Bug: 114660660
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Test: atest FrameworksCoreTests:com.android.internal.inputmethod
Test: atest FrameworksServicesTests:com.android.server.inputmethod
Change-Id: I37594096151d77adb6741a41d7985a4506f96ccb
parent 835ab94b
Loading
Loading
Loading
Loading
+2 −4
Original line number Original line Diff line number Diff line
@@ -129,10 +129,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.PackageMonitor;
import com.android.internal.content.PackageMonitor;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IInputMethodPrivilegedOperations;
import com.android.internal.inputmethod.IInputMethodPrivilegedOperations;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
import com.android.internal.inputmethod.InputMethodUtils;
import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.HandlerCaller;
import com.android.internal.os.HandlerCaller;
@@ -152,6 +148,8 @@ import com.android.internal.view.InputMethodClient;
import com.android.server.EventLogTags;
import com.android.server.EventLogTags;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.SystemService;
import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
import com.android.server.inputmethod.InputMethodUtils.InputMethodSettings;
import com.android.server.statusbar.StatusBarManagerService;
import com.android.server.statusbar.StatusBarManagerService;
import com.android.server.wm.WindowManagerInternal;
import com.android.server.wm.WindowManagerInternal;


+6 −8
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package com.android.internal.inputmethod;
package com.android.server.inputmethod;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.Context;
import android.content.Context;
@@ -27,7 +27,7 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSubtype;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
import com.android.server.inputmethod.InputMethodUtils.InputMethodSettings;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
@@ -41,13 +41,11 @@ import java.util.TreeMap;


/**
/**
 * InputMethodSubtypeSwitchingController controls the switching behavior of the subtypes.
 * InputMethodSubtypeSwitchingController controls the switching behavior of the subtypes.
 * <p>
 *
 * This class is designed to be used from and only from
 * <p>This class is designed to be used from and only from {@link InputMethodManagerService} by
 * {@link com.android.server.InputMethodManagerService} by using
 * using {@link InputMethodManagerService#mMethodMap} as a global lock.</p>
 * {@link com.android.server.InputMethodManagerService#mMethodMap} as a global lock.
 * </p>
 */
 */
public class InputMethodSubtypeSwitchingController {
final class InputMethodSubtypeSwitchingController {
    private static final String TAG = InputMethodSubtypeSwitchingController.class.getSimpleName();
    private static final String TAG = InputMethodSubtypeSwitchingController.class.getSimpleName();
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;
    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
+8 −4
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package com.android.internal.inputmethod;
package com.android.server.inputmethod;


import static android.view.inputmethod.InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR;
import static android.view.inputmethod.InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR;
import static android.view.inputmethod.InputMethodManager.CONTROL_WINDOW_VIEW_HAS_FOCUS;
import static android.view.inputmethod.InputMethodManager.CONTROL_WINDOW_VIEW_HAS_FOCUS;
@@ -53,10 +53,14 @@ import java.util.List;
import java.util.Locale;
import java.util.Locale;


/**
/**
 * InputMethodManagerUtils contains some static methods that provides IME informations.
 * This class provides random static utility methods for {@link InputMethodManagerService} and its
 * This methods are supposed to be used in both the framework and the Settings application.
 * utility classes.
 *
 * <p>This class is intentionally package-private.  Utility methods here are tightly coupled with
 * implementation details in {@link InputMethodManagerService}.  Hence this class is not suitable
 * for other components to directly use.</p>
 */
 */
public class InputMethodUtils {
final class InputMethodUtils {
    public static final boolean DEBUG = false;
    public static final boolean DEBUG = false;
    public static final int NOT_A_SUBTYPE_ID = -1;
    public static final int NOT_A_SUBTYPE_ID = -1;
    public static final String SUBTYPE_MODE_ANY = null;
    public static final String SUBTYPE_MODE_ANY = null;
+2 −7
Original line number Original line Diff line number Diff line
@@ -14,9 +14,7 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package com.android.internal.inputmethod;
package com.android.server.inputmethod;

import com.android.internal.annotations.VisibleForTesting;


import android.annotation.IntRange;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -31,9 +29,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Locale;


public final class LocaleUtils {
final class LocaleUtils {

    @VisibleForTesting
    public interface LocaleExtractor<T> {
    public interface LocaleExtractor<T> {
        @Nullable
        @Nullable
        Locale get(@Nullable T source);
        Locale get(@Nullable T source);
@@ -149,7 +145,6 @@ public final class LocaleUtils {
     * @param dest Destination into which the filtered items will be added.
     * @param dest Destination into which the filtered items will be added.
     * @param <T> Type of the data items.
     * @param <T> Type of the data items.
     */
     */
    @VisibleForTesting
    public static <T> void filterByLanguage(
    public static <T> void filterByLanguage(
            @NonNull List<T> sources,
            @NonNull List<T> sources,
            @NonNull LocaleExtractor<T> extractor,
            @NonNull LocaleExtractor<T> extractor,
+6 −6
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package com.android.internal.inputmethod;
package com.android.server.inputmethod;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
@@ -23,15 +23,15 @@ import static org.junit.Assert.assertTrue;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.ServiceInfo;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;


import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ControllerImpl;
import androidx.test.filters.SmallTest;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.inputmethod.InputMethodUtils;

import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ControllerImpl;
import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;


import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
Loading