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 int mSelfReportedDisplayId;
|
||||||
private final KeyEvent.DispatcherState mDispatcherState;
|
private final KeyEvent.DispatcherState mDispatcherState;
|
||||||
private final Looper mLooper;
|
private final Looper mLooper;
|
||||||
|
private final MultiClientInputMethod mInputMethod;
|
||||||
|
|
||||||
ClientCallbackImpl(MultiClientInputMethodServiceDelegate delegate,
|
ClientCallbackImpl(MultiClientInputMethod inputMethod,
|
||||||
|
MultiClientInputMethodServiceDelegate delegate,
|
||||||
SoftInputWindowManager softInputWindowManager, int clientId, int uid, int pid,
|
SoftInputWindowManager softInputWindowManager, int clientId, int uid, int pid,
|
||||||
int selfReportedDisplayId) {
|
int selfReportedDisplayId) {
|
||||||
|
mInputMethod = inputMethod;
|
||||||
mDelegate = delegate;
|
mDelegate = delegate;
|
||||||
mSoftInputWindowManager = softInputWindowManager;
|
mSoftInputWindowManager = softInputWindowManager;
|
||||||
mClientId = clientId;
|
mClientId = clientId;
|
||||||
@@ -53,7 +56,9 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
|||||||
mSelfReportedDisplayId = selfReportedDisplayId;
|
mSelfReportedDisplayId = selfReportedDisplayId;
|
||||||
mDispatcherState = new KeyEvent.DispatcherState();
|
mDispatcherState = new KeyEvent.DispatcherState();
|
||||||
// For simplicity, we use the main looper for this sample.
|
// 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();
|
mLooper = Looper.getMainLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +159,8 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
|||||||
}
|
}
|
||||||
if (inputConnection == null || editorInfo == null) {
|
if (inputConnection == null || editorInfo == null) {
|
||||||
// deactivate previous client.
|
// deactivate previous client.
|
||||||
if (MultiClientInputMethod.sLastClientId != mClientId) {
|
if (mInputMethod.mLastClientId != mClientId) {
|
||||||
mDelegate.setActive(MultiClientInputMethod.sLastClientId, false /* active */);
|
mDelegate.setActive(mInputMethod.mLastClientId, false /* active */);
|
||||||
}
|
}
|
||||||
// Dummy InputConnection case.
|
// Dummy InputConnection case.
|
||||||
if (window.getClientId() == mClientId) {
|
if (window.getClientId() == mClientId) {
|
||||||
@@ -166,7 +171,7 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
|||||||
window.onDummyStartInput(mClientId, targetWindowHandle);
|
window.onDummyStartInput(mClientId, targetWindowHandle);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (MultiClientInputMethod.sLastClientId != mClientId) {
|
if (mInputMethod.mLastClientId != mClientId) {
|
||||||
mDelegate.setActive(mClientId, true /* active */);
|
mDelegate.setActive(mClientId, true /* active */);
|
||||||
}
|
}
|
||||||
window.onStartInput(mClientId, targetWindowHandle, inputConnection);
|
window.onStartInput(mClientId, targetWindowHandle, inputConnection);
|
||||||
@@ -190,7 +195,7 @@ final class ClientCallbackImpl implements MultiClientInputMethodServiceDelegate.
|
|||||||
window.hide();
|
window.hide();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MultiClientInputMethod.sLastClientId = mClientId;
|
mInputMethod.mLastClientId = mClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ import android.util.Log;
|
|||||||
public final class MultiClientInputMethod extends Service {
|
public final class MultiClientInputMethod extends Service {
|
||||||
private static final String TAG = "MultiClientInputMethod";
|
private static final String TAG = "MultiClientInputMethod";
|
||||||
private static final boolean DEBUG = false;
|
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;
|
SoftInputWindowManager mSoftInputWindowManager;
|
||||||
MultiClientInputMethodServiceDelegate mDelegate;
|
MultiClientInputMethodServiceDelegate mDelegate;
|
||||||
|
|
||||||
@@ -50,7 +51,8 @@ public final class MultiClientInputMethod extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void addClient(int clientId, int uid, int pid,
|
public void addClient(int clientId, int uid, int pid,
|
||||||
int selfReportedDisplayId) {
|
int selfReportedDisplayId) {
|
||||||
final ClientCallbackImpl callback = new ClientCallbackImpl(mDelegate,
|
final ClientCallbackImpl callback = new ClientCallbackImpl(
|
||||||
|
MultiClientInputMethod.this, mDelegate,
|
||||||
mSoftInputWindowManager, clientId, uid, pid, selfReportedDisplayId);
|
mSoftInputWindowManager, clientId, uid, pid, selfReportedDisplayId);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, "addClient clientId=" + clientId + " uid=" + uid
|
Log.v(TAG, "addClient clientId=" + clientId + " uid=" + uid
|
||||||
|
|||||||
Reference in New Issue
Block a user