summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wilson Wu <wilsonwu@google.com> 2020-11-24 11:39:19 +0800
committer Wilson Wu <wilsonwu@google.com> 2020-11-24 18:48:23 +0800
commit16b795f36d20ceeabadf04a8ea4933fd6e15fd77 (patch)
tree5412f9b9c00a9518b4e4df4a702186f509056e7f
parentf48a5e3d132521c53bc9f372e11de7dc5c273908 (diff)
Make IInputMethodManager to oneway (2/N)
Make methods(await, logging) to utility in Completable so that other modules could use them directly. Bug: 163453493 Test: Manual test with keyboard Test: atest CtsInputMethodTestCases Change-Id: Idedb9de658de3e6e91afad16bab0c428ee68e7b3
-rw-r--r--core/java/com/android/internal/inputmethod/Completable.java50
-rw-r--r--core/java/com/android/internal/view/InputConnectionWrapper.java63
2 files changed, 66 insertions, 47 deletions
diff --git a/core/java/com/android/internal/inputmethod/Completable.java b/core/java/com/android/internal/inputmethod/Completable.java
index 16473b98b813..d8d1a7df6aa8 100644
--- a/core/java/com/android/internal/inputmethod/Completable.java
+++ b/core/java/com/android/internal/inputmethod/Completable.java
@@ -19,6 +19,7 @@ package com.android.internal.inputmethod;
import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.util.Log;
import com.android.internal.annotations.GuardedBy;
@@ -275,4 +276,53 @@ public final class Completable {
*/
public static final class InputBindResult
extends Values<com.android.internal.view.InputBindResult> { }
+
+ /**
+ * Await the result by the {@link Completable.Int}, and log it if there is no result after
+ * given timeout.
+ *
+ * @return the result once {@link ValueBase#onComplete()}
+ */
+ @AnyThread
+ public static int getResultOrZero(@NonNull Completable.Int value, String tag,
+ @NonNull String methodName, @Nullable CancellationGroup cancellationGroup,
+ int maxWaitTime) {
+ final boolean timedOut = value.await(maxWaitTime, TimeUnit.MILLISECONDS, cancellationGroup);
+ if (value.hasValue()) {
+ return value.getValue();
+ }
+ logInternal(tag, methodName, timedOut, maxWaitTime, 0);
+ return 0;
+ }
+
+ /**
+ * Await the result by the {@link Completable.Values}, and log it if there is no result after
+ * given timeout.
+ *
+ * @return the result once {@link ValueBase#onComplete()}
+ */
+ @AnyThread
+ @Nullable
+ public static <T> T getResultOrNull(@NonNull Completable.Values<T> value, String tag,
+ @NonNull String methodName, @Nullable CancellationGroup cancellationGroup,
+ int maxWaitTime) {
+ final boolean timedOut = value.await(maxWaitTime, TimeUnit.MILLISECONDS, cancellationGroup);
+ if (value.hasValue()) {
+ return value.getValue();
+ }
+ logInternal(tag, methodName, timedOut, maxWaitTime, null);
+ return null;
+ }
+
+ @AnyThread
+ private static void logInternal(String tag, @Nullable String methodName, boolean timedOut,
+ int maxWaitTime, @Nullable Object defaultValue) {
+ if (timedOut) {
+ Log.w(tag, methodName + " didn't respond in " + maxWaitTime + " msec."
+ + " Returning default: " + defaultValue);
+ } else {
+ Log.w(tag, methodName + " was canceled before complete. Returning default: "
+ + defaultValue);
+ }
+ }
}
diff --git a/core/java/com/android/internal/view/InputConnectionWrapper.java b/core/java/com/android/internal/view/InputConnectionWrapper.java
index ec4fe17746ee..8c763a6efe54 100644
--- a/core/java/com/android/internal/view/InputConnectionWrapper.java
+++ b/core/java/com/android/internal/view/InputConnectionWrapper.java
@@ -24,7 +24,6 @@ import android.inputmethodservice.AbstractInputMethodService;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
-import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
@@ -41,7 +40,6 @@ import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.ResultCallbacks;
import java.lang.ref.WeakReference;
-import java.util.concurrent.TimeUnit;
public class InputConnectionWrapper implements InputConnection {
private static final String TAG = "InputConnectionWrapper";
@@ -73,43 +71,6 @@ public class InputConnectionWrapper implements InputConnection {
mCancellationGroup = cancellationGroup;
}
- @AnyThread
- private static void logInternal(@Nullable String methodName, boolean timedOut,
- @Nullable Object defaultValue) {
- if (timedOut) {
- Log.w(TAG, methodName + " didn't respond in " + MAX_WAIT_TIME_MILLIS + " msec."
- + " Returning default: " + defaultValue);
- } else {
- Log.w(TAG, methodName + " was canceled before complete. Returning default: "
- + defaultValue);
- }
- }
-
- @AnyThread
- private static int getResultOrZero(@NonNull Completable.Int value, @NonNull String methodName,
- @Nullable CancellationGroup cancellationGroup) {
- final boolean timedOut =
- value.await(MAX_WAIT_TIME_MILLIS, TimeUnit.MILLISECONDS, cancellationGroup);
- if (value.hasValue()) {
- return value.getValue();
- }
- logInternal(methodName, timedOut, 0);
- return 0;
- }
-
- @AnyThread
- @Nullable
- private static <T> T getResultOrNull(@NonNull Completable.Values<T> value,
- @NonNull String methodName, @Nullable CancellationGroup cancellationGroup) {
- final boolean timedOut =
- value.await(MAX_WAIT_TIME_MILLIS, TimeUnit.MILLISECONDS, cancellationGroup);
- if (value.hasValue()) {
- return value.getValue();
- }
- logInternal(methodName, timedOut, null);
- return null;
- }
-
/**
* See {@link InputConnection#getTextAfterCursor(int, int)}.
*/
@@ -126,7 +87,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return null;
}
- return getResultOrNull(value, "getTextAfterCursor()", mCancellationGroup);
+ return Completable.getResultOrNull(
+ value, TAG, "getTextAfterCursor()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
}
/**
@@ -145,7 +107,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return null;
}
- return getResultOrNull(value, "getTextBeforeCursor()", mCancellationGroup);
+ return Completable.getResultOrNull(
+ value, TAG, "getTextBeforeCursor()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
}
@AnyThread
@@ -164,7 +127,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return null;
}
- return getResultOrNull(value, "getSelectedText()", mCancellationGroup);
+ return Completable.getResultOrNull(
+ value, TAG, "getSelectedText()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
}
/**
@@ -197,7 +161,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return null;
}
- return getResultOrNull(value, "getSurroundingText()", mCancellationGroup);
+ return Completable.getResultOrNull(
+ value, TAG, "getSurroundingText()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
}
@AnyThread
@@ -212,7 +177,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return 0;
}
- return getResultOrZero(value, "getCursorCapsMode()", mCancellationGroup);
+ return Completable.getResultOrZero(
+ value, TAG, "getCursorCapsMode()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
}
@AnyThread
@@ -227,7 +193,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return null;
}
- return getResultOrNull(value, "getExtractedText()", mCancellationGroup);
+ return Completable.getResultOrNull(
+ value, TAG, "getExtractedText()", mCancellationGroup, MAX_WAIT_TIME_MILLIS);
}
@AnyThread
@@ -438,7 +405,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return false;
}
- return getResultOrZero(value, "requestUpdateCursorAnchorInfo()", mCancellationGroup) != 0;
+ return Completable.getResultOrZero(value, TAG, "requestUpdateCursorAnchorInfo()",
+ mCancellationGroup, MAX_WAIT_TIME_MILLIS) != 0;
}
@AnyThread
@@ -478,7 +446,8 @@ public class InputConnectionWrapper implements InputConnection {
} catch (RemoteException e) {
return false;
}
- return getResultOrZero(value, "commitContent()", mCancellationGroup) != 0;
+ return Completable.getResultOrZero(
+ value, TAG, "commitContent()", mCancellationGroup, MAX_WAIT_TIME_MILLIS) != 0;
}
@AnyThread