Move encapsulated members to binding controller

Bug: 205676419
Test: make
Change-Id: Ic3d525a4e1bf8f20f6e62ab6bb061f8bad09535d
This commit is contained in:
Nikolas Havrikov
2021-11-08 11:42:17 +01:00
parent 29e2529ca4
commit 2be64fc442
2 changed files with 136 additions and 35 deletions

View File

@@ -17,6 +17,10 @@
package com.android.server.inputmethod;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Intent;
import android.os.IBinder;
import android.view.inputmethod.InputMethodInfo;
/**
* A controller managing the state of the input method binding.
@@ -27,7 +31,122 @@ final class InputMethodBindingController {
private final InputMethodManagerService mService;
private long mLastBindTime;
private boolean mHasConnection;
@Nullable private String mCurId;
@Nullable private String mSelectedMethodId;
@Nullable private Intent mCurIntent;
private IBinder mCurToken;
private int mCurSeq;
InputMethodBindingController(@NonNull InputMethodManagerService service) {
mService = service;
}
/**
* Time that we last initiated a bind to the input method, to determine
* if we should try to disconnect and reconnect to it.
*/
long getLastBindTime() {
return mLastBindTime;
}
void setLastBindTime(long lastBindTime) {
mLastBindTime = lastBindTime;
}
/**
* Set to true if our ServiceConnection is currently actively bound to
* a service (whether or not we have gotten its IBinder back yet).
*/
boolean hasConnection() {
return mHasConnection;
}
void setHasConnection(boolean hasConnection) {
mHasConnection = hasConnection;
}
/**
* Id obtained with {@link InputMethodInfo#getId()} for the input method that we are currently
* connected to or in the process of connecting to.
*
* <p>This can be {@code null} when no input method is connected.</p>
*
* @see #getSelectedMethodId()
*/
@Nullable
String getCurId() {
return mCurId;
}
void setCurId(@Nullable String curId) {
mCurId = curId;
}
/**
* Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method.
* This is to be synchronized with the secure settings keyed with
* {@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD}.
*
* <p>This can be transiently {@code null} when the system is re-initializing input method
* settings, e.g., the system locale is just changed.</p>
*
* <p>Note that {@link #getCurId()} is used to track which IME is being connected to
* {@link com.android.server.inputmethod.InputMethodManagerService}.</p>
*
* @see #getCurId()
*/
@Nullable
String getSelectedMethodId() {
return mSelectedMethodId;
}
void setSelectedMethodId(@Nullable String selectedMethodId) {
mSelectedMethodId = selectedMethodId;
}
/**
* The token we have made for the currently active input method, to
* identify it in the future.
*/
IBinder getCurToken() {
return mCurToken;
}
void setCurToken(IBinder curToken) {
mCurToken = curToken;
}
/**
* The Intent used to connect to the current input method.
*/
@Nullable
Intent getCurIntent() {
return mCurIntent;
}
void setCurIntent(@Nullable Intent curIntent) {
mCurIntent = curIntent;
}
/**
* The current binding sequence number, incremented every time there is
* a new bind performed.
*/
int getSequenceNumber() {
return mCurSeq;
}
/**
* Increase the current binding sequence number by one.
* Reset to 1 on overflow.
*/
void advanceSequenceNumber() {
mCurSeq += 1;
if (mCurSeq <= 0) {
mCurSeq = 1;
}
}
}

View File

@@ -469,28 +469,26 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
* <p>This can be transiently {@code null} when the system is re-initializing input method
* settings, e.g., the system locale is just changed.</p>
*
* <p>Note that {@link #getCurId()} is used to track which IME is being connected to
* {@link InputMethodManagerService}.</p>
* <p>Note that {@link InputMethodBindingController#getCurId()} is used to track which IME is
* being connected to {@link InputMethodManagerService}.</p>
*
* @see #getCurId()
* @see InputMethodBindingController#getCurId()
*/
@Nullable
private String getSelectedMethodId() {
return mSelectedMethodId;
return mBindingController.getSelectedMethodId();
}
private void setSelectedMethodId(@Nullable String selectedMethodId) {
mSelectedMethodId = selectedMethodId;
mBindingController.setSelectedMethodId(selectedMethodId);
}
@Nullable
private String mSelectedMethodId;
/**
* The current binding sequence number, incremented every time there is
* a new bind performed.
*/
private int getSequenceNumber() {
return mCurSeq;
return mBindingController.getSequenceNumber();
}
/**
@@ -498,14 +496,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
* Reset to 1 on overflow.
*/
private void advanceSequenceNumber() {
mCurSeq += 1;
if (mCurSeq <= 0) {
mCurSeq = 1;
}
mBindingController.advanceSequenceNumber();
}
private int mCurSeq;
/**
* {@code true} if the Ime policy has been set to {@link WindowManager#DISPLAY_IME_POLICY_HIDE}.
*
@@ -565,16 +558,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
*/
@Nullable
private String getCurId() {
return mCurId;
return mBindingController.getCurId();
}
private void setCurId(@Nullable String curId) {
mCurId = curId;
mBindingController.setCurId(curId);
}
@Nullable
private String mCurId;
/**
* The current subtype of the current input method.
*/
@@ -590,13 +580,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
* a service (whether or not we have gotten its IBinder back yet).
*/
private boolean hasConnection() {
return mHasConnection;
return mBindingController.hasConnection();
}
private void setHasConnection(boolean hasConnection) {
mHasConnection = hasConnection;
mBindingController.setHasConnection(hasConnection);
}
private boolean mHasConnection;
/**
* Set if the client has asked for the input method to be shown.
@@ -628,30 +617,25 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
*/
@Nullable
private Intent getCurIntent() {
return mCurIntent;
return mBindingController.getCurIntent();
}
private void setCurIntent(@Nullable Intent curIntent) {
mCurIntent = curIntent;
mBindingController.setCurIntent(curIntent);
}
@Nullable
private Intent mCurIntent;
/**
* The token we have made for the currently active input method, to
* identify it in the future.
*/
private IBinder getCurToken() {
return mCurToken;
return mBindingController.getCurToken();
}
private void setCurToken(IBinder curToken) {
mCurToken = curToken;
mBindingController.setCurToken(curToken);
}
private IBinder mCurToken;
/**
* The displayId of current active input method.
*/
@@ -688,15 +672,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
* if we should try to disconnect and reconnect to it.
*/
private long getLastBindTime() {
return mLastBindTime;
return mBindingController.getLastBindTime();
}
private void setLastBindTime(long lastBindTime) {
mLastBindTime = lastBindTime;
mBindingController.setLastBindTime(lastBindTime);
}
private long mLastBindTime;
/**
* Have we called mCurMethod.bindInput()?
*/