Loading core/java/com/android/internal/inputmethod/CallbackUtils.java +25 −0 Original line number Diff line number Diff line Loading @@ -200,4 +200,29 @@ public final class CallbackUtils { callback.onResult(result); } catch (RemoteException ignored) { } } /** * A utility method using given {@link IVoidResultCallback} to callback the result. * * @param callback {@link IVoidResultCallback} to be called back. * @param resultSupplier the supplier from which the result is provided. */ public static void onResult(@NonNull IVoidResultCallback callback, @NonNull Supplier<Void> resultSupplier) { Throwable exception = null; try { resultSupplier.get(); } catch (Throwable throwable) { exception = throwable; } try { if (exception != null) { callback.onError(ThrowableHolder.of(exception)); return; } callback.onResult(); } catch (RemoteException ignored) { } } } core/java/com/android/internal/inputmethod/Completable.java +54 −0 Original line number Diff line number Diff line Loading @@ -285,6 +285,42 @@ public final class Completable { } } /** * Completable object of {@link java.lang.Void}. */ public static final class Void extends ValueBase { /** * Notify when this completable object callback. */ @AnyThread @Override protected void onComplete() { synchronized (mStateLock) { switch (mState) { case CompletionState.NOT_COMPLETED: mState = CompletionState.COMPLETED_WITH_VALUE; break; default: throw new UnsupportedOperationException( "onComplete() is not allowed on state=" + stateToString(mState)); } } super.onComplete(); } /** * @throws RuntimeException when called while {@link #onError} happened. * @throws UnsupportedOperationException when called while {@link #hasValue()} returns * {@code false}. */ @AnyThread public void getValue() { synchronized (mStateLock) { enforceGetValueLocked(); } } } /** * Base class of completable object types. * Loading Loading @@ -395,6 +431,13 @@ public final class Completable { return new Completable.InputMethodInfoList(); } /** * @return an instance of {@link Completable.Void}. */ public static Completable.Void createVoid() { return new Completable.Void(); } /** * Completable object of {@link java.lang.Boolean}. */ Loading Loading @@ -464,6 +507,17 @@ public final class Completable { return value.getValue(); } /** * Await the result by the {@link Completable.Void}. * * Check the result once {@link ValueBase#onComplete()} */ @AnyThread public static void getResult(@NonNull Completable.Void value) { value.await(); value.getValue(); } /** * Await the result by the {@link Completable.Int}, and log it if there is no result after * given timeout. Loading core/java/com/android/internal/inputmethod/IVoidResultCallback.aidl 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * 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 com.android.internal.inputmethod.ThrowableHolder; oneway interface IVoidResultCallback { void onResult(); void onError(in ThrowableHolder exception); } No newline at end of file core/java/com/android/internal/inputmethod/ResultCallbacks.java +35 −0 Original line number Diff line number Diff line Loading @@ -352,4 +352,39 @@ public final class ResultCallbacks { } }; } /** * Creates {@link IVoidResultCallback.Stub} that is to set {@link Completable.Void} when * receiving the result. * * @param value {@link Completable.Void} to be set when receiving the result. * @return {@link IVoidResultCallback.Stub} that can be passed as a binder IPC parameter. */ @AnyThread public static IVoidResultCallback.Stub of(@NonNull Completable.Void value) { final AtomicReference<WeakReference<Completable.Void>> atomicRef = new AtomicReference<>(new WeakReference<>(value)); return new IVoidResultCallback.Stub() { @BinderThread @Override public void onResult() { final Completable.Void value = unwrap(atomicRef); if (value == null) { return; } value.onComplete(); } @BinderThread @Override public void onError(ThrowableHolder throwableHolder) { final Completable.Void value = unwrap(atomicRef); if (value == null) { return; } value.onError(throwableHolder); } }; } } Loading
core/java/com/android/internal/inputmethod/CallbackUtils.java +25 −0 Original line number Diff line number Diff line Loading @@ -200,4 +200,29 @@ public final class CallbackUtils { callback.onResult(result); } catch (RemoteException ignored) { } } /** * A utility method using given {@link IVoidResultCallback} to callback the result. * * @param callback {@link IVoidResultCallback} to be called back. * @param resultSupplier the supplier from which the result is provided. */ public static void onResult(@NonNull IVoidResultCallback callback, @NonNull Supplier<Void> resultSupplier) { Throwable exception = null; try { resultSupplier.get(); } catch (Throwable throwable) { exception = throwable; } try { if (exception != null) { callback.onError(ThrowableHolder.of(exception)); return; } callback.onResult(); } catch (RemoteException ignored) { } } }
core/java/com/android/internal/inputmethod/Completable.java +54 −0 Original line number Diff line number Diff line Loading @@ -285,6 +285,42 @@ public final class Completable { } } /** * Completable object of {@link java.lang.Void}. */ public static final class Void extends ValueBase { /** * Notify when this completable object callback. */ @AnyThread @Override protected void onComplete() { synchronized (mStateLock) { switch (mState) { case CompletionState.NOT_COMPLETED: mState = CompletionState.COMPLETED_WITH_VALUE; break; default: throw new UnsupportedOperationException( "onComplete() is not allowed on state=" + stateToString(mState)); } } super.onComplete(); } /** * @throws RuntimeException when called while {@link #onError} happened. * @throws UnsupportedOperationException when called while {@link #hasValue()} returns * {@code false}. */ @AnyThread public void getValue() { synchronized (mStateLock) { enforceGetValueLocked(); } } } /** * Base class of completable object types. * Loading Loading @@ -395,6 +431,13 @@ public final class Completable { return new Completable.InputMethodInfoList(); } /** * @return an instance of {@link Completable.Void}. */ public static Completable.Void createVoid() { return new Completable.Void(); } /** * Completable object of {@link java.lang.Boolean}. */ Loading Loading @@ -464,6 +507,17 @@ public final class Completable { return value.getValue(); } /** * Await the result by the {@link Completable.Void}. * * Check the result once {@link ValueBase#onComplete()} */ @AnyThread public static void getResult(@NonNull Completable.Void value) { value.await(); value.getValue(); } /** * Await the result by the {@link Completable.Int}, and log it if there is no result after * given timeout. Loading
core/java/com/android/internal/inputmethod/IVoidResultCallback.aidl 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * 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 com.android.internal.inputmethod.ThrowableHolder; oneway interface IVoidResultCallback { void onResult(); void onError(in ThrowableHolder exception); } No newline at end of file
core/java/com/android/internal/inputmethod/ResultCallbacks.java +35 −0 Original line number Diff line number Diff line Loading @@ -352,4 +352,39 @@ public final class ResultCallbacks { } }; } /** * Creates {@link IVoidResultCallback.Stub} that is to set {@link Completable.Void} when * receiving the result. * * @param value {@link Completable.Void} to be set when receiving the result. * @return {@link IVoidResultCallback.Stub} that can be passed as a binder IPC parameter. */ @AnyThread public static IVoidResultCallback.Stub of(@NonNull Completable.Void value) { final AtomicReference<WeakReference<Completable.Void>> atomicRef = new AtomicReference<>(new WeakReference<>(value)); return new IVoidResultCallback.Stub() { @BinderThread @Override public void onResult() { final Completable.Void value = unwrap(atomicRef); if (value == null) { return; } value.onComplete(); } @BinderThread @Override public void onError(ThrowableHolder throwableHolder) { final Completable.Void value = unwrap(atomicRef); if (value == null) { return; } value.onError(throwableHolder); } }; } }