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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user