| 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 static java.lang.annotation.RetentionPolicy.SOURCE; |
| 20 |
|
| 21 |
import android.annotation.IntDef; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.content.ComponentName; |
| 24 |
import android.content.Intent; |
| 25 |
import android.content.ServiceConnection; |
| 26 |
import android.graphics.Matrix; |
| 27 |
import android.os.IBinder; |
| 28 |
import android.os.Parcel; |
| 29 |
import android.os.Parcelable; |
| 30 |
import android.util.SparseArray; |
| 31 |
import android.view.InputChannel; |
| 32 |
|
| 33 |
import com.android.internal.view.IInputMethodSession; |
| 34 |
|
| 35 |
import java.lang.annotation.Retention; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public final class InputBindResult implements Parcelable { |
| 42 |
|
| 43 |
@Retention(SOURCE) |
| 44 |
@IntDef({ |
| 45 |
ResultCode.SUCCESS_WITH_IME_SESSION, |
| 46 |
ResultCode.SUCCESS_WAITING_IME_SESSION, |
| 47 |
ResultCode.SUCCESS_WAITING_IME_BINDING, |
| 48 |
ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY, |
| 49 |
ResultCode.ERROR_NULL, |
| 50 |
ResultCode.ERROR_NO_IME, |
| 51 |
ResultCode.ERROR_INVALID_PACKAGE_NAME, |
| 52 |
ResultCode.ERROR_SYSTEM_NOT_READY, |
| 53 |
ResultCode.ERROR_IME_NOT_CONNECTED, |
| 54 |
ResultCode.ERROR_INVALID_USER, |
| 55 |
ResultCode.ERROR_NULL_EDITOR_INFO, |
| 56 |
ResultCode.ERROR_NOT_IME_TARGET_WINDOW, |
| 57 |
ResultCode.ERROR_NO_EDITOR, |
| 58 |
ResultCode.ERROR_DISPLAY_ID_MISMATCH, |
| 59 |
ResultCode.ERROR_INVALID_DISPLAY_ID, |
| 60 |
ResultCode.SUCCESS_WITH_ACCESSIBILITY_SESSION |
| 61 |
}) |
| 62 |
public @interface ResultCode { |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
int SUCCESS_WITH_IME_SESSION = 0; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
int SUCCESS_WAITING_IME_SESSION = 1; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
int SUCCESS_WAITING_IME_BINDING = 2; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
int SUCCESS_WAITING_USER_SWITCHING = 3; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
int SUCCESS_REPORT_WINDOW_FOCUS_ONLY = 4; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
int ERROR_NULL = 5; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
int ERROR_NO_IME = 6; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
int ERROR_INVALID_PACKAGE_NAME = 7; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
int ERROR_SYSTEM_NOT_READY = 8; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
int ERROR_IME_NOT_CONNECTED = 9; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
int ERROR_INVALID_USER = 10; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
int ERROR_NULL_EDITOR_INFO = 11; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
int ERROR_NOT_IME_TARGET_WINDOW = 12; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
int ERROR_NO_EDITOR = 13; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
int ERROR_DISPLAY_ID_MISMATCH = 14; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
int ERROR_INVALID_DISPLAY_ID = 15; |
| 175 |
int SUCCESS_WITH_ACCESSIBILITY_SESSION = 16; |
| 176 |
} |
| 177 |
|
| 178 |
@ResultCode |
| 179 |
public final int result; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public final IInputMethodSession method; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public SparseArray<IAccessibilityInputMethodSession> accessibilitySessions; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public final InputChannel channel; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public final String id; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public final int sequence; |
| 206 |
|
| 207 |
@Nullable |
| 208 |
private final float[] mVirtualDisplayToScreenMatrixValues; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public final boolean isInputMethodSuppressingSpellChecker; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
@Nullable |
| 220 |
public Matrix getVirtualDisplayToScreenMatrix() { |
| 221 |
if (mVirtualDisplayToScreenMatrixValues == null) { |
| 222 |
return null; |
| 223 |
} |
| 224 |
final Matrix matrix = new Matrix(); |
| 225 |
matrix.setValues(mVirtualDisplayToScreenMatrixValues); |
| 226 |
return matrix; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
public InputBindResult(@ResultCode int result, |
| 245 |
IInputMethodSession method, |
| 246 |
SparseArray<IAccessibilityInputMethodSession> accessibilitySessions, |
| 247 |
InputChannel channel, String id, int sequence, |
| 248 |
@Nullable Matrix virtualDisplayToScreenMatrix, |
| 249 |
boolean isInputMethodSuppressingSpellChecker) { |
| 250 |
this.result = result; |
| 251 |
this.method = method; |
| 252 |
this.accessibilitySessions = accessibilitySessions; |
| 253 |
this.channel = channel; |
| 254 |
this.id = id; |
| 255 |
this.sequence = sequence; |
| 256 |
if (virtualDisplayToScreenMatrix == null) { |
| 257 |
mVirtualDisplayToScreenMatrixValues = null; |
| 258 |
} else { |
| 259 |
mVirtualDisplayToScreenMatrixValues = new float[9]; |
| 260 |
virtualDisplayToScreenMatrix.getValues(mVirtualDisplayToScreenMatrixValues); |
| 261 |
} |
| 262 |
this.isInputMethodSuppressingSpellChecker = isInputMethodSuppressingSpellChecker; |
| 263 |
} |
| 264 |
|
| 265 |
private InputBindResult(Parcel source) { |
| 266 |
result = source.readInt(); |
| 267 |
method = IInputMethodSession.Stub.asInterface(source.readStrongBinder()); |
| 268 |
int n = source.readInt(); |
| 269 |
if (n < 0) { |
| 270 |
accessibilitySessions = null; |
| 271 |
} else { |
| 272 |
accessibilitySessions = new SparseArray<>(n); |
| 273 |
while (n > 0) { |
| 274 |
int key = source.readInt(); |
| 275 |
IAccessibilityInputMethodSession value = |
| 276 |
IAccessibilityInputMethodSession.Stub.asInterface( |
| 277 |
source.readStrongBinder()); |
| 278 |
accessibilitySessions.append(key, value); |
| 279 |
n--; |
| 280 |
} |
| 281 |
} |
| 282 |
if (source.readInt() != 0) { |
| 283 |
channel = InputChannel.CREATOR.createFromParcel(source); |
| 284 |
} else { |
| 285 |
channel = null; |
| 286 |
} |
| 287 |
id = source.readString(); |
| 288 |
sequence = source.readInt(); |
| 289 |
mVirtualDisplayToScreenMatrixValues = source.createFloatArray(); |
| 290 |
isInputMethodSuppressingSpellChecker = source.readBoolean(); |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
@Override |
| 297 |
public String toString() { |
| 298 |
return "InputBindResult{result=" + getResultString() + " method=" + method + " id=" + id |
| 299 |
+ " sequence=" + sequence |
| 300 |
+ " virtualDisplayToScreenMatrix=" + getVirtualDisplayToScreenMatrix() |
| 301 |
+ " isInputMethodSuppressingSpellChecker=" + isInputMethodSuppressingSpellChecker |
| 302 |
+ "}"; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
@Override |
| 309 |
public void writeToParcel(Parcel dest, int flags) { |
| 310 |
dest.writeInt(result); |
| 311 |
dest.writeStrongInterface(method); |
| 312 |
if (accessibilitySessions == null) { |
| 313 |
dest.writeInt(-1); |
| 314 |
} else { |
| 315 |
int n = accessibilitySessions.size(); |
| 316 |
dest.writeInt(n); |
| 317 |
int i = 0; |
| 318 |
while (i < n) { |
| 319 |
dest.writeInt(accessibilitySessions.keyAt(i)); |
| 320 |
dest.writeStrongInterface(accessibilitySessions.valueAt(i)); |
| 321 |
i++; |
| 322 |
} |
| 323 |
} |
| 324 |
if (channel != null) { |
| 325 |
dest.writeInt(1); |
| 326 |
channel.writeToParcel(dest, flags); |
| 327 |
} else { |
| 328 |
dest.writeInt(0); |
| 329 |
} |
| 330 |
dest.writeString(id); |
| 331 |
dest.writeInt(sequence); |
| 332 |
dest.writeFloatArray(mVirtualDisplayToScreenMatrixValues); |
| 333 |
dest.writeBoolean(isInputMethodSuppressingSpellChecker); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
public static final Parcelable.Creator<InputBindResult> CREATOR = |
| 340 |
new Parcelable.Creator<InputBindResult>() { |
| 341 |
@Override |
| 342 |
public InputBindResult createFromParcel(Parcel source) { |
| 343 |
return new InputBindResult(source); |
| 344 |
} |
| 345 |
|
| 346 |
@Override |
| 347 |
public InputBindResult[] newArray(int size) { |
| 348 |
return new InputBindResult[size]; |
| 349 |
} |
| 350 |
}; |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
@Override |
| 356 |
public int describeContents() { |
| 357 |
return channel != null ? channel.describeContents() : 0; |
| 358 |
} |
| 359 |
|
| 360 |
private String getResultString() { |
| 361 |
switch (result) { |
| 362 |
case ResultCode.SUCCESS_WITH_IME_SESSION: |
| 363 |
return "SUCCESS_WITH_IME_SESSION"; |
| 364 |
case ResultCode.SUCCESS_WAITING_IME_SESSION: |
| 365 |
return "SUCCESS_WAITING_IME_SESSION"; |
| 366 |
case ResultCode.SUCCESS_WAITING_IME_BINDING: |
| 367 |
return "SUCCESS_WAITING_IME_BINDING"; |
| 368 |
case ResultCode.SUCCESS_WAITING_USER_SWITCHING: |
| 369 |
return "SUCCESS_WAITING_USER_SWITCHING"; |
| 370 |
case ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY: |
| 371 |
return "SUCCESS_REPORT_WINDOW_FOCUS_ONLY"; |
| 372 |
case ResultCode.ERROR_NULL: |
| 373 |
return "ERROR_NULL"; |
| 374 |
case ResultCode.ERROR_NO_IME: |
| 375 |
return "ERROR_NO_IME"; |
| 376 |
case ResultCode.ERROR_NO_EDITOR: |
| 377 |
return "ERROR_NO_EDITOR"; |
| 378 |
case ResultCode.ERROR_INVALID_PACKAGE_NAME: |
| 379 |
return "ERROR_INVALID_PACKAGE_NAME"; |
| 380 |
case ResultCode.ERROR_SYSTEM_NOT_READY: |
| 381 |
return "ERROR_SYSTEM_NOT_READY"; |
| 382 |
case ResultCode.ERROR_IME_NOT_CONNECTED: |
| 383 |
return "ERROR_IME_NOT_CONNECTED"; |
| 384 |
case ResultCode.ERROR_INVALID_USER: |
| 385 |
return "ERROR_INVALID_USER"; |
| 386 |
case ResultCode.ERROR_NULL_EDITOR_INFO: |
| 387 |
return "ERROR_NULL_EDITOR_INFO"; |
| 388 |
case ResultCode.ERROR_NOT_IME_TARGET_WINDOW: |
| 389 |
return "ERROR_NOT_IME_TARGET_WINDOW"; |
| 390 |
case ResultCode.ERROR_DISPLAY_ID_MISMATCH: |
| 391 |
return "ERROR_DISPLAY_ID_MISMATCH"; |
| 392 |
case ResultCode.ERROR_INVALID_DISPLAY_ID: |
| 393 |
return "ERROR_INVALID_DISPLAY_ID"; |
| 394 |
default: |
| 395 |
return "Unknown(" + result + ")"; |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
private static InputBindResult error(@ResultCode int result) { |
| 400 |
return new InputBindResult(result, null, null, null, null, -1, null, false); |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
public static final InputBindResult NULL = error(ResultCode.ERROR_NULL); |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
public static final InputBindResult NO_IME = error(ResultCode.ERROR_NO_IME); |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
public static final InputBindResult NO_EDITOR = error(ResultCode.ERROR_NO_EDITOR); |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
public static final InputBindResult INVALID_PACKAGE_NAME = |
| 419 |
error(ResultCode.ERROR_INVALID_PACKAGE_NAME); |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
public static final InputBindResult NULL_EDITOR_INFO = error(ResultCode.ERROR_NULL_EDITOR_INFO); |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
public static final InputBindResult NOT_IME_TARGET_WINDOW = |
| 428 |
error(ResultCode.ERROR_NOT_IME_TARGET_WINDOW); |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
public static final InputBindResult IME_NOT_CONNECTED = |
| 433 |
error(ResultCode.ERROR_IME_NOT_CONNECTED); |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
public static final InputBindResult INVALID_USER = error(ResultCode.ERROR_INVALID_USER); |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
public static final InputBindResult DISPLAY_ID_MISMATCH = |
| 443 |
error(ResultCode.ERROR_DISPLAY_ID_MISMATCH); |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
public static final InputBindResult INVALID_DISPLAY_ID = |
| 449 |
error(ResultCode.ERROR_INVALID_DISPLAY_ID); |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
public static final InputBindResult USER_SWITCHING = |
| 456 |
error(ResultCode.SUCCESS_WAITING_USER_SWITCHING); |
| 457 |
} |