| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.inputmethod; |
| 18 |
|
| 19 |
import android.annotation.AnyThread; |
| 20 |
import android.annotation.DurationMillisLong; |
| 21 |
import android.annotation.IntRange; |
| 22 |
import android.annotation.NonNull; |
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.view.KeyEvent; |
| 25 |
import android.view.inputmethod.SurroundingText; |
| 26 |
import android.view.inputmethod.TextAttribute; |
| 27 |
|
| 28 |
import com.android.internal.infra.AndroidFuture; |
| 29 |
import com.android.internal.view.IInputMethod; |
| 30 |
|
| 31 |
import java.util.concurrent.CompletableFuture; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public final class RemoteAccessibilityInputConnection { |
| 39 |
private static final String TAG = "RemoteA11yInputConnection"; |
| 40 |
|
| 41 |
@DurationMillisLong |
| 42 |
private static final int MAX_WAIT_TIME_MILLIS = 2000; |
| 43 |
|
| 44 |
@NonNull |
| 45 |
IRemoteAccessibilityInputConnectionInvoker mInvoker; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@NonNull |
| 54 |
private final CancellationGroup mCancellationGroup; |
| 55 |
|
| 56 |
public RemoteAccessibilityInputConnection( |
| 57 |
@NonNull IRemoteAccessibilityInputConnection connection, |
| 58 |
@NonNull CancellationGroup cancellationGroup) { |
| 59 |
mInvoker = IRemoteAccessibilityInputConnectionInvoker.create(connection); |
| 60 |
mCancellationGroup = cancellationGroup; |
| 61 |
} |
| 62 |
|
| 63 |
public RemoteAccessibilityInputConnection(@NonNull RemoteAccessibilityInputConnection original, |
| 64 |
int sessionId) { |
| 65 |
mInvoker = original.mInvoker.cloneWithSessionId(sessionId); |
| 66 |
mCancellationGroup = original.mCancellationGroup; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@AnyThread |
| 76 |
public boolean isSameConnection(@NonNull IRemoteAccessibilityInputConnection connection) { |
| 77 |
return mInvoker.isSameConnection(connection); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
@AnyThread |
| 89 |
public void commitText(@NonNull CharSequence text, int newCursorPosition, |
| 90 |
@Nullable TextAttribute textAttribute) { |
| 91 |
mInvoker.commitText(text, newCursorPosition, textAttribute); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
@AnyThread |
| 102 |
public void setSelection(int start, int end) { |
| 103 |
mInvoker.setSelection(start, end); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
@AnyThread |
| 116 |
public SurroundingText getSurroundingText( |
| 117 |
@IntRange(from = 0) int beforeLength, @IntRange(from = 0) int afterLength, int flags) { |
| 118 |
if (mCancellationGroup.isCanceled()) { |
| 119 |
return null; |
| 120 |
} |
| 121 |
|
| 122 |
final CompletableFuture<SurroundingText> value = mInvoker.getSurroundingText(beforeLength, |
| 123 |
afterLength, flags); |
| 124 |
return CompletableFutureUtil.getResultOrNull( |
| 125 |
value, TAG, "getSurroundingText()", mCancellationGroup, MAX_WAIT_TIME_MILLIS); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
@AnyThread |
| 136 |
public void deleteSurroundingText(int beforeLength, int afterLength) { |
| 137 |
mInvoker.deleteSurroundingText(beforeLength, afterLength); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
@AnyThread |
| 147 |
public void sendKeyEvent(KeyEvent event) { |
| 148 |
mInvoker.sendKeyEvent(event); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
@AnyThread |
| 158 |
public void performEditorAction(int actionCode) { |
| 159 |
mInvoker.performEditorAction(actionCode); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
@AnyThread |
| 169 |
public void performContextMenuAction(int id) { |
| 170 |
mInvoker.performContextMenuAction(id); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
@AnyThread |
| 181 |
public int getCursorCapsMode(int reqModes) { |
| 182 |
if (mCancellationGroup.isCanceled()) { |
| 183 |
return 0; |
| 184 |
} |
| 185 |
|
| 186 |
final CompletableFuture<Integer> value = mInvoker.getCursorCapsMode(reqModes); |
| 187 |
|
| 188 |
return CompletableFutureUtil.getResultOrZero( |
| 189 |
value, TAG, "getCursorCapsMode()", mCancellationGroup, MAX_WAIT_TIME_MILLIS); |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
@AnyThread |
| 199 |
public void clearMetaKeyStates(int states) { |
| 200 |
mInvoker.clearMetaKeyStates(states); |
| 201 |
} |
| 202 |
} |