MSIME sample: Make lastClientId non-static
This is a followup for comment in I77bf8c844838f32888004611975cfa316255961b lastClientId doesn't need to be static as MultiClientInputMethod is single instance. Bug: 128751901 Test: Manually verified using steps in bug. Change-Id: I049a5e9966408b1d304e23713fae2c3597d89a5c
This commit is contained in:
@@ -41,10 +41,13 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
||||
private final int mSelfReportedDisplayId;
|
||||
private final KeyEvent.DispatcherState mDispatcherState;
|
||||
private final Looper mLooper;
|
||||
private final MultiClientInputMethod mInputMethod;
|
||||
|
||||
ClientCallbackImpl(MultiClientInputMethodServiceDelegate delegate,
|
||||
ClientCallbackImpl(MultiClientInputMethod inputMethod,
|
||||
MultiClientInputMethodServiceDelegate delegate,
|
||||
SoftInputWindowManager softInputWindowManager, int clientId, int uid, int pid,
|
||||
int selfReportedDisplayId) {
|
||||
mInputMethod = inputMethod;
|
||||
mDelegate = delegate;
|
||||
mSoftInputWindowManager = softInputWindowManager;
|
||||
mClientId = clientId;
|
||||
@@ -53,7 +56,9 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
||||
mSelfReportedDisplayId = selfReportedDisplayId;
|
||||
mDispatcherState = new KeyEvent.DispatcherState();
|
||||
// For simplicity, we use the main looper for this sample.
|
||||
// To use other looper thread, make sure that the IME Window also runs on the same looper.
|
||||
// To use other looper thread, make sure that the IME Window also runs on the same looper
|
||||
// and introduce an appropriate synchronization mechanism instead of directly accessing
|
||||
// MultiClientInputMethod#mLastClientId.
|
||||
mLooper = Looper.getMainLooper();
|
||||
}
|
||||
|
||||
@@ -154,8 +159,8 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
||||
}
|
||||
if (inputConnection == null || editorInfo == null) {
|
||||
// deactivate previous client.
|
||||
if (MultiClientInputMethod.sLastClientId != mClientId) {
|
||||
mDelegate.setActive(MultiClientInputMethod.sLastClientId, false /* active */);
|
||||
if (mInputMethod.mLastClientId != mClientId) {
|
||||
mDelegate.setActive(mInputMethod.mLastClientId, false /* active */);
|
||||
}
|
||||
// Dummy InputConnection case.
|
||||
if (window.getClientId() == mClientId) {
|
||||
@@ -166,7 +171,7 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
||||
window.onDummyStartInput(mClientId, targetWindowHandle);
|
||||
}
|
||||
} else {
|
||||
if (MultiClientInputMethod.sLastClientId != mClientId) {
|
||||
if (mInputMethod.mLastClientId != mClientId) {
|
||||
mDelegate.setActive(mClientId, true /* active */);
|
||||
}
|
||||
window.onStartInput(mClientId, targetWindowHandle, inputConnection);
|
||||
@@ -190,7 +195,7 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
||||
window.hide();
|
||||
break;
|
||||
}
|
||||
MultiClientInputMethod.sLastClientId = mClientId;
|
||||
mInputMethod.mLastClientId = mClientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,8 +28,9 @@ import android.util.Log;
|
||||
public final class MultiClientInputMethod extends Service {
|
||||
private static final String TAG = "MultiClientInputMethod";
|
||||
private static final boolean DEBUG = false;
|
||||
static int sLastClientId = MultiClientInputMethodServiceDelegate.INVALID_CLIENT_ID;
|
||||
|
||||
// last client that had active InputConnection.
|
||||
int mLastClientId = MultiClientInputMethodServiceDelegate.INVALID_CLIENT_ID;
|
||||
SoftInputWindowManager mSoftInputWindowManager;
|
||||
MultiClientInputMethodServiceDelegate mDelegate;
|
||||
|
||||
@@ -50,7 +51,8 @@ public final class MultiClientInputMethod extends Service {
|
||||
@Override
|
||||
public void addClient(int clientId, int uid, int pid,
|
||||
int selfReportedDisplayId) {
|
||||
final ClientCallbackImpl callback = new ClientCallbackImpl(mDelegate,
|
||||
final ClientCallbackImpl callback = new ClientCallbackImpl(
|
||||
MultiClientInputMethod.this, mDelegate,
|
||||
mSoftInputWindowManager, clientId, uid, pid, selfReportedDisplayId);
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "addClient clientId=" + clientId + " uid=" + uid
|
||||
|
||||
Reference in New Issue
Block a user