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

Skip to content
Commit 6c984cca authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Fix a user ID mismatch in IMMS#queryInputMethodServicesInternal

This is a follow up CL to our previous CL [1], which aimed to
introduce a safeguard against Binder transaction failure due to too
large payload, which is actually not something new when dealing with
InputMethodInfo [2].

Anyway, the way how the original CL attempted is to filter out APKs
that contain too many InputMethodService entries (20 entries), unless
the InputMethodService is pre-installed or already enabled, and it was
implemented as an additional step in

  InputMethodManagerService#queryInputMethodServicesInternal().

The primary problem is that to get the list of enabled IME IDs, the
original CL used

  InputMethodManagerService#mSettings.getEnabledInputMethodNames(),

which is valid only for the current IME user. If the query is about
another user, then we are using a wrong user's enabled IME IDs, which
is not our intention. There is, however, a secondary problem on how to
get another user's InputMethodSettings.  Here is why.

Here is the boilerplate code to instantiate an InputMethodSettings
object for a given "userId".

  ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
  ArrayList<InputMethodInfo> methodList = new ArrayList<>();
  ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap =
          new ArrayMap<>();
  AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
  queryInputMethodServicesInternal(mContext, userId,
          additionalSubtypeMap, methodMap, methodList,
          directBootAwareness);
  InputMethodSettings settings = new InputMethodSettings(mContext,
          methodMap, userId, true /* copyOnWrite */);

With the commit in question [1], however, there is a cyclic data
dependency, that is, we need to rely on

  InputMethodSettings#getEnabledInputMethodNames()

to instantiate an InputMethodSettings.

  ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
  ArrayList<InputMethodInfo> methodList = new ArrayList<>();
  ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap =
          new ArrayMap<>();
  AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
  queryInputMethodServicesInternal(mContext, userId,
          additionalSubtypeMap, methodMap, methodList,
          directBootAwareness,
          // the following settings is not yet available.
          // it will be created in the next line!!!
          settings.getEnabledInputMethodNames());
  InputMethodSettings settings = new InputMethodSettings(mContext,
          methodMap, userId, true /* copyOnWrite */);

Fortunately, the real data dependency is not cyclic and we can still
create the necessary list by directly accessing

  Settings.Secure.ENABLED_INPUT_METHODS.

With above, this CL introduces

  InputMethodUtils#getEnabledInputMethodIdsForFiltering()

so that queryInputMethodServicesInternal() can be used without relying
on InputMethodSettings.

This CL is also a preparatoin to start maintaining multiple instances
of InputMethodSettings at the same time.

There must be no semantic change in this CL except for we now take
right user's enabled IME IDs into considerations anyway.

 [1]: I51703563414192ee778f30ab57390da1c1a5ded5
      eed10082
 [2]: Ibb2940fcc02f3b3b51ba6bbe127d646fd7de7c45
      f0656956

Bug: 261723412
Bug: 309837937
Test: presubmit
Change-Id: Iac98fdbb2758f4d9c68930f49d219eb83e54a3d0
parent 5d46b5c6
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment