From 777ef95ebf18c61ff09e7567a06058d351c530ca Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 25 Nov 2015 20:32:24 -0800 Subject: [PATCH 1/2] Use Context.getSystemService(Class) for InputMethodManager. This is a mechanical replacement of Context.getSystemService(String) with Context.getSystemService(Class) when retrieving InputMethodManager. Note those are bundled code. Hence we don't need to make sure Build.VERSION.SDK_INT >= 23. Change-Id: Icc64942ad8f11e44bf84f8d4fe476b2fdd1257f3 --- core/java/android/app/NativeActivity.java | 4 ++-- core/java/android/app/SearchDialog.java | 6 ++---- core/java/android/webkit/FindActionModeCallback.java | 3 +-- core/java/android/widget/AbsListView.java | 4 ++-- core/java/android/widget/SearchView.java | 10 ++++------ .../src/com/android/printspooler/ui/PrintActivity.java | 3 +-- .../systemui/statusbar/phone/NavigationBarView.java | 2 +- .../com/android/server/TextServicesManagerService.java | 3 +-- .../devicepolicy/DevicePolicyManagerService.java | 8 ++++---- 9 files changed, 18 insertions(+), 25 deletions(-) diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java index 2e05edb2e7d9e..1370000fe0925 100644 --- a/core/java/android/app/NativeActivity.java +++ b/core/java/android/app/NativeActivity.java @@ -129,8 +129,8 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2, String libname = "main"; String funcname = "ANativeActivity_onCreate"; ActivityInfo ai; - - mIMM = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + + mIMM = getSystemService(InputMethodManager.class); getWindow().takeSurface(this); getWindow().takeInputQueue(this); diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java index fa11221cc841e..9c18df8c6c2ab 100644 --- a/core/java/android/app/SearchDialog.java +++ b/core/java/android/app/SearchDialog.java @@ -505,8 +505,7 @@ public class SearchDialog extends Dialog { // We made sure the IME was displayed, so also make sure it is closed // when we go away. - InputMethodManager imm = (InputMethodManager)getContext() - .getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.hideSoftInputFromWindow( getWindow().getDecorView().getWindowToken(), 0); @@ -643,8 +642,7 @@ public class SearchDialog extends Dialog { public void onBackPressed() { // If the input method is covering the search dialog completely, // e.g. in landscape mode with no hard keyboard, dismiss just the input method - InputMethodManager imm = (InputMethodManager)getContext() - .getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null && imm.isFullscreenMode() && imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0)) { return; diff --git a/core/java/android/webkit/FindActionModeCallback.java b/core/java/android/webkit/FindActionModeCallback.java index b3b95f8c9dd2b..f313893505195 100644 --- a/core/java/android/webkit/FindActionModeCallback.java +++ b/core/java/android/webkit/FindActionModeCallback.java @@ -61,8 +61,7 @@ public class FindActionModeCallback implements ActionMode.Callback, TextWatcher, setText(""); mMatches = (TextView) mCustomView.findViewById( com.android.internal.R.id.matches); - mInput = (InputMethodManager) - context.getSystemService(Context.INPUT_METHOD_SERVICE); + mInput = context.getSystemService(InputMethodManager.class); mResources = context.getResources(); } diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 90de0539df921..f050e49f0b05b 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -5755,8 +5755,8 @@ public abstract class AbsListView extends AdapterView implements Te // The editor is off in its own window; we need to be // the one that does this. if (editorAction == EditorInfo.IME_ACTION_DONE) { - InputMethodManager imm = (InputMethodManager) - getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = + getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index ad2b4a714b824..88f02d1fcd5fb 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -152,8 +152,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { */ private Runnable mShowImeRunnable = new Runnable() { public void run() { - InputMethodManager imm = (InputMethodManager) - getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.showSoftInputUnchecked(0, null); @@ -912,8 +911,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { post(mShowImeRunnable); } else { removeCallbacks(mShowImeRunnable); - InputMethodManager imm = (InputMethodManager) - getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); @@ -1768,8 +1766,8 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { super.onWindowFocusChanged(hasWindowFocus); if (hasWindowFocus && mSearchView.hasFocus() && getVisibility() == VISIBLE) { - InputMethodManager inputManager = (InputMethodManager) getContext() - .getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager inputManager = + getContext().getSystemService(InputMethodManager.class); inputManager.showSoftInput(this, 0); // If in landscape mode, then make sure that // the ime is in front of the dropdown. diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index 67e170fa30640..652156542575a 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -556,8 +556,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // Make sure the IME is not on the way of preview as // the user may have used it to type copies or range. - InputMethodManager imm = (InputMethodManager) getSystemService( - Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = getSystemService(InputMethodManager.class); imm.hideSoftInputFromWindow(mDestinationSpinner.getWindowToken(), 0); } 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 e1aec6f5d8683..cddb1fc3a6ad2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -143,7 +143,7 @@ public class NavigationBarView extends LinearLayout { private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { @Override public void onClick(View view) { - ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) + mContext.getSystemService(InputMethodManager.class) .showInputMethodPicker(true /* showAuxiliarySubtypes */); } }; diff --git a/services/core/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java index fc3a322670ee4..fcd56eb700809 100644 --- a/services/core/java/com/android/server/TextServicesManagerService.java +++ b/services/core/java/com/android/server/TextServicesManagerService.java @@ -446,8 +446,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub { String candidateLocale = null; if (hashCode == 0) { // Spell checker language settings == "auto" - final InputMethodManager imm = - (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); + final InputMethodManager imm = mContext.getSystemService(InputMethodManager.class); if (imm != null) { final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype(); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 819925080ea37..47951deceea0c 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -5567,8 +5567,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // InputMethodManager fetches input methods for current user. // So this can only be set when calling user is the current user // or parent is current user in case of managed profiles. - InputMethodManager inputMethodManager = (InputMethodManager) mContext - .getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager inputMethodManager = + mContext.getSystemService(InputMethodManager.class); List enabledImes = inputMethodManager.getEnabledInputMethodList(); if (enabledImes != null) { @@ -5646,8 +5646,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // If we have a permitted list add all system input methods. if (result != null) { - InputMethodManager inputMethodManager = (InputMethodManager) mContext - .getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager inputMethodManager = + mContext.getSystemService(InputMethodManager.class); List imes = inputMethodManager.getInputMethodList(); long id = mInjector.binderClearCallingIdentity(); try { From 8ce2a538d9b94a0d8e1543c4ee4620a8af525276 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 25 Nov 2015 20:35:04 -0800 Subject: [PATCH 2/2] Use Context.getSystemService(Class) for InputManager. This is a mechanical replacement of Context.getSystemService(String) with Context.getSystemService(Class) when retrieving InputManager. Note those are bundled code. Hence we don't need to make sure Build.VERSION.SDK_INT >= 23. Change-Id: Iee47e374e1349720e3100bab33ed139e1f47c169 --- core/java/com/android/internal/widget/PointerLocationView.java | 2 +- .../SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java | 2 +- services/core/java/com/android/server/VibratorService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java index e339c44db16e7..592576bb41d06 100644 --- a/core/java/com/android/internal/widget/PointerLocationView.java +++ b/core/java/com/android/internal/widget/PointerLocationView.java @@ -137,7 +137,7 @@ public class PointerLocationView extends View implements InputDeviceListener, super(c); setFocusableInTouchMode(true); - mIm = (InputManager)c.getSystemService(Context.INPUT_SERVICE); + mIm = c.getSystemService(InputManager.class); mVC = ViewConfiguration.get(c); mTextPaint = new Paint(); diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java b/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java index 96ee39756513e..d931856a822b1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java +++ b/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java @@ -180,7 +180,7 @@ public class KeyboardUI extends SystemUI implements InputManager.OnTabletModeCha mProfileManager = bluetoothManager.getProfileManager(); bluetoothManager.getEventManager().registerCallback(new BluetoothCallbackHandler()); - InputManager im = (InputManager) context.getSystemService(Context.INPUT_SERVICE); + InputManager im = context.getSystemService(InputManager.class); im.registerOnTabletModeChangedListener(this, mHandler); mInTabletMode = im.isInTabletMode(); diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 9eb66dd281e1c..2924cef09d17d 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -223,7 +223,7 @@ public class VibratorService extends IVibratorService.Stub } public void systemReady() { - mIm = (InputManager)mContext.getSystemService(Context.INPUT_SERVICE); + mIm = mContext.getSystemService(InputManager.class); mSettingObserver = new SettingsObserver(mH); mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);