Remove RemoteInputConnectionImpl#mLock, which is redudant
It is guaranteed that the following two boolean expressions have always the same value observed outside from RemoteInputConnectionImpl#mLock. A. RemoteInputConnectionImpl#mFinished B. RemoteInputConnectionImpl#mInputConnection != null With that we should be able to simply merge them into an atomic reference object AtomicReference<InputConnection> without requiring RemoteInputConnectionImpl#mLock as a lock object. This CL does so as a preparation to clean up RemoteInputConnectionImpl for Bug 291826769. There should be no observable behavior change, except for the fact that RemoteInputConnectionImpl#dumpDebug() no longer blocks other operations that required mLock, which is kind of out of our original intention. Bug: 291826769 Test: presubmit Change-Id: I69fa2c81670f84be3dd4a808262758a803f69dfc
This commit is contained in:
@@ -43,7 +43,6 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewRootImpl;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.infra.AndroidFuture;
|
||||
import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
|
||||
import com.android.internal.inputmethod.IRemoteInputConnection;
|
||||
@@ -54,6 +53,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -158,18 +158,13 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
boolean cancellable();
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
@Nullable
|
||||
private InputConnection mInputConnection;
|
||||
@NonNull
|
||||
private final AtomicReference<InputConnection> mInputConnectionRef;
|
||||
|
||||
@NonNull
|
||||
private final Looper mLooper;
|
||||
private final Handler mH;
|
||||
|
||||
private final Object mLock = new Object();
|
||||
@GuardedBy("mLock")
|
||||
private boolean mFinished = false;
|
||||
|
||||
private final InputMethodManager mParentInputMethodManager;
|
||||
private final WeakReference<View> mServedView;
|
||||
|
||||
@@ -185,7 +180,7 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
RemoteInputConnectionImpl(@NonNull Looper looper,
|
||||
@NonNull InputConnection inputConnection,
|
||||
@NonNull InputMethodManager inputMethodManager, @Nullable View servedView) {
|
||||
mInputConnection = inputConnection;
|
||||
mInputConnectionRef = new AtomicReference<>(inputConnection);
|
||||
mLooper = looper;
|
||||
mH = new Handler(mLooper);
|
||||
mParentInputMethodManager = inputMethodManager;
|
||||
@@ -197,9 +192,7 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
*/
|
||||
@Nullable
|
||||
public InputConnection getInputConnection() {
|
||||
synchronized (mLock) {
|
||||
return mInputConnection;
|
||||
}
|
||||
return mInputConnectionRef.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,9 +208,7 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
* {@link InputConnection#closeConnection()} as a result of {@link #deactivate()}.
|
||||
*/
|
||||
private boolean isFinished() {
|
||||
synchronized (mLock) {
|
||||
return mFinished;
|
||||
}
|
||||
return mInputConnectionRef.get() == null;
|
||||
}
|
||||
|
||||
private boolean isActive() {
|
||||
@@ -386,10 +377,7 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
// TODO(b/199934664): See if we can remove this by providing a default impl.
|
||||
}
|
||||
} finally {
|
||||
synchronized (mLock) {
|
||||
mInputConnection = null;
|
||||
mFinished = true;
|
||||
}
|
||||
mInputConnectionRef.set(null);
|
||||
Trace.traceEnd(Trace.TRACE_TAG_INPUT);
|
||||
}
|
||||
|
||||
@@ -441,7 +429,6 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
public String toString() {
|
||||
return "RemoteInputConnectionImpl{"
|
||||
+ "connection=" + getInputConnection()
|
||||
+ " finished=" + isFinished()
|
||||
+ " mParentInputMethodManager.isActive()=" + mParentInputMethodManager.isActive()
|
||||
+ " mServedView=" + mServedView.get()
|
||||
+ "}";
|
||||
@@ -455,16 +442,14 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
|
||||
* {@link DumpableInputConnection#dumpDebug(ProtoOutputStream, long)}.
|
||||
*/
|
||||
public void dumpDebug(ProtoOutputStream proto, long fieldId) {
|
||||
synchronized (mLock) {
|
||||
// Check that the call is initiated in the target thread of the current InputConnection
|
||||
// {@link InputConnection#getHandler} since the messages to IInputConnectionWrapper are
|
||||
// executed on this thread. Otherwise the messages are dispatched to the correct thread
|
||||
// in IInputConnectionWrapper, but this is not wanted while dumpng, for performance
|
||||
// reasons.
|
||||
if ((mInputConnection instanceof DumpableInputConnection)
|
||||
&& mLooper.isCurrentThread()) {
|
||||
((DumpableInputConnection) mInputConnection).dumpDebug(proto, fieldId);
|
||||
}
|
||||
final InputConnection ic = mInputConnectionRef.get();
|
||||
// Check that the call is initiated in the target thread of the current InputConnection
|
||||
// {@link InputConnection#getHandler} since the messages to IInputConnectionWrapper are
|
||||
// executed on this thread. Otherwise the messages are dispatched to the correct thread
|
||||
// in IInputConnectionWrapper, but this is not wanted while dumping, for performance
|
||||
// reasons.
|
||||
if ((ic instanceof DumpableInputConnection) && mLooper.isCurrentThread()) {
|
||||
((DumpableInputConnection) ic).dumpDebug(proto, fieldId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user