Supports VirtualDisplay for the input window mappings.

- Uses the regular expression to match the display unique id.
- Changes the config separator from comma to slash, since comma is used in
  virtual display unique id.
- Adds the example config for ActivityView.

Bug: 136039906
Test: manually with the example configs.
Change-Id: I51917d39c5cb11666dcb4fea69545f3075a024a7
This commit is contained in:
Yuncheol Heo
2019-08-26 18:15:46 -07:00
parent 55fd569783
commit 52b912ddd6
2 changed files with 19 additions and 9 deletions

View File

@@ -21,15 +21,21 @@
<!-- <!--
The MultiClientInputMethod will use the same display for the IME window by default. The MultiClientInputMethod will use the same display for the IME window by default.
But, if you want to use the separate display for the IME window, consider to define item of But, if you want to use the separate display for the IME window, consider to define item of
'config_inputDisplayToImeDisplay'. The each item is a comma-separated pair of the uniqueId of 'config_inputDisplayToImeDisplay'. The each item is a slash-separated (/) pair of the display
the displays. The first is the uniqueId of the display where the input happens and the second the uniqueIds. The first is the uniqueId of the display where the input happens and the second
is the unqiueId of the display where the IME window will be shown. is the unqiueId of the display where the IME window will be shown.
FYI, you can find the uniqueId of displays in "dumpsys display". FYI, you can find the uniqueId of displays in "dumpsys display".
E.g. If you have two displays 19261083906282752, local:19260422155234049 and you want to use E.g. If you have two displays 19261083906282752, local:19260422155234049 and you want to use
local:19260422155234049 as the IME window for the input at the display local:19261083906282752, local:19260422155234049 as the IME window for the input at the display local:19261083906282752,
then the config item will be: then the config item will be:
<item>local:19261083906282752,local:19260422155234049</item> <item>local:19261083906282752/local:19260422155234049</item>
E.g. The display of ActivityView has the unique id of the form of
'virtual:' + package_name + ',' + ownerUid + ',' + 'ActivityViewVirtualDisplay@'
+ hashCode + ',' + displayIndex.
We can use the following regular expression to match it:
<item>virtual:com.android.car.carlauncher,\\d+,ActivityViewVirtualDisplay@\\d+,\\d+/local:19260422155234049</item>
--> -->
</string-array> </string-array>
</resources> </resources>

View File

@@ -90,6 +90,7 @@ public final class MultiClientInputMethod extends Service implements DisplayList
@Override @Override
public void onDisplayAdded(int displayId) { public void onDisplayAdded(int displayId) {
mInputDisplayToImeDisplay = buildInputDisplayToImeDisplay();
} }
@Override @Override
@@ -132,7 +133,6 @@ public final class MultiClientInputMethod extends Service implements DisplayList
@NonNull @NonNull
private SparseIntArray buildInputDisplayToImeDisplay() { private SparseIntArray buildInputDisplayToImeDisplay() {
// TODO: Support the virtual display after b/137375833 is fixed.
Context context = getApplicationContext(); Context context = getApplicationContext();
String config[] = context.getResources().getStringArray( String config[] = context.getResources().getStringArray(
R.array.config_inputDisplayToImeDisplay); R.array.config_inputDisplayToImeDisplay);
@@ -140,7 +140,7 @@ public final class MultiClientInputMethod extends Service implements DisplayList
SparseIntArray inputDisplayToImeDisplay = new SparseIntArray(); SparseIntArray inputDisplayToImeDisplay = new SparseIntArray();
Display[] displays = context.getSystemService(DisplayManager.class).getDisplays(); Display[] displays = context.getSystemService(DisplayManager.class).getDisplays();
for (String item: config) { for (String item: config) {
String[] pair = item.split(","); String[] pair = item.split("/");
if (pair.length != 2) { if (pair.length != 2) {
Log.w(TAG, "Skip illegal config: " + item); Log.w(TAG, "Skip illegal config: " + item);
continue; continue;
@@ -154,13 +154,17 @@ public final class MultiClientInputMethod extends Service implements DisplayList
return inputDisplayToImeDisplay; return inputDisplayToImeDisplay;
} }
private static int findDisplayId(Display displays[], String uniqueId) { private static int findDisplayId(Display displays[], String regexp) {
for (Display display: displays) { for (Display display: displays) {
if (uniqueId.equals(display.getUniqueId())) { if (display.getUniqueId().matches(regexp)) {
return display.getDisplayId(); int displayId = display.getDisplayId();
if (DEBUG) {
Log.v(TAG, regexp + " matches displayId=" + displayId);
}
return displayId;
} }
} }
Log.w(TAG, "Can't find the display of " + uniqueId); Log.w(TAG, "Can't find the display of " + regexp);
return Display.INVALID_DISPLAY; return Display.INVALID_DISPLAY;
} }
} }