summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java23
-rw-r--r--core/java/com/android/internal/inputmethod/CallbackUtils.java58
-rw-r--r--core/java/com/android/internal/inputmethod/Completable.java28
-rw-r--r--core/java/com/android/internal/inputmethod/IInputMethodSubtypeListResultCallback.aidl25
-rw-r--r--core/java/com/android/internal/inputmethod/IInputMethodSubtypeResultCallback.aidl25
-rw-r--r--core/java/com/android/internal/inputmethod/ResultCallbacks.java76
-rw-r--r--core/java/com/android/internal/view/IInputMethodManager.aidl10
7 files changed, 235 insertions, 10 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 6526b8c4d743..c7c00cb80020 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -1430,8 +1430,13 @@ public final class InputMethodManager {
public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi,
boolean allowsImplicitlySelectedSubtypes) {
try {
- return mService.getEnabledInputMethodSubtypeList(
- imi == null ? null : imi.getId(), allowsImplicitlySelectedSubtypes);
+ final Completable.InputMethodSubtypeList value =
+ Completable.createInputMethodSubtypeList();
+ mService.getEnabledInputMethodSubtypeList(
+ imi == null ? null : imi.getId(),
+ allowsImplicitlySelectedSubtypes,
+ ResultCallbacks.of(value));
+ return Completable.getResult(value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2970,7 +2975,9 @@ public final class InputMethodManager {
*/
public InputMethodSubtype getCurrentInputMethodSubtype() {
try {
- return mService.getCurrentInputMethodSubtype();
+ final Completable.InputMethodSubtype value = Completable.createInputMethodSubtype();
+ mService.getCurrentInputMethodSubtype(ResultCallbacks.of(value));
+ return Completable.getResult(value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -3019,7 +3026,11 @@ public final class InputMethodManager {
}
final List<InputMethodSubtype> enabledSubtypes;
try {
- enabledSubtypes = mService.getEnabledInputMethodSubtypeList(imeId, true);
+ final Completable.InputMethodSubtypeList value =
+ Completable.createInputMethodSubtypeList();
+ mService.getEnabledInputMethodSubtypeList(
+ imeId, true, ResultCallbacks.of(value));
+ enabledSubtypes = Completable.getResult(value);
} catch (RemoteException e) {
return false;
}
@@ -3214,7 +3225,9 @@ public final class InputMethodManager {
public InputMethodSubtype getLastInputMethodSubtype() {
try {
- return mService.getLastInputMethodSubtype();
+ final Completable.InputMethodSubtype value = Completable.createInputMethodSubtype();
+ mService.getLastInputMethodSubtype(ResultCallbacks.of(value));
+ return Completable.getResult(value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/com/android/internal/inputmethod/CallbackUtils.java b/core/java/com/android/internal/inputmethod/CallbackUtils.java
index a77583f87ee4..f72d0e68c38a 100644
--- a/core/java/com/android/internal/inputmethod/CallbackUtils.java
+++ b/core/java/com/android/internal/inputmethod/CallbackUtils.java
@@ -19,9 +19,11 @@ package com.android.internal.inputmethod;
import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.os.RemoteException;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.internal.view.InputBindResult;
+import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
@@ -67,7 +69,7 @@ public final class CallbackUtils {
/**
* A utility method using given {@link IBooleanResultCallback} to callback the result.
*
- * @param callback {@link IInputBindResultResultCallback} to be called back.
+ * @param callback {@link IBooleanResultCallback} to be called back.
* @param resultSupplier the supplier from which the result is provided.
*/
public static void onResult(@NonNull IBooleanResultCallback callback,
@@ -89,4 +91,58 @@ public final class CallbackUtils {
callback.onResult(result);
} catch (RemoteException ignored) { }
}
+
+ /**
+ * A utility method using given {@link IInputMethodSubtypeResultCallback} to callback the
+ * result.
+ *
+ * @param callback {@link IInputMethodSubtypeResultCallback} to be called back.
+ * @param resultSupplier the supplier from which the result is provided.
+ */
+ public static void onResult(@NonNull IInputMethodSubtypeResultCallback callback,
+ @NonNull Supplier<InputMethodSubtype> resultSupplier) {
+ InputMethodSubtype result = null;
+ Throwable exception = null;
+
+ try {
+ result = resultSupplier.get();
+ } catch (Throwable throwable) {
+ exception = throwable;
+ }
+
+ try {
+ if (exception != null) {
+ callback.onError(ThrowableHolder.of(exception));
+ return;
+ }
+ callback.onResult(result);
+ } catch (RemoteException ignored) { }
+ }
+
+ /**
+ * A utility method using given {@link IInputMethodSubtypeListResultCallback} to callback the
+ * result.
+ *
+ * @param callback {@link IInputMethodSubtypeListResultCallback} to be called back.
+ * @param resultSupplier the supplier from which the result is provided.
+ */
+ public static void onResult(@NonNull IInputMethodSubtypeListResultCallback callback,
+ @NonNull Supplier<List<InputMethodSubtype>> resultSupplier) {
+ List<InputMethodSubtype> result = null;
+ Throwable exception = null;
+
+ try {
+ result = resultSupplier.get();
+ } catch (Throwable throwable) {
+ exception = throwable;
+ }
+
+ try {
+ if (exception != null) {
+ callback.onError(ThrowableHolder.of(exception));
+ return;
+ }
+ callback.onResult(result);
+ } catch (RemoteException ignored) { }
+ }
}
diff --git a/core/java/com/android/internal/inputmethod/Completable.java b/core/java/com/android/internal/inputmethod/Completable.java
index bd8c23e66e51..819653642808 100644
--- a/core/java/com/android/internal/inputmethod/Completable.java
+++ b/core/java/com/android/internal/inputmethod/Completable.java
@@ -23,10 +23,12 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.Log;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.internal.annotations.GuardedBy;
import java.lang.annotation.Retention;
+import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -373,6 +375,20 @@ public final class Completable {
}
/**
+ * @return an instance of {@link Completable.InputMethodSubtype}.
+ */
+ public static Completable.InputMethodSubtype createInputMethodSubtype() {
+ return new Completable.InputMethodSubtype();
+ }
+
+ /**
+ * @return an instance of {@link Completable.InputMethodSubtypeList}.
+ */
+ public static Completable.InputMethodSubtypeList createInputMethodSubtypeList() {
+ return new Completable.InputMethodSubtypeList();
+ }
+
+ /**
* Completable object of {@link java.lang.Boolean}.
*/
public static final class Boolean extends Values<java.lang.Boolean> { }
@@ -401,6 +417,18 @@ public final class Completable {
extends Values<com.android.internal.view.InputBindResult> { }
/**
+ * Completable object of {@link android.view.inputmethod.InputMethodSubtype}.
+ */
+ public static final class InputMethodSubtype
+ extends Values<android.view.inputmethod.InputMethodSubtype> { }
+
+ /**
+ * Completable object of {@link List<android.view.inputmethod.InputMethodSubtype>}.
+ */
+ public static final class InputMethodSubtypeList
+ extends Values<List<android.view.inputmethod.InputMethodSubtype>> { }
+
+ /**
* Await the result by the {@link Completable.Values}.
*
* @return the result once {@link ValueBase#onComplete()}
diff --git a/core/java/com/android/internal/inputmethod/IInputMethodSubtypeListResultCallback.aidl b/core/java/com/android/internal/inputmethod/IInputMethodSubtypeListResultCallback.aidl
new file mode 100644
index 000000000000..619c87e1cd5b
--- /dev/null
+++ b/core/java/com/android/internal/inputmethod/IInputMethodSubtypeListResultCallback.aidl
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.inputmethod;
+
+import android.view.inputmethod.InputMethodSubtype;
+import com.android.internal.inputmethod.ThrowableHolder;
+
+oneway interface IInputMethodSubtypeListResultCallback {
+ void onResult(in List<InputMethodSubtype> result);
+ void onError(in ThrowableHolder exception);
+} \ No newline at end of file
diff --git a/core/java/com/android/internal/inputmethod/IInputMethodSubtypeResultCallback.aidl b/core/java/com/android/internal/inputmethod/IInputMethodSubtypeResultCallback.aidl
new file mode 100644
index 000000000000..66c09026321f
--- /dev/null
+++ b/core/java/com/android/internal/inputmethod/IInputMethodSubtypeResultCallback.aidl
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.inputmethod;
+
+import android.view.inputmethod.InputMethodSubtype;
+import com.android.internal.inputmethod.ThrowableHolder;
+
+oneway interface IInputMethodSubtypeResultCallback {
+ void onResult(in InputMethodSubtype result);
+ void onError(in ThrowableHolder exception);
+} \ No newline at end of file
diff --git a/core/java/com/android/internal/inputmethod/ResultCallbacks.java b/core/java/com/android/internal/inputmethod/ResultCallbacks.java
index b07c5f8c9b2a..8d95f2945c82 100644
--- a/core/java/com/android/internal/inputmethod/ResultCallbacks.java
+++ b/core/java/com/android/internal/inputmethod/ResultCallbacks.java
@@ -20,10 +20,12 @@ import android.annotation.AnyThread;
import android.annotation.BinderThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.internal.view.InputBindResult;
import java.lang.ref.WeakReference;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -228,4 +230,78 @@ public final class ResultCallbacks {
}
};
}
+
+ /**
+ * Creates {@link IInputMethodSubtypeResultCallback.Stub} that is to set
+ * {@link Completable.InputMethodSubtype} when receiving the result.
+ *
+ * @param value {@link Completable.InputMethodSubtype} to be set when receiving the result.
+ * @return {@link IInputMethodSubtypeResultCallback.Stub} that can be passed as a binder
+ * IPC parameter.
+ */
+ @AnyThread
+ public static IInputMethodSubtypeResultCallback.Stub of(
+ @NonNull Completable.InputMethodSubtype value) {
+ final AtomicReference<WeakReference<Completable.InputMethodSubtype>>
+ atomicRef = new AtomicReference<>(new WeakReference<>(value));
+
+ return new IInputMethodSubtypeResultCallback.Stub() {
+ @BinderThread
+ @Override
+ public void onResult(InputMethodSubtype result) {
+ final Completable.InputMethodSubtype value = unwrap(atomicRef);
+ if (value == null) {
+ return;
+ }
+ value.onComplete(result);
+ }
+
+ @BinderThread
+ @Override
+ public void onError(ThrowableHolder throwableHolder) {
+ final Completable.InputMethodSubtype value = unwrap(atomicRef);
+ if (value == null) {
+ return;
+ }
+ value.onError(throwableHolder);
+ }
+ };
+ }
+
+ /**
+ * Creates {@link IInputMethodSubtypeListResultCallback.Stub} that is to set
+ * {@link Completable.InputMethodSubtypeList} when receiving the result.
+ *
+ * @param value {@link Completable.InputMethodSubtypeList} to be set when receiving the result.
+ * @return {@link IInputMethodSubtypeListResultCallback.Stub} that can be passed as a binder
+ * IPC parameter.
+ */
+ @AnyThread
+ public static IInputMethodSubtypeListResultCallback.Stub of(
+ @NonNull Completable.InputMethodSubtypeList value) {
+ final AtomicReference<WeakReference<Completable.InputMethodSubtypeList>>
+ atomicRef = new AtomicReference<>(new WeakReference<>(value));
+
+ return new IInputMethodSubtypeListResultCallback.Stub() {
+ @BinderThread
+ @Override
+ public void onResult(List<InputMethodSubtype> result) {
+ final Completable.InputMethodSubtypeList value = unwrap(atomicRef);
+ if (value == null) {
+ return;
+ }
+ value.onComplete(result);
+ }
+
+ @BinderThread
+ @Override
+ public void onError(ThrowableHolder throwableHolder) {
+ final Completable.InputMethodSubtypeList value = unwrap(atomicRef);
+ if (value == null) {
+ return;
+ }
+ value.onError(throwableHolder);
+ }
+ };
+ }
}
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index 455e48949690..1b5cf6ce6819 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -26,6 +26,8 @@ import com.android.internal.view.IInputContext;
import com.android.internal.view.IInputMethodClient;
import com.android.internal.inputmethod.IBooleanResultCallback;
import com.android.internal.inputmethod.IInputBindResultResultCallback;
+import com.android.internal.inputmethod.IInputMethodSubtypeResultCallback;
+import com.android.internal.inputmethod.IInputMethodSubtypeListResultCallback;
/**
* Public interface to the global input method manager, used by all client
@@ -39,9 +41,9 @@ interface IInputMethodManager {
List<InputMethodInfo> getInputMethodList(int userId);
// TODO: Use ParceledListSlice instead
List<InputMethodInfo> getEnabledInputMethodList(int userId);
- List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in String imiId,
- boolean allowsImplicitlySelectedSubtypes);
- InputMethodSubtype getLastInputMethodSubtype();
+ void getEnabledInputMethodSubtypeList(in String imiId, boolean allowsImplicitlySelectedSubtypes,
+ in IInputMethodSubtypeListResultCallback resultCallback);
+ void getLastInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
void showSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
in ResultReceiver resultReceiver, in IBooleanResultCallback resultCallback);
@@ -66,7 +68,7 @@ interface IInputMethodManager {
int displayId);
void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId);
void isInputMethodPickerShownForTest(in IBooleanResultCallback resultCallback);
- InputMethodSubtype getCurrentInputMethodSubtype();
+ void getCurrentInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
// This is kept due to @UnsupportedAppUsage.
// TODO(Bug 113914148): Consider removing this.