diff options
| author | 2018-12-10 18:56:40 +0000 | |
|---|---|---|
| committer | 2018-12-10 18:56:40 +0000 | |
| commit | a5a81d2458bd76eca493232df279603dbdc1e8bb (patch) | |
| tree | da222c438c27a2f2a90e61bba6708497a87a1f35 | |
| parent | 13f94032c77d4ded10dd90ca766945f0400a654d (diff) | |
| parent | 0b05f9e49dc6e2a418479f432e8728346ebaaf54 (diff) | |
Merge "Add IMMS#showInputMethodPickerFromSystem."
8 files changed, 68 insertions, 23 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 492aad904ff8..fe9b1ffb378f 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2281,6 +2281,15 @@ public final class ActivityThread extends ClientTransactionHandler { } } + /** + * Create the context instance base on system resources & display information which used for UI. + * @param displayId The ID of the display where the UI is shown. + * @see ContextImpl#createSystemUiContext(ContextImpl, int) + */ + public ContextImpl createSystemUiContext(int displayId) { + return ContextImpl.createSystemUiContext(getSystemUiContext(), displayId); + } + public void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { synchronized (this) { getSystemContext().installSystemApplicationInfo(info, classLoader); diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index c7a9d99fe927..92cdb20c7f4f 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -2407,16 +2407,28 @@ class ContextImpl extends Context { /** * System Context to be used for UI. This Context has resources that can be themed. * Make sure that the created system UI context shares the same LoadedApk as the system context. + * @param systemContext The system context which created by + * {@link #createSystemContext(ActivityThread)}. + * @param displayId The ID of the display where the UI is shown. */ - static ContextImpl createSystemUiContext(ContextImpl systemContext) { + static ContextImpl createSystemUiContext(ContextImpl systemContext, int displayId) { final LoadedApk packageInfo = systemContext.mPackageInfo; ContextImpl context = new ContextImpl(null, systemContext.mMainThread, packageInfo, null, null, null, 0, null); - context.setResources(createResources(null, packageInfo, null, Display.DEFAULT_DISPLAY, null, + context.setResources(createResources(null, packageInfo, null, displayId, null, packageInfo.getCompatibilityInfo())); + context.updateDisplay(displayId); return context; } + /** + * The overloaded method of {@link #createSystemUiContext(ContextImpl, int)}. + * Uses {@Code Display.DEFAULT_DISPLAY} as the target display. + */ + static ContextImpl createSystemUiContext(ContextImpl systemContext) { + return createSystemUiContext(systemContext, Display.DEFAULT_DISPLAY); + } + @UnsupportedAppUsage static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 1b2d8b1d7791..e57fdffdfd1a 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -2354,17 +2354,19 @@ public final class InputMethodManager { } /** - * Shows the input method chooser dialog. + * Shows the input method chooser dialog from system. * * @param showAuxiliarySubtypes Set true to show auxiliary input methods. + * @param displayId The ID of the display where the chooser dialog should be shown. * @hide */ - public void showInputMethodPicker(boolean showAuxiliarySubtypes) { + @RequiresPermission(WRITE_SECURE_SETTINGS) + public void showInputMethodPickerFromSystem(boolean showAuxiliarySubtypes, int displayId) { final int mode = showAuxiliarySubtypes ? SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES : SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES; try { - mService.showInputMethodPickerFromClient(mClient, mode); + mService.showInputMethodPickerFromSystem(mClient, mode, displayId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index a5c505dba4bc..f62c4402cb4e 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -64,6 +64,8 @@ interface IInputMethodManager { void showInputMethodPickerFromClient(in IInputMethodClient client, int auxiliarySubtypeMode); + void showInputMethodPickerFromSystem(in IInputMethodClient client, int auxiliarySubtypeMode, + int displayId); void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId); boolean isInputMethodPickerShownForTest(); // TODO(Bug 114488811): this can be removed once we deprecate special null token rule. diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java index 6b24ad56d01c..41afa9a21128 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java @@ -193,7 +193,8 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView public void onClick(View v) { mCallback.userActivity(); // Leave the screen on a bit longer // Do not show auxiliary subtypes in password lock screen. - mImm.showInputMethodPicker(false /* showAuxiliarySubtypes */); + mImm.showInputMethodPickerFromSystem(false /* showAuxiliarySubtypes */, + getContext().getDisplayId()); } }); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index a0021ea13617..30e840926698 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -213,8 +213,8 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { @Override public void onClick(View view) { - mContext.getSystemService(InputMethodManager.class) - .showInputMethodPicker(true /* showAuxiliarySubtypes */); + mContext.getSystemService(InputMethodManager.class).showInputMethodPickerFromSystem( + true /* showAuxiliarySubtypes */, getContext().getDisplayId()); } }; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 7717a57be3df..28a6ba4ceb1d 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -984,9 +984,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // {@link #canShowInputMethodPickerLocked(IInputMethodClient)}. mHandler.obtainMessage( MSG_SHOW_IM_SUBTYPE_PICKER, + // TODO(b/120076400): Design and implement IME switcher for heterogeneous + // navbar configuration. InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, - 0 /* arg2 */) - .sendToTarget(); + DEFAULT_DISPLAY).sendToTarget(); } else { Slog.w(TAG, "Unexpected intent " + intent); } @@ -3034,9 +3035,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private boolean canShowInputMethodPickerLocked(IInputMethodClient client) { // TODO(yukawa): multi-display support. final int uid = Binder.getCallingUid(); - if (UserHandle.getAppId(uid) == Process.SYSTEM_UID) { - return true; - } else if (mCurFocusedWindowClient != null && client != null + if (mCurFocusedWindowClient != null && client != null && mCurFocusedWindowClient.client.asBinder() == client.asBinder()) { return true; } else if (mCurIntent != null && InputMethodUtils.checkIfPackageBelongsToUid( @@ -3044,12 +3043,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub uid, mCurIntent.getComponent().getPackageName())) { return true; - } else if (mContext.checkCallingPermission( - android.Manifest.permission.WRITE_SECURE_SETTINGS) - == PackageManager.PERMISSION_GRANTED) { - return true; } - return false; } @@ -3068,11 +3062,26 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // Always call subtype picker, because subtype picker is a superset of input method // picker. - mHandler.sendMessage(mCaller.obtainMessageI( - MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode)); + mHandler.sendMessage(mCaller.obtainMessageII( + MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, + (mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY)); } } + @Override + public void showInputMethodPickerFromSystem(IInputMethodClient client, int auxiliarySubtypeMode, + int displayId) { + if (mContext.checkCallingPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) + != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException( + "showInputMethodPickerFromSystem requires WRITE_SECURE_SETTINGS permission"); + } + // Always call subtype picker, because subtype picker is a superset of input method + // picker. + mHandler.sendMessage(mCaller.obtainMessageII( + MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId)); + } + public boolean isInputMethodPickerShownForTest() { synchronized(mMethodMap) { if (mSwitchingDialog == null) { @@ -3405,6 +3414,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub switch (msg.what) { case MSG_SHOW_IM_SUBTYPE_PICKER: final boolean showAuxSubtypes; + final int displayId = msg.arg2; switch (msg.arg1) { case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: // This is undocumented so far, but IMM#showInputMethodPicker() has been @@ -3422,7 +3432,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); return false; } - showInputMethodMenu(showAuxSubtypes); + showInputMethodMenu(showAuxSubtypes, displayId); return true; case MSG_SHOW_IM_SUBTYPE_ENABLER: @@ -3802,7 +3812,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); } - private void showInputMethodMenu(boolean showAuxSubtypes) { + private void showInputMethodMenu(boolean showAuxSubtypes, int displayId) { if (DEBUG) Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes); final boolean isScreenLocked = isScreenLocked(); @@ -3848,8 +3858,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } + final ActivityThread currentThread = ActivityThread.currentActivityThread(); final Context settingsContext = new ContextThemeWrapper( - ActivityThread.currentActivityThread().getSystemUiContext(), + displayId == DEFAULT_DISPLAY ? currentThread.getSystemUiContext() + : currentThread.createSystemUiContext(displayId), com.android.internal.R.style.Theme_DeviceDefault_Settings); mDialogBuilder = new AlertDialog.Builder(settingsContext); diff --git a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java index 128d4d49a39b..5edb5c8e3286 100644 --- a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java @@ -1541,6 +1541,13 @@ public final class MultiClientInputMethodManagerService { @BinderThread @Override + public void showInputMethodPickerFromSystem( + IInputMethodClient client, int auxiliarySubtypeMode, int displayId) { + reportNotSupported(); + } + + @BinderThread + @Override public void showInputMethodAndSubtypeEnablerFromClient( IInputMethodClient client, String inputMethodId) { reportNotSupported(); |