| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.inputmethodservice; |
| 18 |
|
| 19 |
import static android.inputmethodservice.InputMethodServiceProto.CANDIDATES_VIEW_STARTED; |
| 20 |
import static android.inputmethodservice.InputMethodServiceProto.CANDIDATES_VISIBILITY; |
| 21 |
import static android.inputmethodservice.InputMethodServiceProto.CONFIGURATION; |
| 22 |
import static android.inputmethodservice.InputMethodServiceProto.DECOR_VIEW_VISIBLE; |
| 23 |
import static android.inputmethodservice.InputMethodServiceProto.DECOR_VIEW_WAS_VISIBLE; |
| 24 |
import static android.inputmethodservice.InputMethodServiceProto.EXTRACTED_TOKEN; |
| 25 |
import static android.inputmethodservice.InputMethodServiceProto.EXTRACT_VIEW_HIDDEN; |
| 26 |
import static android.inputmethodservice.InputMethodServiceProto.FULLSCREEN_APPLIED; |
| 27 |
import static android.inputmethodservice.InputMethodServiceProto.INPUT_BINDING; |
| 28 |
import static android.inputmethodservice.InputMethodServiceProto.INPUT_CONNECTION_CALL; |
| 29 |
import static android.inputmethodservice.InputMethodServiceProto.INPUT_EDITOR_INFO; |
| 30 |
import static android.inputmethodservice.InputMethodServiceProto.INPUT_STARTED; |
| 31 |
import static android.inputmethodservice.InputMethodServiceProto.INPUT_VIEW_STARTED; |
| 32 |
import static android.inputmethodservice.InputMethodServiceProto.IN_SHOW_WINDOW; |
| 33 |
import static android.inputmethodservice.InputMethodServiceProto.IS_FULLSCREEN; |
| 34 |
import static android.inputmethodservice.InputMethodServiceProto.IS_INPUT_VIEW_SHOWN; |
| 35 |
import static android.inputmethodservice.InputMethodServiceProto.InsetsProto.CONTENT_TOP_INSETS; |
| 36 |
import static android.inputmethodservice.InputMethodServiceProto.InsetsProto.TOUCHABLE_INSETS; |
| 37 |
import static android.inputmethodservice.InputMethodServiceProto.InsetsProto.TOUCHABLE_REGION; |
| 38 |
import static android.inputmethodservice.InputMethodServiceProto.InsetsProto.VISIBLE_TOP_INSETS; |
| 39 |
import static android.inputmethodservice.InputMethodServiceProto.LAST_COMPUTED_INSETS; |
| 40 |
import static android.inputmethodservice.InputMethodServiceProto.LAST_SHOW_INPUT_REQUESTED; |
| 41 |
import static android.inputmethodservice.InputMethodServiceProto.SETTINGS_OBSERVER; |
| 42 |
import static android.inputmethodservice.InputMethodServiceProto.SHOW_INPUT_FLAGS; |
| 43 |
import static android.inputmethodservice.InputMethodServiceProto.SHOW_INPUT_REQUESTED; |
| 44 |
import static android.inputmethodservice.InputMethodServiceProto.SOFT_INPUT_WINDOW; |
| 45 |
import static android.inputmethodservice.InputMethodServiceProto.STATUS_ICON; |
| 46 |
import static android.inputmethodservice.InputMethodServiceProto.TOKEN; |
| 47 |
import static android.inputmethodservice.InputMethodServiceProto.VIEWS_CREATED; |
| 48 |
import static android.inputmethodservice.InputMethodServiceProto.WINDOW_VISIBLE; |
| 49 |
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
| 50 |
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 51 |
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 52 |
import static android.view.WindowInsets.Type.navigationBars; |
| 53 |
import static android.view.WindowInsets.Type.statusBars; |
| 54 |
|
| 55 |
import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 56 |
|
| 57 |
import android.annotation.AnyThread; |
| 58 |
import android.annotation.CallSuper; |
| 59 |
import android.annotation.DrawableRes; |
| 60 |
import android.annotation.IntDef; |
| 61 |
import android.annotation.MainThread; |
| 62 |
import android.annotation.NonNull; |
| 63 |
import android.annotation.Nullable; |
| 64 |
import android.annotation.TestApi; |
| 65 |
import android.annotation.UiContext; |
| 66 |
import android.app.ActivityManager; |
| 67 |
import android.app.Dialog; |
| 68 |
import android.compat.annotation.ChangeId; |
| 69 |
import android.compat.annotation.EnabledSince; |
| 70 |
import android.compat.annotation.UnsupportedAppUsage; |
| 71 |
import android.content.Context; |
| 72 |
import android.content.pm.PackageManager; |
| 73 |
import android.content.res.Configuration; |
| 74 |
import android.content.res.Resources; |
| 75 |
import android.content.res.TypedArray; |
| 76 |
import android.database.ContentObserver; |
| 77 |
import android.graphics.Rect; |
| 78 |
import android.graphics.Region; |
| 79 |
import android.net.Uri; |
| 80 |
import android.os.Binder; |
| 81 |
import android.os.Build; |
| 82 |
import android.os.Bundle; |
| 83 |
import android.os.Handler; |
| 84 |
import android.os.IBinder; |
| 85 |
import android.os.Looper; |
| 86 |
import android.os.Process; |
| 87 |
import android.os.ResultReceiver; |
| 88 |
import android.os.SystemClock; |
| 89 |
import android.os.SystemProperties; |
| 90 |
import android.os.Trace; |
| 91 |
import android.provider.Settings; |
| 92 |
import android.text.InputType; |
| 93 |
import android.text.Layout; |
| 94 |
import android.text.Spannable; |
| 95 |
import android.text.method.MovementMethod; |
| 96 |
import android.util.Log; |
| 97 |
import android.util.PrintWriterPrinter; |
| 98 |
import android.util.Printer; |
| 99 |
import android.util.proto.ProtoOutputStream; |
| 100 |
import android.view.BatchedInputEventReceiver.SimpleBatchedInputEventReceiver; |
| 101 |
import android.view.Choreographer; |
| 102 |
import android.view.Gravity; |
| 103 |
import android.view.InputChannel; |
| 104 |
import android.view.InputDevice; |
| 105 |
import android.view.InputEventReceiver; |
| 106 |
import android.view.KeyCharacterMap; |
| 107 |
import android.view.KeyEvent; |
| 108 |
import android.view.LayoutInflater; |
| 109 |
import android.view.MotionEvent; |
| 110 |
import android.view.View; |
| 111 |
import android.view.ViewGroup; |
| 112 |
import android.view.ViewRootImpl; |
| 113 |
import android.view.ViewTreeObserver; |
| 114 |
import android.view.Window; |
| 115 |
import android.view.WindowInsets.Side; |
| 116 |
import android.view.WindowInsets.Type; |
| 117 |
import android.view.WindowManager; |
| 118 |
import android.view.animation.AnimationUtils; |
| 119 |
import android.view.inputmethod.CompletionInfo; |
| 120 |
import android.view.inputmethod.CursorAnchorInfo; |
| 121 |
import android.view.inputmethod.EditorInfo; |
| 122 |
import android.view.inputmethod.ExtractedText; |
| 123 |
import android.view.inputmethod.ExtractedTextRequest; |
| 124 |
import android.view.inputmethod.InlineSuggestionsRequest; |
| 125 |
import android.view.inputmethod.InlineSuggestionsResponse; |
| 126 |
import android.view.inputmethod.InputBinding; |
| 127 |
import android.view.inputmethod.InputConnection; |
| 128 |
import android.view.inputmethod.InputContentInfo; |
| 129 |
import android.view.inputmethod.InputMethod; |
| 130 |
import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodServiceTraceProto; |
| 131 |
import android.view.inputmethod.InputMethodInfo; |
| 132 |
import android.view.inputmethod.InputMethodManager; |
| 133 |
import android.view.inputmethod.InputMethodSubtype; |
| 134 |
import android.widget.FrameLayout; |
| 135 |
import android.widget.ImageButton; |
| 136 |
import android.widget.LinearLayout; |
| 137 |
import android.widget.TextView; |
| 138 |
import android.window.CompatOnBackInvokedCallback; |
| 139 |
import android.window.ImeOnBackInvokedDispatcher; |
| 140 |
import android.window.OnBackInvokedCallback; |
| 141 |
import android.window.OnBackInvokedDispatcher; |
| 142 |
import android.window.WindowMetricsHelper; |
| 143 |
|
| 144 |
import com.android.internal.annotations.GuardedBy; |
| 145 |
import com.android.internal.inputmethod.IInputContentUriToken; |
| 146 |
import com.android.internal.inputmethod.IInputMethodPrivilegedOperations; |
| 147 |
import com.android.internal.inputmethod.ImeTracing; |
| 148 |
import com.android.internal.inputmethod.InputMethodNavButtonFlags; |
| 149 |
import com.android.internal.inputmethod.InputMethodPrivilegedOperations; |
| 150 |
import com.android.internal.inputmethod.InputMethodPrivilegedOperationsRegistry; |
| 151 |
import com.android.internal.inputmethod.SoftInputShowHideReason; |
| 152 |
import com.android.internal.util.RingBuffer; |
| 153 |
import com.android.internal.view.IInlineSuggestionsRequestCallback; |
| 154 |
import com.android.internal.view.IInputContext; |
| 155 |
import com.android.internal.view.InlineSuggestionsRequestInfo; |
| 156 |
|
| 157 |
import java.io.FileDescriptor; |
| 158 |
import java.io.PrintWriter; |
| 159 |
import java.lang.annotation.Retention; |
| 160 |
import java.lang.annotation.RetentionPolicy; |
| 161 |
import java.util.ArrayList; |
| 162 |
import java.util.List; |
| 163 |
import java.util.Objects; |
| 164 |
import java.util.OptionalInt; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
@UiContext |
| 319 |
public class InputMethodService extends AbstractInputMethodService { |
| 320 |
static final String TAG = "InputMethodService"; |
| 321 |
static final boolean DEBUG = false; |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
private static final String PROP_CAN_RENDER_GESTURAL_NAV_BUTTONS = |
| 341 |
"persist.sys.ime.can_render_gestural_nav_buttons"; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
private static final int MAX_EVENTS_BUFFER = 500; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
private RingBuffer<MotionEvent> mPendingEvents; |
| 353 |
private ImeOnBackInvokedDispatcher mImeDispatcher; |
| 354 |
private Boolean mBackCallbackRegistered = false; |
| 355 |
private final CompatOnBackInvokedCallback mCompatBackCallback = this::compatHandleBack; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
@AnyThread |
| 371 |
public static boolean canImeRenderGesturalNavButtons() { |
| 372 |
return SystemProperties.getBoolean(PROP_CAN_RENDER_GESTURAL_NAV_BUTTONS, true); |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public static final int BACK_DISPOSITION_DEFAULT = 0; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
@Deprecated |
| 409 |
public static final int BACK_DISPOSITION_WILL_NOT_DISMISS = 1; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
@Deprecated |
| 428 |
public static final int BACK_DISPOSITION_WILL_DISMISS = 2; |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
public static final int BACK_DISPOSITION_ADJUST_NOTHING = 3; |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
@Retention(SOURCE) |
| 455 |
@IntDef(value = {BACK_DISPOSITION_DEFAULT, BACK_DISPOSITION_WILL_NOT_DISMISS, |
| 456 |
BACK_DISPOSITION_WILL_DISMISS, BACK_DISPOSITION_ADJUST_NOTHING}, |
| 457 |
prefix = "BACK_DISPOSITION_") |
| 458 |
public @interface BackDispositionMode {} |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
public static final int IME_ACTIVE = 0x1; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
public static final int IME_VISIBLE = 0x2; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
public static final int IME_INVISIBLE = 0x4; |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
public static final int IME_VISIBLE_IMPERCEPTIBLE = 0x8; |
| 487 |
|
| 488 |
|
| 489 |
private static final int BACK_DISPOSITION_MIN = BACK_DISPOSITION_DEFAULT; |
| 490 |
private static final int BACK_DISPOSITION_MAX = BACK_DISPOSITION_ADJUST_NOTHING; |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
private static final long TIMEOUT_SURFACE_REMOVAL_MILLIS = 500; |
| 497 |
|
| 498 |
InputMethodManager mImm; |
| 499 |
private InputMethodPrivilegedOperations mPrivOps = new InputMethodPrivilegedOperations(); |
| 500 |
|
| 501 |
@NonNull |
| 502 |
private final NavigationBarController mNavigationBarController = |
| 503 |
new NavigationBarController(this); |
| 504 |
|
| 505 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 506 |
int mTheme = 0; |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
@TestApi |
| 526 |
@ChangeId |
| 527 |
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) |
| 528 |
public static final long FINISH_INPUT_NO_FALLBACK_CONNECTION = 156215187L; |
| 529 |
|
| 530 |
LayoutInflater mInflater; |
| 531 |
TypedArray mThemeAttrs; |
| 532 |
@UnsupportedAppUsage |
| 533 |
View mRootView; |
| 534 |
SoftInputWindow mWindow; |
| 535 |
boolean mInitialized; |
| 536 |
boolean mViewsCreated; |
| 537 |
|
| 538 |
boolean mDecorViewVisible; |
| 539 |
boolean mDecorViewWasVisible; |
| 540 |
boolean mInShowWindow; |
| 541 |
|
| 542 |
|
| 543 |
boolean mWindowVisible; |
| 544 |
|
| 545 |
ViewGroup mFullscreenArea; |
| 546 |
FrameLayout mExtractFrame; |
| 547 |
FrameLayout mCandidatesFrame; |
| 548 |
FrameLayout mInputFrame; |
| 549 |
|
| 550 |
IBinder mToken; |
| 551 |
|
| 552 |
InputBinding mInputBinding; |
| 553 |
InputConnection mInputConnection; |
| 554 |
boolean mInputStarted; |
| 555 |
boolean mInputViewStarted; |
| 556 |
boolean mCandidatesViewStarted; |
| 557 |
InputConnection mStartedInputConnection; |
| 558 |
EditorInfo mInputEditorInfo; |
| 559 |
|
| 560 |
int mShowInputFlags; |
| 561 |
boolean mShowInputRequested; |
| 562 |
boolean mLastShowInputRequested; |
| 563 |
int mCandidatesVisibility; |
| 564 |
CompletionInfo[] mCurCompletions; |
| 565 |
|
| 566 |
boolean mFullscreenApplied; |
| 567 |
boolean mIsFullscreen; |
| 568 |
private boolean mLastWasInFullscreenMode; |
| 569 |
@UnsupportedAppUsage |
| 570 |
View mExtractView; |
| 571 |
boolean mExtractViewHidden; |
| 572 |
@UnsupportedAppUsage |
| 573 |
ExtractEditText mExtractEditText; |
| 574 |
ViewGroup mExtractAccessories; |
| 575 |
View mExtractAction; |
| 576 |
ExtractedText mExtractedText; |
| 577 |
int mExtractedToken; |
| 578 |
|
| 579 |
View mInputView; |
| 580 |
boolean mIsInputViewShown; |
| 581 |
|
| 582 |
int mStatusIcon; |
| 583 |
|
| 584 |
@BackDispositionMode |
| 585 |
int mBackDisposition; |
| 586 |
|
| 587 |
private Object mLock = new Object(); |
| 588 |
@GuardedBy("mLock") |
| 589 |
private boolean mNotifyUserActionSent; |
| 590 |
|
| 591 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 592 |
final Insets mTmpInsets = new Insets(); |
| 593 |
final int[] mTmpLocation = new int[2]; |
| 594 |
|
| 595 |
private InlineSuggestionSessionController mInlineSuggestionSessionController; |
| 596 |
|
| 597 |
private boolean mHideNavBarForKeyboard; |
| 598 |
private boolean mIsAutomotive; |
| 599 |
private @NonNull OptionalInt mHandwritingRequestId = OptionalInt.empty(); |
| 600 |
private InputEventReceiver mHandwritingEventReceiver; |
| 601 |
private Handler mHandler; |
| 602 |
private boolean mImeSurfaceScheduledForRemoval; |
| 603 |
private ImsConfigurationTracker mConfigTracker = new ImsConfigurationTracker(); |
| 604 |
private boolean mDestroyed; |
| 605 |
private boolean mOnPreparedStylusHwCalled; |
| 606 |
|
| 607 |
|
| 608 |
private InkWindow mInkWindow; |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
private IBinder mCurShowInputToken; |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
private IBinder mCurHideInputToken; |
| 629 |
|
| 630 |
final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> { |
| 631 |
onComputeInsets(mTmpInsets); |
| 632 |
if (!mViewsCreated) { |
| 633 |
|
| 634 |
mTmpInsets.visibleTopInsets = 0; |
| 635 |
} |
| 636 |
if (isExtractViewShown()) { |
| 637 |
|
| 638 |
|
| 639 |
View decor = getWindow().getWindow().getDecorView(); |
| 640 |
info.contentInsets.top = info.visibleInsets.top = decor.getHeight(); |
| 641 |
info.touchableRegion.setEmpty(); |
| 642 |
info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME); |
| 643 |
} else { |
| 644 |
info.contentInsets.top = mTmpInsets.contentTopInsets; |
| 645 |
info.visibleInsets.top = mTmpInsets.visibleTopInsets; |
| 646 |
info.touchableRegion.set(mTmpInsets.touchableRegion); |
| 647 |
info.setTouchableInsets(mTmpInsets.touchableInsets); |
| 648 |
} |
| 649 |
mNavigationBarController.updateTouchableInsets(mTmpInsets, info); |
| 650 |
|
| 651 |
if (mInputFrame != null) { |
| 652 |
setImeExclusionRect(mTmpInsets.visibleTopInsets); |
| 653 |
} |
| 654 |
}; |
| 655 |
|
| 656 |
final View.OnClickListener mActionClickListener = v -> { |
| 657 |
final EditorInfo ei = getCurrentInputEditorInfo(); |
| 658 |
final InputConnection ic = getCurrentInputConnection(); |
| 659 |
if (ei != null && ic != null) { |
| 660 |
if (ei.actionId != 0) { |
| 661 |
ic.performEditorAction(ei.actionId); |
| 662 |
} else if ((ei.imeOptions & EditorInfo.IME_MASK_ACTION) != EditorInfo.IME_ACTION_NONE) { |
| 663 |
ic.performEditorAction(ei.imeOptions & EditorInfo.IME_MASK_ACTION); |
| 664 |
} |
| 665 |
} |
| 666 |
}; |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
public class InputMethodImpl extends AbstractInputMethodImpl { |
| 674 |
|
| 675 |
private boolean mSystemCallingShowSoftInput; |
| 676 |
private boolean mSystemCallingHideSoftInput; |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
@MainThread |
| 683 |
@Override |
| 684 |
public final void initializeInternal(@NonNull IBinder token, |
| 685 |
IInputMethodPrivilegedOperations privilegedOperations, int configChanges, |
| 686 |
boolean stylusHwSupported, @InputMethodNavButtonFlags int navButtonFlags) { |
| 687 |
if (mDestroyed) { |
| 688 |
Log.i(TAG, "The InputMethodService has already onDestroyed()." |
| 689 |
+ "Ignore the initialization."); |
| 690 |
return; |
| 691 |
} |
| 692 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initializeInternal"); |
| 693 |
mConfigTracker.onInitialize(configChanges); |
| 694 |
mPrivOps.set(privilegedOperations); |
| 695 |
InputMethodPrivilegedOperationsRegistry.put(token, mPrivOps); |
| 696 |
if (stylusHwSupported) { |
| 697 |
mInkWindow = new InkWindow(mWindow.getContext()); |
| 698 |
} |
| 699 |
mNavigationBarController.onNavButtonFlagsChanged(navButtonFlags); |
| 700 |
attachToken(token); |
| 701 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
@MainThread |
| 709 |
@Override |
| 710 |
public void onCreateInlineSuggestionsRequest( |
| 711 |
@NonNull InlineSuggestionsRequestInfo requestInfo, |
| 712 |
@NonNull IInlineSuggestionsRequestCallback cb) { |
| 713 |
if (DEBUG) { |
| 714 |
Log.d(TAG, "InputMethodService received onCreateInlineSuggestionsRequest()"); |
| 715 |
} |
| 716 |
mInlineSuggestionSessionController.onMakeInlineSuggestionsRequest(requestInfo, cb); |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
@MainThread |
| 723 |
@Override |
| 724 |
public void attachToken(IBinder token) { |
| 725 |
if (mToken != null) { |
| 726 |
throw new IllegalStateException( |
| 727 |
"attachToken() must be called at most once. token=" + token); |
| 728 |
} |
| 729 |
attachToWindowToken(token); |
| 730 |
mToken = token; |
| 731 |
mWindow.setToken(token); |
| 732 |
if (mInkWindow != null) { |
| 733 |
mInkWindow.setToken(token); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
@MainThread |
| 743 |
@Override |
| 744 |
public void bindInput(InputBinding binding) { |
| 745 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.bindInput"); |
| 746 |
mInputBinding = binding; |
| 747 |
mInputConnection = binding.getConnection(); |
| 748 |
if (DEBUG) Log.v(TAG, "bindInput(): binding=" + binding |
| 749 |
+ " ic=" + mInputConnection); |
| 750 |
reportFullscreenMode(); |
| 751 |
initialize(); |
| 752 |
onBindInput(); |
| 753 |
mConfigTracker.onBindInput(getResources()); |
| 754 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
@MainThread |
| 763 |
@Override |
| 764 |
public void unbindInput() { |
| 765 |
if (DEBUG) Log.v(TAG, "unbindInput(): binding=" + mInputBinding |
| 766 |
+ " ic=" + mInputConnection); |
| 767 |
|
| 768 |
onUnbindInput(); |
| 769 |
mInputBinding = null; |
| 770 |
mInputConnection = null; |
| 771 |
|
| 772 |
if (mInkWindow != null) { |
| 773 |
mInkWindow.hide(true ); |
| 774 |
} |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
@MainThread |
| 781 |
@Override |
| 782 |
public void startInput(InputConnection ic, EditorInfo attribute) { |
| 783 |
if (DEBUG) Log.v(TAG, "startInput(): editor=" + attribute); |
| 784 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.startInput"); |
| 785 |
doStartInput(ic, attribute, false); |
| 786 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
@MainThread |
| 793 |
@Override |
| 794 |
public void restartInput(InputConnection ic, EditorInfo attribute) { |
| 795 |
if (DEBUG) Log.v(TAG, "restartInput(): editor=" + attribute); |
| 796 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.restartInput"); |
| 797 |
doStartInput(ic, attribute, true); |
| 798 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
@MainThread |
| 806 |
@Override |
| 807 |
public final void dispatchStartInputWithToken(@Nullable InputConnection inputConnection, |
| 808 |
@NonNull EditorInfo editorInfo, boolean restarting, |
| 809 |
@NonNull IBinder startInputToken, @InputMethodNavButtonFlags int navButtonFlags, |
| 810 |
@NonNull ImeOnBackInvokedDispatcher imeDispatcher) { |
| 811 |
mPrivOps.reportStartInputAsync(startInputToken); |
| 812 |
mNavigationBarController.onNavButtonFlagsChanged(navButtonFlags); |
| 813 |
if (restarting) { |
| 814 |
restartInput(inputConnection, editorInfo); |
| 815 |
} else { |
| 816 |
startInput(inputConnection, editorInfo); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
mImeDispatcher = imeDispatcher; |
| 823 |
if (mWindow != null) { |
| 824 |
mWindow.getOnBackInvokedDispatcher().setImeOnBackInvokedDispatcher( |
| 825 |
imeDispatcher); |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
@MainThread |
| 834 |
@Override |
| 835 |
public void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) { |
| 836 |
mNavigationBarController.onNavButtonFlagsChanged(navButtonFlags); |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
@MainThread |
| 844 |
@Override |
| 845 |
public void hideSoftInputWithToken(int flags, ResultReceiver resultReceiver, |
| 846 |
IBinder hideInputToken) { |
| 847 |
mSystemCallingHideSoftInput = true; |
| 848 |
mCurHideInputToken = hideInputToken; |
| 849 |
hideSoftInput(flags, resultReceiver); |
| 850 |
mCurHideInputToken = null; |
| 851 |
mSystemCallingHideSoftInput = false; |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
@MainThread |
| 858 |
@Override |
| 859 |
public void hideSoftInput(int flags, ResultReceiver resultReceiver) { |
| 860 |
if (DEBUG) Log.v(TAG, "hideSoftInput()"); |
| 861 |
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R |
| 862 |
&& !mSystemCallingHideSoftInput) { |
| 863 |
Log.e(TAG, "IME shouldn't call hideSoftInput on itself." |
| 864 |
+ " Use requestHideSelf(int) itself"); |
| 865 |
return; |
| 866 |
} |
| 867 |
ImeTracing.getInstance().triggerServiceDump( |
| 868 |
"InputMethodService.InputMethodImpl#hideSoftInput", mDumper, |
| 869 |
null ); |
| 870 |
final boolean wasVisible = isInputViewShown(); |
| 871 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.hideSoftInput"); |
| 872 |
|
| 873 |
mShowInputFlags = 0; |
| 874 |
mShowInputRequested = false; |
| 875 |
hideWindow(); |
| 876 |
final boolean isVisible = isInputViewShown(); |
| 877 |
final boolean visibilityChanged = isVisible != wasVisible; |
| 878 |
if (resultReceiver != null) { |
| 879 |
resultReceiver.send(visibilityChanged |
| 880 |
? InputMethodManager.RESULT_HIDDEN |
| 881 |
: (wasVisible ? InputMethodManager.RESULT_UNCHANGED_SHOWN |
| 882 |
: InputMethodManager.RESULT_UNCHANGED_HIDDEN), null); |
| 883 |
} |
| 884 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
@MainThread |
| 892 |
@Override |
| 893 |
public void showSoftInputWithToken(int flags, ResultReceiver resultReceiver, |
| 894 |
IBinder showInputToken) { |
| 895 |
mSystemCallingShowSoftInput = true; |
| 896 |
mCurShowInputToken = showInputToken; |
| 897 |
showSoftInput(flags, resultReceiver); |
| 898 |
mCurShowInputToken = null; |
| 899 |
mSystemCallingShowSoftInput = false; |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
@MainThread |
| 906 |
@Override |
| 907 |
public void showSoftInput(int flags, ResultReceiver resultReceiver) { |
| 908 |
if (DEBUG) Log.v(TAG, "showSoftInput()"); |
| 909 |
|
| 910 |
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R |
| 911 |
&& !mSystemCallingShowSoftInput) { |
| 912 |
Log.e(TAG," IME shouldn't call showSoftInput on itself." |
| 913 |
+ " Use requestShowSelf(int) itself"); |
| 914 |
return; |
| 915 |
} |
| 916 |
|
| 917 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.showSoftInput"); |
| 918 |
ImeTracing.getInstance().triggerServiceDump( |
| 919 |
"InputMethodService.InputMethodImpl#showSoftInput", mDumper, |
| 920 |
null ); |
| 921 |
final boolean wasVisible = isInputViewShown(); |
| 922 |
if (dispatchOnShowInputRequested(flags, false)) { |
| 923 |
showWindow(true); |
| 924 |
} |
| 925 |
setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition); |
| 926 |
|
| 927 |
final boolean isVisible = isInputViewShown(); |
| 928 |
final boolean visibilityChanged = isVisible != wasVisible; |
| 929 |
if (resultReceiver != null) { |
| 930 |
resultReceiver.send(visibilityChanged |
| 931 |
? InputMethodManager.RESULT_SHOWN |
| 932 |
: (wasVisible ? InputMethodManager.RESULT_UNCHANGED_SHOWN |
| 933 |
: InputMethodManager.RESULT_UNCHANGED_HIDDEN), null); |
| 934 |
} |
| 935 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
@Override |
| 943 |
public void canStartStylusHandwriting(int requestId) { |
| 944 |
if (DEBUG) Log.v(TAG, "canStartStylusHandwriting()"); |
| 945 |
if (mHandwritingRequestId.isPresent()) { |
| 946 |
Log.d(TAG, "There is an ongoing Handwriting session. ignoring."); |
| 947 |
return; |
| 948 |
} |
| 949 |
if (!mInputStarted) { |
| 950 |
Log.d(TAG, "Input should have started before starting Stylus handwriting."); |
| 951 |
return; |
| 952 |
} |
| 953 |
if (!mOnPreparedStylusHwCalled) { |
| 954 |
|
| 955 |
onPrepareStylusHandwriting(); |
| 956 |
mOnPreparedStylusHwCalled = true; |
| 957 |
} |
| 958 |
if (onStartStylusHandwriting()) { |
| 959 |
mPrivOps.onStylusHandwritingReady(requestId, Process.myPid()); |
| 960 |
} else { |
| 961 |
Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting"); |
| 962 |
|
| 963 |
} |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
@MainThread |
| 971 |
@Override |
| 972 |
public void startStylusHandwriting( |
| 973 |
int requestId, @NonNull InputChannel channel, |
| 974 |
@NonNull List<MotionEvent> stylusEvents) { |
| 975 |
if (DEBUG) Log.v(TAG, "startStylusHandwriting()"); |
| 976 |
Objects.requireNonNull(channel); |
| 977 |
Objects.requireNonNull(stylusEvents); |
| 978 |
|
| 979 |
if (mHandwritingRequestId.isPresent()) { |
| 980 |
return; |
| 981 |
} |
| 982 |
|
| 983 |
mHandwritingRequestId = OptionalInt.of(requestId); |
| 984 |
mShowInputRequested = false; |
| 985 |
|
| 986 |
mInkWindow.show(); |
| 987 |
|
| 988 |
|
| 989 |
stylusEvents.forEach(InputMethodService.this::onStylusHandwritingMotionEvent); |
| 990 |
|
| 991 |
|
| 992 |
mHandwritingEventReceiver = new SimpleBatchedInputEventReceiver( |
| 993 |
channel, |
| 994 |
Looper.getMainLooper(), Choreographer.getInstance(), |
| 995 |
event -> { |
| 996 |
if (!(event instanceof MotionEvent)) { |
| 997 |
return false; |
| 998 |
} |
| 999 |
onStylusHandwritingMotionEvent((MotionEvent) event); |
| 1000 |
return true; |
| 1001 |
}); |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
@Override |
| 1009 |
public void initInkWindow() { |
| 1010 |
mInkWindow.initOnly(); |
| 1011 |
onPrepareStylusHandwriting(); |
| 1012 |
mOnPreparedStylusHwCalled = true; |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
@Override |
| 1020 |
public void finishStylusHandwriting() { |
| 1021 |
InputMethodService.this.finishStylusHandwriting(); |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
@MainThread |
| 1028 |
@Override |
| 1029 |
public void changeInputMethodSubtype(InputMethodSubtype subtype) { |
| 1030 |
dispatchOnCurrentInputMethodSubtypeChanged(subtype); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
@Nullable |
| 1052 |
public InlineSuggestionsRequest onCreateInlineSuggestionsRequest(@NonNull Bundle uiExtras) { |
| 1053 |
return null; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
public boolean onInlineSuggestionsResponse(@NonNull InlineSuggestionsResponse response) { |
| 1066 |
return false; |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
@Nullable |
| 1073 |
private IBinder getHostInputToken() { |
| 1074 |
ViewRootImpl viewRoot = null; |
| 1075 |
if (mRootView != null) { |
| 1076 |
viewRoot = mRootView.getViewRootImpl(); |
| 1077 |
} |
| 1078 |
return viewRoot == null ? null : viewRoot.getInputToken(); |
| 1079 |
} |
| 1080 |
|
| 1081 |
private void scheduleImeSurfaceRemoval() { |
| 1082 |
if (mShowInputRequested || mWindowVisible || mWindow == null |
| 1083 |
|| mImeSurfaceScheduledForRemoval) { |
| 1084 |
return; |
| 1085 |
} |
| 1086 |
if (mHandler == null) { |
| 1087 |
mHandler = new Handler(getMainLooper()); |
| 1088 |
} |
| 1089 |
|
| 1090 |
if (mLastWasInFullscreenMode) { |
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
removeImeSurface(); |
| 1096 |
} else { |
| 1097 |
mImeSurfaceScheduledForRemoval = true; |
| 1098 |
mHandler.postDelayed(() -> removeImeSurface(), TIMEOUT_SURFACE_REMOVAL_MILLIS); |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
private void removeImeSurface() { |
| 1103 |
|
| 1104 |
if (mWindow != null) { |
| 1105 |
mWindow.hide(); |
| 1106 |
} |
| 1107 |
mImeSurfaceScheduledForRemoval = false; |
| 1108 |
} |
| 1109 |
|
| 1110 |
private void cancelImeSurfaceRemoval() { |
| 1111 |
if (mHandler != null && mImeSurfaceScheduledForRemoval) { |
| 1112 |
mHandler.removeCallbacksAndMessages(null ); |
| 1113 |
mImeSurfaceScheduledForRemoval = false; |
| 1114 |
} |
| 1115 |
} |
| 1116 |
|
| 1117 |
private void setImeWindowStatus(int visibilityFlags, int backDisposition) { |
| 1118 |
mPrivOps.setImeWindowStatusAsync(visibilityFlags, backDisposition); |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
private void setImeExclusionRect(int visibleTopInsets) { |
| 1123 |
View rootView = mInputFrame.getRootView(); |
| 1124 |
android.graphics.Insets systemGesture = |
| 1125 |
rootView.getRootWindowInsets().getInsets(Type.systemGestures()); |
| 1126 |
ArrayList<Rect> exclusionRects = new ArrayList<>(); |
| 1127 |
exclusionRects.add(new Rect(0, |
| 1128 |
visibleTopInsets, |
| 1129 |
systemGesture.left, |
| 1130 |
rootView.getHeight())); |
| 1131 |
exclusionRects.add(new Rect(rootView.getWidth() - systemGesture.right, |
| 1132 |
visibleTopInsets, |
| 1133 |
rootView.getWidth(), |
| 1134 |
rootView.getHeight())); |
| 1135 |
rootView.setSystemGestureExclusionRects(exclusionRects); |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
public class InputMethodSessionImpl extends AbstractInputMethodSessionImpl { |
| 1144 |
public void finishInput() { |
| 1145 |
if (!isEnabled()) { |
| 1146 |
return; |
| 1147 |
} |
| 1148 |
if (DEBUG) Log.v(TAG, "finishInput() in " + this); |
| 1149 |
doFinishInput(); |
| 1150 |
} |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
public void displayCompletions(CompletionInfo[] completions) { |
| 1157 |
if (!isEnabled()) { |
| 1158 |
return; |
| 1159 |
} |
| 1160 |
mCurCompletions = completions; |
| 1161 |
onDisplayCompletions(completions); |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
public void updateExtractedText(int token, ExtractedText text) { |
| 1169 |
if (!isEnabled()) { |
| 1170 |
return; |
| 1171 |
} |
| 1172 |
onUpdateExtractedText(token, text); |
| 1173 |
} |
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
public void updateSelection(int oldSelStart, int oldSelEnd, |
| 1180 |
int newSelStart, int newSelEnd, |
| 1181 |
int candidatesStart, int candidatesEnd) { |
| 1182 |
if (!isEnabled()) { |
| 1183 |
return; |
| 1184 |
} |
| 1185 |
InputMethodService.this.onUpdateSelection(oldSelStart, oldSelEnd, |
| 1186 |
newSelStart, newSelEnd, candidatesStart, candidatesEnd); |
| 1187 |
} |
| 1188 |
|
| 1189 |
@Override |
| 1190 |
public void viewClicked(boolean focusChanged) { |
| 1191 |
if (!isEnabled()) { |
| 1192 |
return; |
| 1193 |
} |
| 1194 |
InputMethodService.this.onViewClicked(focusChanged); |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
public void updateCursor(Rect newCursor) { |
| 1202 |
if (!isEnabled()) { |
| 1203 |
return; |
| 1204 |
} |
| 1205 |
InputMethodService.this.onUpdateCursor(newCursor); |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
public void appPrivateCommand(String action, Bundle data) { |
| 1213 |
if (!isEnabled()) { |
| 1214 |
return; |
| 1215 |
} |
| 1216 |
InputMethodService.this.onAppPrivateCommand(action, data); |
| 1217 |
} |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
@Deprecated |
| 1228 |
public void toggleSoftInput(int showFlags, int hideFlags) { |
| 1229 |
InputMethodService.this.onToggleSoftInput(showFlags, hideFlags); |
| 1230 |
} |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
public void updateCursorAnchorInfo(CursorAnchorInfo info) { |
| 1237 |
if (!isEnabled()) { |
| 1238 |
return; |
| 1239 |
} |
| 1240 |
InputMethodService.this.onUpdateCursorAnchorInfo(info); |
| 1241 |
} |
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
public final void removeImeSurface() { |
| 1248 |
InputMethodService.this.scheduleImeSurfaceRemoval(); |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
@Override |
| 1256 |
public final void invalidateInputInternal(@NonNull EditorInfo editorInfo, |
| 1257 |
@NonNull IInputContext inputContext, int sessionId) { |
| 1258 |
if (mStartedInputConnection instanceof RemoteInputConnection) { |
| 1259 |
final RemoteInputConnection ric = (RemoteInputConnection) mStartedInputConnection; |
| 1260 |
if (!ric.isSameConnection(inputContext)) { |
| 1261 |
|
| 1262 |
if (DEBUG) { |
| 1263 |
Log.d(TAG, "ignoring invalidateInput() due to context mismatch."); |
| 1264 |
} |
| 1265 |
return; |
| 1266 |
} |
| 1267 |
editorInfo.makeCompatible(getApplicationInfo().targetSdkVersion); |
| 1268 |
getInputMethodInternal().restartInput(new RemoteInputConnection(ric, sessionId), |
| 1269 |
editorInfo); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
public static final class Insets { |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
public int contentTopInsets; |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
public int visibleTopInsets; |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
public final Region touchableRegion = new Region(); |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
public static final int TOUCHABLE_INSETS_FRAME |
| 1313 |
= ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
public static final int TOUCHABLE_INSETS_CONTENT |
| 1320 |
= ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
public static final int TOUCHABLE_INSETS_VISIBLE |
| 1327 |
= ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE; |
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
public static final int TOUCHABLE_INSETS_REGION |
| 1334 |
= ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
public int touchableInsets; |
| 1343 |
|
| 1344 |
private void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 1345 |
final long token = proto.start(fieldId); |
| 1346 |
proto.write(CONTENT_TOP_INSETS, contentTopInsets); |
| 1347 |
proto.write(VISIBLE_TOP_INSETS, visibleTopInsets); |
| 1348 |
proto.write(TOUCHABLE_INSETS, touchableInsets); |
| 1349 |
proto.write(TOUCHABLE_REGION, touchableRegion.toString()); |
| 1350 |
proto.end(token); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
@MainThread |
| 1361 |
private static final class SettingsObserver extends ContentObserver { |
| 1362 |
@Retention(RetentionPolicy.SOURCE) |
| 1363 |
@IntDef({ |
| 1364 |
ShowImeWithHardKeyboardType.UNKNOWN, |
| 1365 |
ShowImeWithHardKeyboardType.FALSE, |
| 1366 |
ShowImeWithHardKeyboardType.TRUE, |
| 1367 |
}) |
| 1368 |
private @interface ShowImeWithHardKeyboardType { |
| 1369 |
int UNKNOWN = 0; |
| 1370 |
int FALSE = 1; |
| 1371 |
int TRUE = 2; |
| 1372 |
} |
| 1373 |
@ShowImeWithHardKeyboardType |
| 1374 |
private int mShowImeWithHardKeyboard = ShowImeWithHardKeyboardType.UNKNOWN; |
| 1375 |
|
| 1376 |
private final InputMethodService mService; |
| 1377 |
|
| 1378 |
private SettingsObserver(InputMethodService service) { |
| 1379 |
super(new Handler(service.getMainLooper())); |
| 1380 |
mService = service; |
| 1381 |
} |
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
public static SettingsObserver createAndRegister(InputMethodService service) { |
| 1396 |
final SettingsObserver observer = new SettingsObserver(service); |
| 1397 |
|
| 1398 |
service.getContentResolver().registerContentObserver( |
| 1399 |
Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), |
| 1400 |
false, observer); |
| 1401 |
return observer; |
| 1402 |
} |
| 1403 |
|
| 1404 |
void unregister() { |
| 1405 |
mService.getContentResolver().unregisterContentObserver(this); |
| 1406 |
} |
| 1407 |
|
| 1408 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1409 |
private boolean shouldShowImeWithHardKeyboard() { |
| 1410 |
|
| 1411 |
if (mShowImeWithHardKeyboard == ShowImeWithHardKeyboardType.UNKNOWN) { |
| 1412 |
mShowImeWithHardKeyboard = Settings.Secure.getInt(mService.getContentResolver(), |
| 1413 |
Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0 ? |
| 1414 |
ShowImeWithHardKeyboardType.TRUE : ShowImeWithHardKeyboardType.FALSE; |
| 1415 |
} |
| 1416 |
switch (mShowImeWithHardKeyboard) { |
| 1417 |
case ShowImeWithHardKeyboardType.TRUE: |
| 1418 |
return true; |
| 1419 |
case ShowImeWithHardKeyboardType.FALSE: |
| 1420 |
return false; |
| 1421 |
default: |
| 1422 |
Log.e(TAG, "Unexpected mShowImeWithHardKeyboard=" + mShowImeWithHardKeyboard); |
| 1423 |
return false; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
@Override |
| 1428 |
public void onChange(boolean selfChange, Uri uri) { |
| 1429 |
final Uri showImeWithHardKeyboardUri = |
| 1430 |
Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 1431 |
if (showImeWithHardKeyboardUri.equals(uri)) { |
| 1432 |
mShowImeWithHardKeyboard = Settings.Secure.getInt(mService.getContentResolver(), |
| 1433 |
Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0 ? |
| 1434 |
ShowImeWithHardKeyboardType.TRUE : ShowImeWithHardKeyboardType.FALSE; |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
mService.resetStateForNewConfiguration(); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
@Override |
| 1444 |
public String toString() { |
| 1445 |
return "SettingsObserver{mShowImeWithHardKeyboard=" + mShowImeWithHardKeyboard + "}"; |
| 1446 |
} |
| 1447 |
} |
| 1448 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1449 |
private SettingsObserver mSettingsObserver; |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
@Override |
| 1460 |
public void setTheme(int theme) { |
| 1461 |
if (mWindow != null) { |
| 1462 |
throw new IllegalStateException("Must be called before onCreate()"); |
| 1463 |
} |
| 1464 |
mTheme = theme; |
| 1465 |
} |
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
@Deprecated |
| 1484 |
public boolean enableHardwareAcceleration() { |
| 1485 |
if (mWindow != null) { |
| 1486 |
throw new IllegalStateException("Must be called before onCreate()"); |
| 1487 |
} |
| 1488 |
return ActivityManager.isHighEndGfx(); |
| 1489 |
} |
| 1490 |
|
| 1491 |
@Override public void onCreate() { |
| 1492 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.onCreate"); |
| 1493 |
mTheme = Resources.selectSystemTheme(mTheme, |
| 1494 |
getApplicationInfo().targetSdkVersion, |
| 1495 |
android.R.style.Theme_InputMethod, |
| 1496 |
android.R.style.Theme_Holo_InputMethod, |
| 1497 |
android.R.style.Theme_DeviceDefault_InputMethod, |
| 1498 |
android.R.style.Theme_DeviceDefault_InputMethod); |
| 1499 |
super.setTheme(mTheme); |
| 1500 |
super.onCreate(); |
| 1501 |
mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); |
| 1502 |
mSettingsObserver = SettingsObserver.createAndRegister(this); |
| 1503 |
|
| 1504 |
|
| 1505 |
mSettingsObserver.shouldShowImeWithHardKeyboard(); |
| 1506 |
|
| 1507 |
mHideNavBarForKeyboard = getApplicationContext().getResources().getBoolean( |
| 1508 |
com.android.internal.R.bool.config_hideNavBarForKeyboard); |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
mInflater = (LayoutInflater)getSystemService( |
| 1514 |
Context.LAYOUT_INFLATER_SERVICE); |
| 1515 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initSoftInputWindow"); |
| 1516 |
mWindow = new SoftInputWindow(this, mTheme, mDispatcherState); |
| 1517 |
if (mImeDispatcher != null) { |
| 1518 |
mWindow.getOnBackInvokedDispatcher() |
| 1519 |
.setImeOnBackInvokedDispatcher(mImeDispatcher); |
| 1520 |
} |
| 1521 |
mNavigationBarController.onSoftInputWindowCreated(mWindow); |
| 1522 |
{ |
| 1523 |
final Window window = mWindow.getWindow(); |
| 1524 |
{ |
| 1525 |
final WindowManager.LayoutParams lp = window.getAttributes(); |
| 1526 |
lp.setTitle("InputMethod"); |
| 1527 |
lp.type = WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 1528 |
lp.width = WindowManager.LayoutParams.MATCH_PARENT; |
| 1529 |
lp.height = WindowManager.LayoutParams.WRAP_CONTENT; |
| 1530 |
lp.gravity = Gravity.BOTTOM; |
| 1531 |
lp.setFitInsetsTypes(statusBars() | navigationBars()); |
| 1532 |
lp.setFitInsetsSides(Side.all() & ~Side.BOTTOM); |
| 1533 |
lp.receiveInsetsIgnoringZOrder = true; |
| 1534 |
window.setAttributes(lp); |
| 1535 |
} |
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
final int windowFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 1540 |
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1541 |
| WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 1542 |
final int windowFlagsMask = windowFlags |
| 1543 |
| WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 1544 |
window.setFlags(windowFlags, windowFlagsMask); |
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
if (mHideNavBarForKeyboard) { |
| 1552 |
window.setDecorFitsSystemWindows(false); |
| 1553 |
} |
| 1554 |
} |
| 1555 |
|
| 1556 |
initViews(); |
| 1557 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 1558 |
|
| 1559 |
mInlineSuggestionSessionController = new InlineSuggestionSessionController( |
| 1560 |
this::onCreateInlineSuggestionsRequest, this::getHostInputToken, |
| 1561 |
this::onInlineSuggestionsResponse); |
| 1562 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 1563 |
} |
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
public void onInitializeInterface() { |
| 1572 |
|
| 1573 |
} |
| 1574 |
|
| 1575 |
void initialize() { |
| 1576 |
if (!mInitialized) { |
| 1577 |
mInitialized = true; |
| 1578 |
onInitializeInterface(); |
| 1579 |
} |
| 1580 |
} |
| 1581 |
|
| 1582 |
void initViews() { |
| 1583 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initViews"); |
| 1584 |
mInitialized = false; |
| 1585 |
mViewsCreated = false; |
| 1586 |
mShowInputRequested = false; |
| 1587 |
mShowInputFlags = 0; |
| 1588 |
|
| 1589 |
mThemeAttrs = obtainStyledAttributes(android.R.styleable.InputMethodService); |
| 1590 |
mRootView = mInflater.inflate( |
| 1591 |
com.android.internal.R.layout.input_method, null); |
| 1592 |
mWindow.setContentView(mRootView); |
| 1593 |
mRootView.getViewTreeObserver().addOnComputeInternalInsetsListener(mInsetsComputer); |
| 1594 |
mFullscreenArea = mRootView.findViewById(com.android.internal.R.id.fullscreenArea); |
| 1595 |
mExtractViewHidden = false; |
| 1596 |
mExtractFrame = mRootView.findViewById(android.R.id.extractArea); |
| 1597 |
mExtractView = null; |
| 1598 |
mExtractEditText = null; |
| 1599 |
mExtractAccessories = null; |
| 1600 |
mExtractAction = null; |
| 1601 |
mFullscreenApplied = false; |
| 1602 |
|
| 1603 |
mCandidatesFrame = mRootView.findViewById(android.R.id.candidatesArea); |
| 1604 |
mInputFrame = mRootView.findViewById(android.R.id.inputArea); |
| 1605 |
mInputView = null; |
| 1606 |
mIsInputViewShown = false; |
| 1607 |
|
| 1608 |
mExtractFrame.setVisibility(View.GONE); |
| 1609 |
mCandidatesVisibility = getCandidatesHiddenVisibility(); |
| 1610 |
mCandidatesFrame.setVisibility(mCandidatesVisibility); |
| 1611 |
mInputFrame.setVisibility(View.GONE); |
| 1612 |
mNavigationBarController.onViewInitialized(); |
| 1613 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 1614 |
} |
| 1615 |
|
| 1616 |
@Override public void onDestroy() { |
| 1617 |
mDestroyed = true; |
| 1618 |
super.onDestroy(); |
| 1619 |
mRootView.getViewTreeObserver().removeOnComputeInternalInsetsListener( |
| 1620 |
mInsetsComputer); |
| 1621 |
doFinishInput(); |
| 1622 |
mNavigationBarController.onDestroy(); |
| 1623 |
mWindow.dismissForDestroyIfNecessary(); |
| 1624 |
if (mSettingsObserver != null) { |
| 1625 |
mSettingsObserver.unregister(); |
| 1626 |
mSettingsObserver = null; |
| 1627 |
} |
| 1628 |
if (mToken != null) { |
| 1629 |
|
| 1630 |
|
| 1631 |
InputMethodPrivilegedOperationsRegistry.remove(mToken); |
| 1632 |
} |
| 1633 |
mImeDispatcher = null; |
| 1634 |
} |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
@Override public void onConfigurationChanged(Configuration newConfig) { |
| 1656 |
super.onConfigurationChanged(newConfig); |
| 1657 |
mConfigTracker.onConfigurationChanged(newConfig, this::resetStateForNewConfiguration); |
| 1658 |
} |
| 1659 |
|
| 1660 |
private void resetStateForNewConfiguration() { |
| 1661 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.resetStateForNewConfiguration"); |
| 1662 |
boolean visible = mDecorViewVisible; |
| 1663 |
int showFlags = mShowInputFlags; |
| 1664 |
boolean showingInput = mShowInputRequested; |
| 1665 |
CompletionInfo[] completions = mCurCompletions; |
| 1666 |
mRootView.getViewTreeObserver().removeOnComputeInternalInsetsListener(mInsetsComputer); |
| 1667 |
initViews(); |
| 1668 |
mInputViewStarted = false; |
| 1669 |
mCandidatesViewStarted = false; |
| 1670 |
if (mInputStarted) { |
| 1671 |
doStartInput(getCurrentInputConnection(), |
| 1672 |
getCurrentInputEditorInfo(), true); |
| 1673 |
} |
| 1674 |
if (visible) { |
| 1675 |
if (showingInput) { |
| 1676 |
|
| 1677 |
if (dispatchOnShowInputRequested(showFlags, true)) { |
| 1678 |
showWindow(true); |
| 1679 |
if (completions != null) { |
| 1680 |
mCurCompletions = completions; |
| 1681 |
onDisplayCompletions(completions); |
| 1682 |
} |
| 1683 |
} else { |
| 1684 |
hideWindow(); |
| 1685 |
} |
| 1686 |
} else if (mCandidatesVisibility == View.VISIBLE) { |
| 1687 |
|
| 1688 |
|
| 1689 |
showWindow(false); |
| 1690 |
} else { |
| 1691 |
|
| 1692 |
hideWindow(); |
| 1693 |
} |
| 1694 |
|
| 1695 |
boolean showing = onEvaluateInputViewShown(); |
| 1696 |
setImeWindowStatus(IME_ACTIVE | (showing ? IME_VISIBLE : 0), mBackDisposition); |
| 1697 |
} |
| 1698 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 1699 |
} |
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
@Override |
| 1706 |
public AbstractInputMethodImpl onCreateInputMethodInterface() { |
| 1707 |
return new InputMethodImpl(); |
| 1708 |
} |
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
@Override |
| 1715 |
public AbstractInputMethodSessionImpl onCreateInputMethodSessionInterface() { |
| 1716 |
return new InputMethodSessionImpl(); |
| 1717 |
} |
| 1718 |
|
| 1719 |
public LayoutInflater getLayoutInflater() { |
| 1720 |
return mInflater; |
| 1721 |
} |
| 1722 |
|
| 1723 |
public Dialog getWindow() { |
| 1724 |
return mWindow; |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
public void setBackDisposition(@BackDispositionMode int disposition) { |
| 1739 |
if (disposition == mBackDisposition) { |
| 1740 |
return; |
| 1741 |
} |
| 1742 |
if (disposition > BACK_DISPOSITION_MAX || disposition < BACK_DISPOSITION_MIN) { |
| 1743 |
Log.e(TAG, "Invalid back disposition value (" + disposition + ") specified."); |
| 1744 |
return; |
| 1745 |
} |
| 1746 |
mBackDisposition = disposition; |
| 1747 |
setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition); |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
@BackDispositionMode |
| 1757 |
public int getBackDisposition() { |
| 1758 |
return mBackDisposition; |
| 1759 |
} |
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
public int getMaxWidth() { |
| 1778 |
final WindowManager windowManager = getSystemService(WindowManager.class); |
| 1779 |
return WindowMetricsHelper.getBoundsExcludingNavigationBarAndCutout( |
| 1780 |
windowManager.getCurrentWindowMetrics()).width(); |
| 1781 |
} |
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
public InputBinding getCurrentInputBinding() { |
| 1788 |
return mInputBinding; |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
public InputConnection getCurrentInputConnection() { |
| 1796 |
InputConnection ic = mStartedInputConnection; |
| 1797 |
if (ic != null) { |
| 1798 |
return ic; |
| 1799 |
} |
| 1800 |
return mInputConnection; |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
public final boolean switchToPreviousInputMethod() { |
| 1811 |
return mPrivOps.switchToPreviousInputMethod(); |
| 1812 |
} |
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
public final boolean switchToNextInputMethod(boolean onlyCurrentIme) { |
| 1823 |
return mPrivOps.switchToNextInputMethod(onlyCurrentIme); |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
public final boolean shouldOfferSwitchingToNextInputMethod() { |
| 1836 |
return mPrivOps.shouldOfferSwitchingToNextInputMethod(); |
| 1837 |
} |
| 1838 |
|
| 1839 |
public boolean getCurrentInputStarted() { |
| 1840 |
return mInputStarted; |
| 1841 |
} |
| 1842 |
|
| 1843 |
public EditorInfo getCurrentInputEditorInfo() { |
| 1844 |
return mInputEditorInfo; |
| 1845 |
} |
| 1846 |
|
| 1847 |
private void reportFullscreenMode() { |
| 1848 |
mPrivOps.reportFullscreenModeAsync(mIsFullscreen); |
| 1849 |
} |
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
public void updateFullscreenMode() { |
| 1860 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.updateFullscreenMode"); |
| 1861 |
boolean isFullscreen = mShowInputRequested && onEvaluateFullscreenMode(); |
| 1862 |
boolean changed = mLastShowInputRequested != mShowInputRequested; |
| 1863 |
if (mIsFullscreen != isFullscreen || !mFullscreenApplied) { |
| 1864 |
changed = true; |
| 1865 |
mIsFullscreen = isFullscreen; |
| 1866 |
reportFullscreenMode(); |
| 1867 |
mFullscreenApplied = true; |
| 1868 |
initialize(); |
| 1869 |
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) |
| 1870 |
mFullscreenArea.getLayoutParams(); |
| 1871 |
if (isFullscreen) { |
| 1872 |
mFullscreenArea.setBackgroundDrawable(mThemeAttrs.getDrawable( |
| 1873 |
com.android.internal.R.styleable.InputMethodService_imeFullscreenBackground)); |
| 1874 |
lp.height = 0; |
| 1875 |
lp.weight = 1; |
| 1876 |
} else { |
| 1877 |
mFullscreenArea.setBackgroundDrawable(null); |
| 1878 |
lp.height = LinearLayout.LayoutParams.WRAP_CONTENT; |
| 1879 |
lp.weight = 0; |
| 1880 |
} |
| 1881 |
((ViewGroup)mFullscreenArea.getParent()).updateViewLayout( |
| 1882 |
mFullscreenArea, lp); |
| 1883 |
if (isFullscreen) { |
| 1884 |
if (mExtractView == null) { |
| 1885 |
View v = onCreateExtractTextView(); |
| 1886 |
if (v != null) { |
| 1887 |
setExtractView(v); |
| 1888 |
} |
| 1889 |
} |
| 1890 |
startExtractingText(false); |
| 1891 |
} |
| 1892 |
updateExtractFrameVisibility(); |
| 1893 |
} |
| 1894 |
|
| 1895 |
if (changed) { |
| 1896 |
onConfigureWindow(mWindow.getWindow(), isFullscreen, !mShowInputRequested); |
| 1897 |
mLastShowInputRequested = mShowInputRequested; |
| 1898 |
} |
| 1899 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 1900 |
} |
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
public void onConfigureWindow(Window win, boolean isFullscreen, |
| 1919 |
boolean isCandidatesOnly) { |
| 1920 |
final int currentHeight = mWindow.getWindow().getAttributes().height; |
| 1921 |
final int newHeight = isFullscreen ? MATCH_PARENT : WRAP_CONTENT; |
| 1922 |
if (mIsInputViewShown && currentHeight != newHeight) { |
| 1923 |
if (DEBUG) { |
| 1924 |
Log.w(TAG,"Window size has been changed. This may cause jankiness of resizing " |
| 1925 |
+ "window: " + currentHeight + " -> " + newHeight); |
| 1926 |
} |
| 1927 |
} |
| 1928 |
mWindow.getWindow().setLayout(MATCH_PARENT, newHeight); |
| 1929 |
} |
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
public boolean isFullscreenMode() { |
| 1937 |
return mIsFullscreen; |
| 1938 |
} |
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
public boolean onEvaluateFullscreenMode() { |
| 1949 |
Configuration config = getResources().getConfiguration(); |
| 1950 |
if (config.orientation != Configuration.ORIENTATION_LANDSCAPE) { |
| 1951 |
return false; |
| 1952 |
} |
| 1953 |
if (mInputEditorInfo != null |
| 1954 |
&& ((mInputEditorInfo.imeOptions & EditorInfo.IME_FLAG_NO_FULLSCREEN) != 0 |
| 1955 |
|
| 1956 |
|
| 1957 |
|| (mInputEditorInfo.internalImeOptions |
| 1958 |
& EditorInfo.IME_INTERNAL_FLAG_APP_WINDOW_PORTRAIT) != 0)) { |
| 1959 |
return false; |
| 1960 |
} |
| 1961 |
return true; |
| 1962 |
} |
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
public void setExtractViewShown(boolean shown) { |
| 1974 |
if (mExtractViewHidden == shown) { |
| 1975 |
mExtractViewHidden = !shown; |
| 1976 |
updateExtractFrameVisibility(); |
| 1977 |
} |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
public boolean isExtractViewShown() { |
| 1991 |
return mIsFullscreen && !mExtractViewHidden; |
| 1992 |
} |
| 1993 |
|
| 1994 |
void updateExtractFrameVisibility() { |
| 1995 |
final int vis; |
| 1996 |
updateCandidatesVisibility(mCandidatesVisibility == View.VISIBLE); |
| 1997 |
|
| 1998 |
if (isFullscreenMode()) { |
| 1999 |
vis = mExtractViewHidden ? View.INVISIBLE : View.VISIBLE; |
| 2000 |
|
| 2001 |
mExtractFrame.setVisibility(vis); |
| 2002 |
} else { |
| 2003 |
|
| 2004 |
|
| 2005 |
vis = mCandidatesVisibility; |
| 2006 |
mExtractFrame.setVisibility(View.GONE); |
| 2007 |
} |
| 2008 |
|
| 2009 |
if (mDecorViewWasVisible && mFullscreenArea.getVisibility() != vis) { |
| 2010 |
int animRes = mThemeAttrs.getResourceId(vis == View.VISIBLE |
| 2011 |
? com.android.internal.R.styleable.InputMethodService_imeExtractEnterAnimation |
| 2012 |
: com.android.internal.R.styleable.InputMethodService_imeExtractExitAnimation, |
| 2013 |
0); |
| 2014 |
if (animRes != 0) { |
| 2015 |
mFullscreenArea.startAnimation(AnimationUtils.loadAnimation( |
| 2016 |
this, animRes)); |
| 2017 |
} |
| 2018 |
} |
| 2019 |
mFullscreenArea.setVisibility(vis); |
| 2020 |
} |
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
public void onComputeInsets(Insets outInsets) { |
| 2036 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.onComputeInsets"); |
| 2037 |
int[] loc = mTmpLocation; |
| 2038 |
if (mInputFrame.getVisibility() == View.VISIBLE) { |
| 2039 |
mInputFrame.getLocationInWindow(loc); |
| 2040 |
} else { |
| 2041 |
View decor = getWindow().getWindow().getDecorView(); |
| 2042 |
loc[1] = decor.getHeight(); |
| 2043 |
} |
| 2044 |
if (isFullscreenMode()) { |
| 2045 |
|
| 2046 |
View decor = getWindow().getWindow().getDecorView(); |
| 2047 |
outInsets.contentTopInsets = decor.getHeight(); |
| 2048 |
} else { |
| 2049 |
outInsets.contentTopInsets = loc[1]; |
| 2050 |
} |
| 2051 |
if (mCandidatesFrame.getVisibility() == View.VISIBLE) { |
| 2052 |
mCandidatesFrame.getLocationInWindow(loc); |
| 2053 |
} |
| 2054 |
outInsets.visibleTopInsets = loc[1]; |
| 2055 |
outInsets.touchableInsets = Insets.TOUCHABLE_INSETS_VISIBLE; |
| 2056 |
outInsets.touchableRegion.setEmpty(); |
| 2057 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 2058 |
} |
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
public void updateInputViewShown() { |
| 2069 |
boolean isShown = mShowInputRequested && onEvaluateInputViewShown(); |
| 2070 |
if (mIsInputViewShown != isShown && mDecorViewVisible) { |
| 2071 |
mIsInputViewShown = isShown; |
| 2072 |
mInputFrame.setVisibility(isShown ? View.VISIBLE : View.GONE); |
| 2073 |
if (mInputView == null) { |
| 2074 |
initialize(); |
| 2075 |
View v = onCreateInputView(); |
| 2076 |
if (v != null) { |
| 2077 |
setInputView(v); |
| 2078 |
} |
| 2079 |
} |
| 2080 |
} |
| 2081 |
} |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
public boolean isShowInputRequested() { |
| 2087 |
return mShowInputRequested; |
| 2088 |
} |
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
public boolean isInputViewShown() { |
| 2096 |
return mDecorViewVisible; |
| 2097 |
} |
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
@CallSuper |
| 2111 |
public boolean onEvaluateInputViewShown() { |
| 2112 |
if (mSettingsObserver == null) { |
| 2113 |
Log.w(TAG, "onEvaluateInputViewShown: mSettingsObserver must not be null here."); |
| 2114 |
return false; |
| 2115 |
} |
| 2116 |
if (mSettingsObserver.shouldShowImeWithHardKeyboard()) { |
| 2117 |
return true; |
| 2118 |
} |
| 2119 |
Configuration config = getResources().getConfiguration(); |
| 2120 |
return config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2121 |
|| config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES; |
| 2122 |
} |
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
public void setCandidatesViewShown(boolean shown) { |
| 2129 |
updateCandidatesVisibility(shown); |
| 2130 |
if (!mShowInputRequested && mDecorViewVisible != shown) { |
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
if (shown) { |
| 2135 |
showWindow(false); |
| 2136 |
} else { |
| 2137 |
hideWindow(); |
| 2138 |
} |
| 2139 |
} |
| 2140 |
} |
| 2141 |
|
| 2142 |
void updateCandidatesVisibility(boolean shown) { |
| 2143 |
int vis = shown ? View.VISIBLE : getCandidatesHiddenVisibility(); |
| 2144 |
if (mCandidatesVisibility != vis) { |
| 2145 |
mCandidatesFrame.setVisibility(vis); |
| 2146 |
mCandidatesVisibility = vis; |
| 2147 |
} |
| 2148 |
} |
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
public int getCandidatesHiddenVisibility() { |
| 2161 |
return isExtractViewShown() ? View.GONE : View.INVISIBLE; |
| 2162 |
} |
| 2163 |
|
| 2164 |
public void showStatusIcon(@DrawableRes int iconResId) { |
| 2165 |
mStatusIcon = iconResId; |
| 2166 |
mPrivOps.updateStatusIconAsync(getPackageName(), iconResId); |
| 2167 |
} |
| 2168 |
|
| 2169 |
public void hideStatusIcon() { |
| 2170 |
mStatusIcon = 0; |
| 2171 |
mPrivOps.updateStatusIconAsync(null, 0); |
| 2172 |
} |
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
public void switchInputMethod(String id) { |
| 2182 |
mPrivOps.setInputMethod(id); |
| 2183 |
} |
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
public final void switchInputMethod(String id, InputMethodSubtype subtype) { |
| 2194 |
mPrivOps.setInputMethodAndSubtype(id, subtype); |
| 2195 |
} |
| 2196 |
|
| 2197 |
public void setExtractView(View view) { |
| 2198 |
mExtractFrame.removeAllViews(); |
| 2199 |
mExtractFrame.addView(view, new FrameLayout.LayoutParams( |
| 2200 |
ViewGroup.LayoutParams.MATCH_PARENT, |
| 2201 |
ViewGroup.LayoutParams.MATCH_PARENT)); |
| 2202 |
mExtractView = view; |
| 2203 |
if (view != null) { |
| 2204 |
mExtractEditText = view.findViewById( |
| 2205 |
com.android.internal.R.id.inputExtractEditText); |
| 2206 |
mExtractEditText.setIME(this); |
| 2207 |
mExtractAction = view.findViewById( |
| 2208 |
com.android.internal.R.id.inputExtractAction); |
| 2209 |
if (mExtractAction != null) { |
| 2210 |
mExtractAccessories = view.findViewById( |
| 2211 |
com.android.internal.R.id.inputExtractAccessories); |
| 2212 |
} |
| 2213 |
startExtractingText(false); |
| 2214 |
} else { |
| 2215 |
mExtractEditText = null; |
| 2216 |
mExtractAccessories = null; |
| 2217 |
mExtractAction = null; |
| 2218 |
} |
| 2219 |
} |
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
public void setCandidatesView(View view) { |
| 2228 |
mCandidatesFrame.removeAllViews(); |
| 2229 |
mCandidatesFrame.addView(view, new FrameLayout.LayoutParams( |
| 2230 |
ViewGroup.LayoutParams.MATCH_PARENT, |
| 2231 |
ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 2232 |
} |
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
public void setInputView(View view) { |
| 2241 |
mInputFrame.removeAllViews(); |
| 2242 |
mInputFrame.addView(view, new FrameLayout.LayoutParams( |
| 2243 |
ViewGroup.LayoutParams.MATCH_PARENT, |
| 2244 |
ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 2245 |
mInputView = view; |
| 2246 |
} |
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
public View onCreateExtractTextView() { |
| 2257 |
return mInflater.inflate( |
| 2258 |
com.android.internal.R.layout.input_method_extract_view, null); |
| 2259 |
} |
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
public View onCreateCandidatesView() { |
| 2272 |
return null; |
| 2273 |
} |
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
public View onCreateInputView() { |
| 2287 |
return null; |
| 2288 |
} |
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
public void onStartInputView(EditorInfo info, boolean restarting) { |
| 2302 |
|
| 2303 |
} |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
public void onFinishInputView(boolean finishingInput) { |
| 2319 |
if (!finishingInput) { |
| 2320 |
InputConnection ic = getCurrentInputConnection(); |
| 2321 |
if (ic != null) { |
| 2322 |
ic.finishComposingText(); |
| 2323 |
} |
| 2324 |
} |
| 2325 |
} |
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
public void onStartCandidatesView(EditorInfo info, boolean restarting) { |
| 2347 |
|
| 2348 |
} |
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
public void onFinishCandidatesView(boolean finishingInput) { |
| 2364 |
if (!finishingInput) { |
| 2365 |
InputConnection ic = getCurrentInputConnection(); |
| 2366 |
if (ic != null) { |
| 2367 |
ic.finishComposingText(); |
| 2368 |
} |
| 2369 |
} |
| 2370 |
} |
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
public void onPrepareStylusHandwriting() { |
| 2381 |
|
| 2382 |
} |
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
public boolean onStartStylusHandwriting() { |
| 2399 |
|
| 2400 |
return false; |
| 2401 |
} |
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) { |
| 2412 |
if (mInkWindow.isInkViewVisible()) { |
| 2413 |
mInkWindow.getDecorView().dispatchTouchEvent(motionEvent); |
| 2414 |
} else { |
| 2415 |
if (mPendingEvents == null) { |
| 2416 |
mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER); |
| 2417 |
} |
| 2418 |
mPendingEvents.append(motionEvent); |
| 2419 |
mInkWindow.setInkViewVisibilityListener(() -> { |
| 2420 |
if (mPendingEvents != null && !mPendingEvents.isEmpty()) { |
| 2421 |
for (MotionEvent event : mPendingEvents.toArray()) { |
| 2422 |
mInkWindow.getDecorView().dispatchTouchEvent(event); |
| 2423 |
} |
| 2424 |
mPendingEvents.clear(); |
| 2425 |
} |
| 2426 |
}); |
| 2427 |
} |
| 2428 |
} |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
public void onFinishStylusHandwriting() { |
| 2438 |
|
| 2439 |
} |
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
@Nullable |
| 2453 |
public final Window getStylusHandwritingWindow() { |
| 2454 |
return mInkWindow; |
| 2455 |
} |
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
public final void finishStylusHandwriting() { |
| 2470 |
if (DEBUG) Log.v(TAG, "finishStylusHandwriting()"); |
| 2471 |
if (mInkWindow == null) { |
| 2472 |
return; |
| 2473 |
} |
| 2474 |
if (!mHandwritingRequestId.isPresent()) { |
| 2475 |
return; |
| 2476 |
} |
| 2477 |
|
| 2478 |
final int requestId = mHandwritingRequestId.getAsInt(); |
| 2479 |
mHandwritingRequestId = OptionalInt.empty(); |
| 2480 |
|
| 2481 |
mHandwritingEventReceiver.dispose(); |
| 2482 |
mHandwritingEventReceiver = null; |
| 2483 |
mInkWindow.hide(false ); |
| 2484 |
|
| 2485 |
mPrivOps.resetStylusHandwriting(requestId); |
| 2486 |
mOnPreparedStylusHwCalled = false; |
| 2487 |
onFinishStylusHandwriting(); |
| 2488 |
} |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
public boolean onShowInputRequested(int flags, boolean configChange) { |
| 2506 |
if (!onEvaluateInputViewShown()) { |
| 2507 |
return false; |
| 2508 |
} |
| 2509 |
if ((flags&InputMethod.SHOW_EXPLICIT) == 0) { |
| 2510 |
if (!configChange && onEvaluateFullscreenMode()) { |
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
return false; |
| 2517 |
} |
| 2518 |
if (!mSettingsObserver.shouldShowImeWithHardKeyboard() && |
| 2519 |
getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
return false; |
| 2524 |
} |
| 2525 |
} |
| 2526 |
return true; |
| 2527 |
} |
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
private boolean dispatchOnShowInputRequested(int flags, boolean configChange) { |
| 2543 |
final boolean result = onShowInputRequested(flags, configChange); |
| 2544 |
mInlineSuggestionSessionController.notifyOnShowInputRequested(result); |
| 2545 |
if (result) { |
| 2546 |
mShowInputFlags = flags; |
| 2547 |
} else { |
| 2548 |
mShowInputFlags = 0; |
| 2549 |
} |
| 2550 |
return result; |
| 2551 |
} |
| 2552 |
|
| 2553 |
public void showWindow(boolean showInput) { |
| 2554 |
if (DEBUG) Log.v(TAG, "Showing window: showInput=" + showInput |
| 2555 |
+ " mShowInputRequested=" + mShowInputRequested |
| 2556 |
+ " mViewsCreated=" + mViewsCreated |
| 2557 |
+ " mDecorViewVisible=" + mDecorViewVisible |
| 2558 |
+ " mWindowVisible=" + mWindowVisible |
| 2559 |
+ " mInputStarted=" + mInputStarted |
| 2560 |
+ " mShowInputFlags=" + mShowInputFlags); |
| 2561 |
|
| 2562 |
if (mInShowWindow) { |
| 2563 |
Log.w(TAG, "Re-entrance in to showWindow"); |
| 2564 |
return; |
| 2565 |
} |
| 2566 |
|
| 2567 |
ImeTracing.getInstance().triggerServiceDump("InputMethodService#showWindow", mDumper, |
| 2568 |
null ); |
| 2569 |
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.showWindow"); |
| 2570 |
mDecorViewWasVisible = mDecorViewVisible; |
| 2571 |
mInShowWindow = true; |
| 2572 |
final int previousImeWindowStatus = |
| 2573 |
(mDecorViewVisible ? IME_ACTIVE : 0) | (isInputViewShown() |
| 2574 |
? (!mWindowVisible ? IME_INVISIBLE : IME_VISIBLE) : 0); |
| 2575 |
startViews(prepareWindow(showInput)); |
| 2576 |
final int nextImeWindowStatus = mapToImeWindowStatus(); |
| 2577 |
if (previousImeWindowStatus != nextImeWindowStatus) { |
| 2578 |
setImeWindowStatus(nextImeWindowStatus, mBackDisposition); |
| 2579 |
} |
| 2580 |
|
| 2581 |
mNavigationBarController.onWindowShown(); |
| 2582 |
|
| 2583 |
onWindowShown(); |
| 2584 |
mWindowVisible = true; |
| 2585 |
|
| 2586 |
|
| 2587 |
if (DEBUG) Log.v(TAG, "showWindow: draw decorView!"); |
| 2588 |
mWindow.show(); |
| 2589 |
mDecorViewWasVisible = true; |
| 2590 |
applyVisibilityInInsetsConsumerIfNecessary(true); |
| 2591 |
cancelImeSurfaceRemoval(); |
| 2592 |
mInShowWindow = false; |
| 2593 |
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 2594 |
registerCompatOnBackInvokedCallback(); |
| 2595 |
} |
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
private void registerCompatOnBackInvokedCallback() { |
| 2604 |
if (mBackCallbackRegistered) { |
| 2605 |
return; |
| 2606 |
} |
| 2607 |
if (mWindow != null) { |
| 2608 |
mWindow.getOnBackInvokedDispatcher().registerOnBackInvokedCallback( |
| 2609 |
OnBackInvokedDispatcher.PRIORITY_DEFAULT, mCompatBackCallback); |
| 2610 |
mBackCallbackRegistered = true; |
| 2611 |
} |
| 2612 |
} |
| 2613 |
|
| 2614 |
private void unregisterCompatOnBackInvokedCallback() { |
| 2615 |
if (!mBackCallbackRegistered) { |
| 2616 |
return; |
| 2617 |
} |
| 2618 |
if (mWindow != null) { |
| 2619 |
mWindow.getOnBackInvokedDispatcher() |
| 2620 |
.unregisterOnBackInvokedCallback(mCompatBackCallback); |
| 2621 |
mBackCallbackRegistered = false; |
| 2622 |
} |
| 2623 |
} |
| 2624 |
|
| 2625 |
private KeyEvent createBackKeyEvent(int action, boolean isTracking) { |
| 2626 |
final long when = SystemClock.uptimeMillis(); |
| 2627 |
return new KeyEvent(when, when, action, |
| 2628 |
KeyEvent.KEYCODE_BACK, 0 , 0 , |
| 2629 |
KeyCharacterMap.VIRTUAL_KEYBOARD, 0 , |
| 2630 |
KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY |
| 2631 |
| (isTracking ? KeyEvent.FLAG_TRACKING : 0), |
| 2632 |
InputDevice.SOURCE_KEYBOARD); |
| 2633 |
} |
| 2634 |
|
| 2635 |
private boolean prepareWindow(boolean showInput) { |
| 2636 |
boolean doShowInput = false; |
| 2637 |
mDecorViewVisible = true; |
| 2638 |
if (!mShowInputRequested && mInputStarted && showInput) { |
| 2639 |
doShowInput = true; |
| 2640 |
mShowInputRequested = true; |
| 2641 |
} |
| 2642 |
|
| 2643 |
if (DEBUG) Log.v(TAG, "showWindow: updating UI"); |
| 2644 |
initialize(); |
| 2645 |
updateFullscreenMode(); |
| 2646 |
updateInputViewShown(); |
| 2647 |
|
| 2648 |
if (!mViewsCreated) { |
| 2649 |
mViewsCreated = true; |
| 2650 |
initialize(); |
| 2651 |
if (DEBUG) Log.v(TAG, "CALL: onCreateCandidatesView"); |
| 2652 |
View v = onCreateCandidatesView(); |
| 2653 |
if (DEBUG) Log.v(TAG, "showWindow: candidates=" + v); |
| 2654 |
if (v != null) { |
| 2655 |
setCandidatesView(v); |
| 2656 |
} |
| 2657 |
} |
| 2658 |
return doShowInput; |
| 2659 |
} |
| 2660 |
|
| 2661 |
private void startViews(boolean doShowInput) { |
| 2662 |
if (mShowInputRequested) { |
| 2663 |
if (!mInputViewStarted) { |
| 2664 |
if (DEBUG) Log.v(TAG, "CALL: onStartInputView"); |
| 2665 |
mInputViewStarted = true; |
| 2666 |
mInlineSuggestionSessionController.notifyOnStartInputView(); |
| 2667 |
onStartInputView(mInputEditorInfo, false); |
| 2668 |
} |
| 2669 |
} else if (!mCandidatesViewStarted) { |
| 2670 |
if (DEBUG) Log.v(TAG, "CALL: onStartCandidatesView"); |
| 2671 |
mCandidatesViewStarted = true; |
| 2672 |
onStartCandidatesView(mInputEditorInfo, false); |
| 2673 |
} |
| 2674 |
if (doShowInput) startExtractingText(false); |
| 2675 |
} |
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
private void applyVisibilityInInsetsConsumerIfNecessary(boolean setVisible) { |
| 2683 |
ImeTracing.getInstance().triggerServiceDump( |
| 2684 |
"InputMethodService#applyVisibilityInInsetsConsumerIfNecessary", mDumper, |
| 2685 |
null ); |
| 2686 |
mPrivOps.applyImeVisibilityAsync(setVisible |
| 2687 |
? mCurShowInputToken : mCurHideInputToken, setVisible); |
| 2688 |
} |
| 2689 |
|
| 2690 |
private void finishViews(boolean finishingInput) { |
| 2691 |
if (mInputViewStarted) { |
| 2692 |
if (DEBUG) Log.v(TAG, "CALL: onFinishInputView"); |
| 2693 |
mInlineSuggestionSessionController.notifyOnFinishInputView(); |
| 2694 |
onFinishInputView(finishingInput); |
| 2695 |
} else if (mCandidatesViewStarted) { |
| 2696 |
if (DEBUG) Log.v(TAG, "CALL: onFinishCandidatesView"); |
| 2697 |
onFinishCandidatesView(finishingInput); |
| 2698 |
} |
| 2699 |
mInputViewStarted = false; |
| 2700 |
mCandidatesViewStarted = false; |
| 2701 |
} |
| 2702 |
|
| 2703 |
public void hideWindow() { |
| 2704 |
if (DEBUG) Log.v(TAG, "CALL: hideWindow"); |
| 2705 |
ImeTracing.getInstance().triggerServiceDump("InputMethodService#hideWindow", mDumper, |
| 2706 |
null ); |
| 2707 |
setImeWindowStatus(0, mBackDisposition); |
| 2708 |
applyVisibilityInInsetsConsumerIfNecessary(false); |
| 2709 |
mWindowVisible = false; |
| 2710 |
finishViews(false ); |
| 2711 |
if (mDecorViewVisible) { |
| 2712 |
|
| 2713 |
if (mInputView != null) { |
| 2714 |
mInputView.dispatchWindowVisibilityChanged(View.GONE); |
| 2715 |
} |
| 2716 |
mDecorViewVisible = false; |
| 2717 |
onWindowHidden(); |
| 2718 |
mDecorViewWasVisible = false; |
| 2719 |
} |
| 2720 |
mLastWasInFullscreenMode = mIsFullscreen; |
| 2721 |
updateFullscreenMode(); |
| 2722 |
unregisterCompatOnBackInvokedCallback(); |
| 2723 |
} |
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
public void onWindowShown() { |
| 2731 |
|
| 2732 |
} |
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
public void onWindowHidden() { |
| 2739 |
|
| 2740 |
} |
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
public void onBindInput() { |
| 2750 |
|
| 2751 |
} |
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
public void onUnbindInput() { |
| 2760 |
|
| 2761 |
} |
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
public void onStartInput(EditorInfo attribute, boolean restarting) { |
| 2776 |
|
| 2777 |
} |
| 2778 |
|
| 2779 |
void doFinishInput() { |
| 2780 |
if (DEBUG) Log.v(TAG, "CALL: doFinishInput"); |
| 2781 |
ImeTracing.getInstance().triggerServiceDump("InputMethodService#doFinishInput", mDumper, |
| 2782 |
null ); |
| 2783 |
finishViews(true ); |
| 2784 |
if (mInputStarted) { |
| 2785 |
mInlineSuggestionSessionController.notifyOnFinishInput(); |
| 2786 |
if (DEBUG) Log.v(TAG, "CALL: onFinishInput"); |
| 2787 |
onFinishInput(); |
| 2788 |
} |
| 2789 |
mInputStarted = false; |
| 2790 |
mStartedInputConnection = null; |
| 2791 |
mCurCompletions = null; |
| 2792 |
if (mInkWindow != null) { |
| 2793 |
finishStylusHandwriting(); |
| 2794 |
} |
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
unregisterCompatOnBackInvokedCallback(); |
| 2800 |
} |
| 2801 |
|
| 2802 |
void doStartInput(InputConnection ic, EditorInfo attribute, boolean restarting) { |
| 2803 |
if (!restarting && mInputStarted) { |
| 2804 |
doFinishInput(); |
| 2805 |
} |
| 2806 |
ImeTracing.getInstance().triggerServiceDump("InputMethodService#doStartInput", mDumper, |
| 2807 |
null ); |
| 2808 |
mInputStarted = true; |
| 2809 |
mStartedInputConnection = ic; |
| 2810 |
mInputEditorInfo = attribute; |
| 2811 |
initialize(); |
| 2812 |
mInlineSuggestionSessionController.notifyOnStartInput( |
| 2813 |
attribute == null ? null : attribute.packageName, |
| 2814 |
attribute == null ? null : attribute.autofillId); |
| 2815 |
if (DEBUG) Log.v(TAG, "CALL: onStartInput"); |
| 2816 |
onStartInput(attribute, restarting); |
| 2817 |
if (mDecorViewVisible) { |
| 2818 |
if (mShowInputRequested) { |
| 2819 |
if (DEBUG) Log.v(TAG, "CALL: onStartInputView"); |
| 2820 |
mInputViewStarted = true; |
| 2821 |
mInlineSuggestionSessionController.notifyOnStartInputView(); |
| 2822 |
onStartInputView(mInputEditorInfo, restarting); |
| 2823 |
startExtractingText(true); |
| 2824 |
} else if (mCandidatesVisibility == View.VISIBLE) { |
| 2825 |
if (DEBUG) Log.v(TAG, "CALL: onStartCandidatesView"); |
| 2826 |
mCandidatesViewStarted = true; |
| 2827 |
onStartCandidatesView(mInputEditorInfo, restarting); |
| 2828 |
} |
| 2829 |
} |
| 2830 |
} |
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
public void onFinishInput() { |
| 2845 |
InputConnection ic = getCurrentInputConnection(); |
| 2846 |
if (ic != null) { |
| 2847 |
ic.finishComposingText(); |
| 2848 |
} |
| 2849 |
} |
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
public void onDisplayCompletions(CompletionInfo[] completions) { |
| 2861 |
|
| 2862 |
} |
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
public void onUpdateExtractedText(int token, ExtractedText text) { |
| 2871 |
if (mExtractedToken != token) { |
| 2872 |
return; |
| 2873 |
} |
| 2874 |
if (text != null) { |
| 2875 |
if (mExtractEditText != null) { |
| 2876 |
mExtractedText = text; |
| 2877 |
mExtractEditText.setExtractedText(text); |
| 2878 |
} |
| 2879 |
} |
| 2880 |
} |
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
public void onUpdateSelection(int oldSelStart, int oldSelEnd, |
| 2897 |
int newSelStart, int newSelEnd, |
| 2898 |
int candidatesStart, int candidatesEnd) { |
| 2899 |
final ExtractEditText eet = mExtractEditText; |
| 2900 |
if (eet != null && isFullscreenMode() && mExtractedText != null) { |
| 2901 |
final int off = mExtractedText.startOffset; |
| 2902 |
eet.startInternalChanges(); |
| 2903 |
newSelStart -= off; |
| 2904 |
newSelEnd -= off; |
| 2905 |
final int len = eet.getText().length(); |
| 2906 |
if (newSelStart < 0) newSelStart = 0; |
| 2907 |
else if (newSelStart > len) newSelStart = len; |
| 2908 |
if (newSelEnd < 0) newSelEnd = 0; |
| 2909 |
else if (newSelEnd > len) newSelEnd = len; |
| 2910 |
eet.setSelection(newSelStart, newSelEnd); |
| 2911 |
eet.finishInternalChanges(); |
| 2912 |
} |
| 2913 |
} |
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
@Deprecated |
| 2929 |
public void onViewClicked(boolean focusChanged) { |
| 2930 |
|
| 2931 |
} |
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
@Deprecated |
| 2940 |
public void onUpdateCursor(Rect newCursor) { |
| 2941 |
|
| 2942 |
} |
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
public void onUpdateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo) { |
| 2952 |
|
| 2953 |
} |
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
public void requestHideSelf(int flags) { |
| 2966 |
requestHideSelf(flags, SoftInputShowHideReason.HIDE_SOFT_INPUT_FROM_IME); |
| 2967 |
} |
| 2968 |
|
| 2969 |
private void requestHideSelf(int flags, @SoftInputShowHideReason int reason) { |
| 2970 |
ImeTracing.getInstance().triggerServiceDump("InputMethodService#requestHideSelf", mDumper, |
| 2971 |
null ); |
| 2972 |
mPrivOps.hideMySoftInput(flags, reason); |
| 2973 |
} |
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
public final void requestShowSelf(int flags) { |
| 2984 |
ImeTracing.getInstance().triggerServiceDump("InputMethodService#requestShowSelf", mDumper, |
| 2985 |
null ); |
| 2986 |
mPrivOps.showMySoftInput(flags); |
| 2987 |
} |
| 2988 |
|
| 2989 |
private boolean handleBack(boolean doIt) { |
| 2990 |
if (mShowInputRequested) { |
| 2991 |
|
| 2992 |
|
| 2993 |
if (doIt) { |
| 2994 |
requestHideSelf(0 , SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_BACK_KEY); |
| 2995 |
} |
| 2996 |
return true; |
| 2997 |
} else if (mDecorViewVisible) { |
| 2998 |
if (mCandidatesVisibility == View.VISIBLE) { |
| 2999 |
|
| 3000 |
|
| 3001 |
if (doIt) setCandidatesViewShown(false); |
| 3002 |
} else { |
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
if (doIt) hideWindow(); |
| 3007 |
} |
| 3008 |
return true; |
| 3009 |
} |
| 3010 |
return false; |
| 3011 |
} |
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
private ExtractEditText getExtractEditTextIfVisible() { |
| 3018 |
if (!isExtractViewShown() || !isInputViewShown()) { |
| 3019 |
return null; |
| 3020 |
} |
| 3021 |
return mExtractEditText; |
| 3022 |
} |
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 3047 |
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 3048 |
final ExtractEditText eet = getExtractEditTextIfVisible(); |
| 3049 |
if (eet != null && eet.handleBackInTextActionModeIfNeeded(event)) { |
| 3050 |
return true; |
| 3051 |
} |
| 3052 |
if (handleBack(false)) { |
| 3053 |
event.startTracking(); |
| 3054 |
return true; |
| 3055 |
} |
| 3056 |
return false; |
| 3057 |
} |
| 3058 |
return doMovementKey(keyCode, event, MOVEMENT_DOWN); |
| 3059 |
} |
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 3067 |
return false; |
| 3068 |
} |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
|
| 3082 |
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) { |
| 3083 |
return doMovementKey(keyCode, event, count); |
| 3084 |
} |
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 3099 |
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { |
| 3100 |
final ExtractEditText eet = getExtractEditTextIfVisible(); |
| 3101 |
if (eet != null && eet.handleBackInTextActionModeIfNeeded(event)) { |
| 3102 |
return true; |
| 3103 |
} |
| 3104 |
if (event.isTracking() && !event.isCanceled()) { |
| 3105 |
return handleBack(true); |
| 3106 |
} |
| 3107 |
} |
| 3108 |
return doMovementKey(keyCode, event, MOVEMENT_UP); |
| 3109 |
} |
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
@Override |
| 3119 |
public boolean onTrackballEvent(MotionEvent event) { |
| 3120 |
if (DEBUG) Log.v(TAG, "onTrackballEvent: " + event); |
| 3121 |
return false; |
| 3122 |
} |
| 3123 |
|
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
@Override |
| 3132 |
public boolean onGenericMotionEvent(MotionEvent event) { |
| 3133 |
if (DEBUG) Log.v(TAG, "onGenericMotionEvent(): event " + event); |
| 3134 |
return false; |
| 3135 |
} |
| 3136 |
|
| 3137 |
public void onAppPrivateCommand(String action, Bundle data) { |
| 3138 |
} |
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
private void onToggleSoftInput(int showFlags, int hideFlags) { |
| 3144 |
if (DEBUG) Log.v(TAG, "toggleSoftInput()"); |
| 3145 |
if (isInputViewShown()) { |
| 3146 |
requestHideSelf( |
| 3147 |
hideFlags, SoftInputShowHideReason.HIDE_SOFT_INPUT_IME_TOGGLE_SOFT_INPUT); |
| 3148 |
} else { |
| 3149 |
requestShowSelf(showFlags); |
| 3150 |
} |
| 3151 |
} |
| 3152 |
|
| 3153 |
static final int MOVEMENT_DOWN = -1; |
| 3154 |
static final int MOVEMENT_UP = -2; |
| 3155 |
|
| 3156 |
void reportExtractedMovement(int keyCode, int count) { |
| 3157 |
int dx = 0, dy = 0; |
| 3158 |
switch (keyCode) { |
| 3159 |
case KeyEvent.KEYCODE_DPAD_LEFT: |
| 3160 |
dx = -count; |
| 3161 |
break; |
| 3162 |
case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 3163 |
dx = count; |
| 3164 |
break; |
| 3165 |
case KeyEvent.KEYCODE_DPAD_UP: |
| 3166 |
dy = -count; |
| 3167 |
break; |
| 3168 |
case KeyEvent.KEYCODE_DPAD_DOWN: |
| 3169 |
dy = count; |
| 3170 |
break; |
| 3171 |
} |
| 3172 |
onExtractedCursorMovement(dx, dy); |
| 3173 |
} |
| 3174 |
|
| 3175 |
boolean doMovementKey(int keyCode, KeyEvent event, int count) { |
| 3176 |
final ExtractEditText eet = getExtractEditTextIfVisible(); |
| 3177 |
if (eet != null) { |
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
MovementMethod movement = eet.getMovementMethod(); |
| 3182 |
Layout layout = eet.getLayout(); |
| 3183 |
if (movement != null && layout != null) { |
| 3184 |
|
| 3185 |
|
| 3186 |
if (count == MOVEMENT_DOWN) { |
| 3187 |
if (movement.onKeyDown(eet, eet.getText(), keyCode, event)) { |
| 3188 |
reportExtractedMovement(keyCode, 1); |
| 3189 |
return true; |
| 3190 |
} |
| 3191 |
} else if (count == MOVEMENT_UP) { |
| 3192 |
if (movement.onKeyUp(eet, eet.getText(), keyCode, event)) { |
| 3193 |
return true; |
| 3194 |
} |
| 3195 |
} else { |
| 3196 |
if (movement.onKeyOther(eet, eet.getText(), event)) { |
| 3197 |
reportExtractedMovement(keyCode, count); |
| 3198 |
} else { |
| 3199 |
KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN); |
| 3200 |
if (movement.onKeyDown(eet, eet.getText(), keyCode, down)) { |
| 3201 |
KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP); |
| 3202 |
movement.onKeyUp(eet, eet.getText(), keyCode, up); |
| 3203 |
while (--count > 0) { |
| 3204 |
movement.onKeyDown(eet, eet.getText(), keyCode, down); |
| 3205 |
movement.onKeyUp(eet, eet.getText(), keyCode, up); |
| 3206 |
} |
| 3207 |
reportExtractedMovement(keyCode, count); |
| 3208 |
} |
| 3209 |
} |
| 3210 |
} |
| 3211 |
} |
| 3212 |
|
| 3213 |
|
| 3214 |
switch (keyCode) { |
| 3215 |
case KeyEvent.KEYCODE_DPAD_LEFT: |
| 3216 |
case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 3217 |
case KeyEvent.KEYCODE_DPAD_UP: |
| 3218 |
case KeyEvent.KEYCODE_DPAD_DOWN: |
| 3219 |
return true; |
| 3220 |
} |
| 3221 |
} |
| 3222 |
|
| 3223 |
return false; |
| 3224 |
} |
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
public void sendDownUpKeyEvents(int keyEventCode) { |
| 3246 |
InputConnection ic = getCurrentInputConnection(); |
| 3247 |
if (ic == null) return; |
| 3248 |
long eventTime = SystemClock.uptimeMillis(); |
| 3249 |
ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, |
| 3250 |
KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
| 3251 |
KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE)); |
| 3252 |
ic.sendKeyEvent(new KeyEvent(eventTime, SystemClock.uptimeMillis(), |
| 3253 |
KeyEvent.ACTION_UP, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, |
| 3254 |
KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE)); |
| 3255 |
} |
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
public boolean sendDefaultEditorAction(boolean fromEnterKey) { |
| 3279 |
EditorInfo ei = getCurrentInputEditorInfo(); |
| 3280 |
if (ei != null && |
| 3281 |
(!fromEnterKey || (ei.imeOptions & |
| 3282 |
EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) && |
| 3283 |
(ei.imeOptions & EditorInfo.IME_MASK_ACTION) != |
| 3284 |
EditorInfo.IME_ACTION_NONE) { |
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
InputConnection ic = getCurrentInputConnection(); |
| 3289 |
if (ic != null) { |
| 3290 |
ic.performEditorAction(ei.imeOptions&EditorInfo.IME_MASK_ACTION); |
| 3291 |
} |
| 3292 |
return true; |
| 3293 |
} |
| 3294 |
|
| 3295 |
return false; |
| 3296 |
} |
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
public void sendKeyChar(char charCode) { |
| 3313 |
switch (charCode) { |
| 3314 |
case '\n': |
| 3315 |
if (!sendDefaultEditorAction(true)) { |
| 3316 |
sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); |
| 3317 |
} |
| 3318 |
break; |
| 3319 |
default: |
| 3320 |
|
| 3321 |
if (charCode >= '0' && charCode <= '9') { |
| 3322 |
sendDownUpKeyEvents(charCode - '0' + KeyEvent.KEYCODE_0); |
| 3323 |
} else { |
| 3324 |
InputConnection ic = getCurrentInputConnection(); |
| 3325 |
if (ic != null) { |
| 3326 |
ic.commitText(String.valueOf(charCode), 1); |
| 3327 |
} |
| 3328 |
} |
| 3329 |
break; |
| 3330 |
} |
| 3331 |
} |
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
public void onExtractedSelectionChanged(int start, int end) { |
| 3340 |
InputConnection conn = getCurrentInputConnection(); |
| 3341 |
if (conn != null) { |
| 3342 |
conn.setSelection(start, end); |
| 3343 |
} |
| 3344 |
} |
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
@UnsupportedAppUsage |
| 3350 |
public void onExtractedDeleteText(int start, int end) { |
| 3351 |
InputConnection conn = getCurrentInputConnection(); |
| 3352 |
if (conn != null) { |
| 3353 |
conn.finishComposingText(); |
| 3354 |
conn.setSelection(start, start); |
| 3355 |
conn.deleteSurroundingText(0, end - start); |
| 3356 |
} |
| 3357 |
} |
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
@UnsupportedAppUsage |
| 3363 |
public void onExtractedReplaceText(int start, int end, CharSequence text) { |
| 3364 |
InputConnection conn = getCurrentInputConnection(); |
| 3365 |
if (conn != null) { |
| 3366 |
conn.setComposingRegion(start, end); |
| 3367 |
conn.commitText(text, 1); |
| 3368 |
} |
| 3369 |
} |
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
@UnsupportedAppUsage |
| 3375 |
public void onExtractedSetSpan(Object span, int start, int end, int flags) { |
| 3376 |
InputConnection conn = getCurrentInputConnection(); |
| 3377 |
if (conn != null) { |
| 3378 |
if (!conn.setSelection(start, end)) return; |
| 3379 |
CharSequence text = conn.getSelectedText(InputConnection.GET_TEXT_WITH_STYLES); |
| 3380 |
if (text instanceof Spannable) { |
| 3381 |
((Spannable) text).setSpan(span, 0, text.length(), flags); |
| 3382 |
conn.setComposingRegion(start, end); |
| 3383 |
conn.commitText(text, 1); |
| 3384 |
} |
| 3385 |
} |
| 3386 |
} |
| 3387 |
|
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
public void onExtractedTextClicked() { |
| 3396 |
if (mExtractEditText == null) { |
| 3397 |
return; |
| 3398 |
} |
| 3399 |
if (mExtractEditText.hasVerticalScrollBar()) { |
| 3400 |
setCandidatesViewShown(false); |
| 3401 |
} |
| 3402 |
} |
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
public void onExtractedCursorMovement(int dx, int dy) { |
| 3415 |
if (mExtractEditText == null || dy == 0) { |
| 3416 |
return; |
| 3417 |
} |
| 3418 |
if (mExtractEditText.hasVerticalScrollBar()) { |
| 3419 |
setCandidatesViewShown(false); |
| 3420 |
} |
| 3421 |
} |
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
public boolean onExtractTextContextMenuItem(int id) { |
| 3432 |
InputConnection ic = getCurrentInputConnection(); |
| 3433 |
if (ic != null) { |
| 3434 |
ic.performContextMenuAction(id); |
| 3435 |
} |
| 3436 |
return true; |
| 3437 |
} |
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
public CharSequence getTextForImeAction(int imeOptions) { |
| 3451 |
switch (imeOptions&EditorInfo.IME_MASK_ACTION) { |
| 3452 |
case EditorInfo.IME_ACTION_NONE: |
| 3453 |
return null; |
| 3454 |
case EditorInfo.IME_ACTION_GO: |
| 3455 |
return getText(com.android.internal.R.string.ime_action_go); |
| 3456 |
case EditorInfo.IME_ACTION_SEARCH: |
| 3457 |
return getText(com.android.internal.R.string.ime_action_search); |
| 3458 |
case EditorInfo.IME_ACTION_SEND: |
| 3459 |
return getText(com.android.internal.R.string.ime_action_send); |
| 3460 |
case EditorInfo.IME_ACTION_NEXT: |
| 3461 |
return getText(com.android.internal.R.string.ime_action_next); |
| 3462 |
case EditorInfo.IME_ACTION_DONE: |
| 3463 |
return getText(com.android.internal.R.string.ime_action_done); |
| 3464 |
case EditorInfo.IME_ACTION_PREVIOUS: |
| 3465 |
return getText(com.android.internal.R.string.ime_action_previous); |
| 3466 |
default: |
| 3467 |
return getText(com.android.internal.R.string.ime_action_default); |
| 3468 |
} |
| 3469 |
} |
| 3470 |
|
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
@DrawableRes |
| 3480 |
private int getIconForImeAction(int imeOptions) { |
| 3481 |
switch (imeOptions&EditorInfo.IME_MASK_ACTION) { |
| 3482 |
case EditorInfo.IME_ACTION_GO: |
| 3483 |
return com.android.internal.R.drawable.ic_input_extract_action_go; |
| 3484 |
case EditorInfo.IME_ACTION_SEARCH: |
| 3485 |
return com.android.internal.R.drawable.ic_input_extract_action_search; |
| 3486 |
case EditorInfo.IME_ACTION_SEND: |
| 3487 |
return com.android.internal.R.drawable.ic_input_extract_action_send; |
| 3488 |
case EditorInfo.IME_ACTION_NEXT: |
| 3489 |
return com.android.internal.R.drawable.ic_input_extract_action_next; |
| 3490 |
case EditorInfo.IME_ACTION_DONE: |
| 3491 |
return com.android.internal.R.drawable.ic_input_extract_action_done; |
| 3492 |
case EditorInfo.IME_ACTION_PREVIOUS: |
| 3493 |
return com.android.internal.R.drawable.ic_input_extract_action_previous; |
| 3494 |
default: |
| 3495 |
return com.android.internal.R.drawable.ic_input_extract_action_return; |
| 3496 |
} |
| 3497 |
} |
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
|
| 3503 |
|
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
public void onUpdateExtractingVisibility(EditorInfo ei) { |
| 3509 |
if (ei.inputType == InputType.TYPE_NULL || |
| 3510 |
(ei.imeOptions&EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0) { |
| 3511 |
|
| 3512 |
setExtractViewShown(false); |
| 3513 |
return; |
| 3514 |
} |
| 3515 |
|
| 3516 |
setExtractViewShown(true); |
| 3517 |
} |
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
public void onUpdateExtractingViews(EditorInfo ei) { |
| 3535 |
if (!isExtractViewShown()) { |
| 3536 |
return; |
| 3537 |
} |
| 3538 |
|
| 3539 |
if (mExtractAccessories == null) { |
| 3540 |
return; |
| 3541 |
} |
| 3542 |
final boolean hasAction = ei.actionLabel != null || ( |
| 3543 |
(ei.imeOptions&EditorInfo.IME_MASK_ACTION) != EditorInfo.IME_ACTION_NONE && |
| 3544 |
(ei.imeOptions&EditorInfo.IME_FLAG_NO_ACCESSORY_ACTION) == 0 && |
| 3545 |
ei.inputType != InputType.TYPE_NULL); |
| 3546 |
if (hasAction) { |
| 3547 |
mExtractAccessories.setVisibility(View.VISIBLE); |
| 3548 |
if (mExtractAction != null) { |
| 3549 |
if (mExtractAction instanceof ImageButton) { |
| 3550 |
((ImageButton) mExtractAction) |
| 3551 |
.setImageResource(getIconForImeAction(ei.imeOptions)); |
| 3552 |
if (ei.actionLabel != null) { |
| 3553 |
mExtractAction.setContentDescription(ei.actionLabel); |
| 3554 |
} else { |
| 3555 |
mExtractAction.setContentDescription(getTextForImeAction(ei.imeOptions)); |
| 3556 |
} |
| 3557 |
} else { |
| 3558 |
if (ei.actionLabel != null) { |
| 3559 |
((TextView) mExtractAction).setText(ei.actionLabel); |
| 3560 |
} else { |
| 3561 |
((TextView) mExtractAction).setText(getTextForImeAction(ei.imeOptions)); |
| 3562 |
} |
| 3563 |
} |
| 3564 |
mExtractAction.setOnClickListener(mActionClickListener); |
| 3565 |
} |
| 3566 |
} else { |
| 3567 |
mExtractAccessories.setVisibility(View.GONE); |
| 3568 |
if (mExtractAction != null) { |
| 3569 |
mExtractAction.setOnClickListener(null); |
| 3570 |
} |
| 3571 |
} |
| 3572 |
} |
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
public void onExtractingInputChanged(EditorInfo ei) { |
| 3581 |
if (ei.inputType == InputType.TYPE_NULL) { |
| 3582 |
requestHideSelf(InputMethodManager.HIDE_NOT_ALWAYS, |
| 3583 |
SoftInputShowHideReason.HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED); |
| 3584 |
} |
| 3585 |
} |
| 3586 |
|
| 3587 |
void startExtractingText(boolean inputChanged) { |
| 3588 |
final ExtractEditText eet = mExtractEditText; |
| 3589 |
if (eet != null && getCurrentInputStarted() |
| 3590 |
&& isFullscreenMode()) { |
| 3591 |
mExtractedToken++; |
| 3592 |
ExtractedTextRequest req = new ExtractedTextRequest(); |
| 3593 |
req.token = mExtractedToken; |
| 3594 |
req.flags = InputConnection.GET_TEXT_WITH_STYLES; |
| 3595 |
req.hintMaxLines = 10; |
| 3596 |
req.hintMaxChars = 10000; |
| 3597 |
InputConnection ic = getCurrentInputConnection(); |
| 3598 |
mExtractedText = ic == null? null |
| 3599 |
: ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR); |
| 3600 |
if (mExtractedText == null || ic == null) { |
| 3601 |
Log.e(TAG, "Unexpected null in startExtractingText : mExtractedText = " |
| 3602 |
+ mExtractedText + ", input connection = " + ic); |
| 3603 |
} |
| 3604 |
final EditorInfo ei = getCurrentInputEditorInfo(); |
| 3605 |
|
| 3606 |
try { |
| 3607 |
eet.startInternalChanges(); |
| 3608 |
onUpdateExtractingVisibility(ei); |
| 3609 |
onUpdateExtractingViews(ei); |
| 3610 |
int inputType = ei.inputType; |
| 3611 |
if ((inputType&EditorInfo.TYPE_MASK_CLASS) |
| 3612 |
== EditorInfo.TYPE_CLASS_TEXT) { |
| 3613 |
if ((inputType&EditorInfo.TYPE_TEXT_FLAG_IME_MULTI_LINE) != 0) { |
| 3614 |
inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE; |
| 3615 |
} |
| 3616 |
} |
| 3617 |
eet.setInputType(inputType); |
| 3618 |
eet.setHint(ei.hintText); |
| 3619 |
if (mExtractedText != null) { |
| 3620 |
eet.setEnabled(true); |
| 3621 |
eet.setExtractedText(mExtractedText); |
| 3622 |
} else { |
| 3623 |
eet.setEnabled(false); |
| 3624 |
eet.setText(""); |
| 3625 |
} |
| 3626 |
} finally { |
| 3627 |
eet.finishInternalChanges(); |
| 3628 |
} |
| 3629 |
|
| 3630 |
if (inputChanged) { |
| 3631 |
onExtractingInputChanged(ei); |
| 3632 |
} |
| 3633 |
} |
| 3634 |
} |
| 3635 |
|
| 3636 |
private void dispatchOnCurrentInputMethodSubtypeChanged(InputMethodSubtype newSubtype) { |
| 3637 |
synchronized (mLock) { |
| 3638 |
mNotifyUserActionSent = false; |
| 3639 |
} |
| 3640 |
onCurrentInputMethodSubtypeChanged(newSubtype); |
| 3641 |
} |
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
protected void onCurrentInputMethodSubtypeChanged(InputMethodSubtype newSubtype) { |
| 3649 |
if (DEBUG) { |
| 3650 |
int nameResId = newSubtype.getNameResId(); |
| 3651 |
String mode = newSubtype.getMode(); |
| 3652 |
String output = "changeInputMethodSubtype:" |
| 3653 |
+ (nameResId == 0 ? "<none>" : getString(nameResId)) + "," |
| 3654 |
+ mode + "," |
| 3655 |
+ newSubtype.getLocale() + "," + newSubtype.getExtraValue(); |
| 3656 |
Log.v(TAG, "--- " + output); |
| 3657 |
} |
| 3658 |
} |
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
|
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
@Deprecated |
| 3673 |
public int getInputMethodWindowRecommendedHeight() { |
| 3674 |
Log.w(TAG, "getInputMethodWindowRecommendedHeight() is deprecated and now always returns 0." |
| 3675 |
+ " Do not use this method."); |
| 3676 |
return 0; |
| 3677 |
} |
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
|
| 3683 |
|
| 3684 |
@NonNull |
| 3685 |
@Override |
| 3686 |
final InputMethodServiceInternal createInputMethodServiceInternal() { |
| 3687 |
return new InputMethodServiceInternal() { |
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
@NonNull |
| 3692 |
@Override |
| 3693 |
public Context getContext() { |
| 3694 |
return InputMethodService.this; |
| 3695 |
} |
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
|
| 3700 |
@Override |
| 3701 |
public void exposeContent(@NonNull InputContentInfo inputContentInfo, |
| 3702 |
@NonNull InputConnection inputConnection) { |
| 3703 |
if (inputConnection == null) { |
| 3704 |
return; |
| 3705 |
} |
| 3706 |
if (getCurrentInputConnection() != inputConnection) { |
| 3707 |
return; |
| 3708 |
} |
| 3709 |
exposeContentInternal(inputContentInfo, getCurrentInputEditorInfo()); |
| 3710 |
} |
| 3711 |
|
| 3712 |
|
| 3713 |
|
| 3714 |
|
| 3715 |
@Override |
| 3716 |
public void notifyUserActionIfNecessary() { |
| 3717 |
synchronized (mLock) { |
| 3718 |
if (mNotifyUserActionSent) { |
| 3719 |
return; |
| 3720 |
} |
| 3721 |
mPrivOps.notifyUserActionAsync(); |
| 3722 |
mNotifyUserActionSent = true; |
| 3723 |
} |
| 3724 |
} |
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
private void exposeContentInternal(@NonNull InputContentInfo inputContentInfo, |
| 3737 |
@NonNull EditorInfo editorInfo) { |
| 3738 |
final Uri contentUri = inputContentInfo.getContentUri(); |
| 3739 |
final IInputContentUriToken uriToken = |
| 3740 |
mPrivOps.createInputContentUriToken(contentUri, editorInfo.packageName); |
| 3741 |
if (uriToken == null) { |
| 3742 |
Log.e(TAG, "createInputContentAccessToken failed. contentUri=" |
| 3743 |
+ contentUri.toString() + " packageName=" + editorInfo.packageName); |
| 3744 |
return; |
| 3745 |
} |
| 3746 |
inputContentInfo.setUriToken(uriToken); |
| 3747 |
} |
| 3748 |
|
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
@Override |
| 3753 |
public void dump(FileDescriptor fd, PrintWriter fout, String[]args) { |
| 3754 |
InputMethodService.this.dump(fd, fout, args); |
| 3755 |
} |
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
@Override |
| 3761 |
public void triggerServiceDump(String where, @Nullable byte[] icProto) { |
| 3762 |
ImeTracing.getInstance().triggerServiceDump(where, mDumper, icProto); |
| 3763 |
} |
| 3764 |
}; |
| 3765 |
} |
| 3766 |
|
| 3767 |
private int mapToImeWindowStatus() { |
| 3768 |
return IME_ACTIVE |
| 3769 |
| (isInputViewShown() ? IME_VISIBLE : 0); |
| 3770 |
} |
| 3771 |
|
| 3772 |
private boolean isAutomotive() { |
| 3773 |
return getApplicationContext().getPackageManager().hasSystemFeature( |
| 3774 |
PackageManager.FEATURE_AUTOMOTIVE); |
| 3775 |
} |
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
|
| 3781 |
@Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { |
| 3782 |
final Printer p = new PrintWriterPrinter(fout); |
| 3783 |
p.println("Input method service state for " + this + ":"); |
| 3784 |
p.println(" mViewsCreated=" + mViewsCreated); |
| 3785 |
p.println(" mDecorViewVisible=" + mDecorViewVisible |
| 3786 |
+ " mDecorViewWasVisible=" + mDecorViewWasVisible |
| 3787 |
+ " mWindowVisible=" + mWindowVisible |
| 3788 |
+ " mInShowWindow=" + mInShowWindow); |
| 3789 |
p.println(" Configuration=" + getResources().getConfiguration()); |
| 3790 |
p.println(" mToken=" + mToken); |
| 3791 |
p.println(" mInputBinding=" + mInputBinding); |
| 3792 |
p.println(" mInputConnection=" + mInputConnection); |
| 3793 |
p.println(" mStartedInputConnection=" + mStartedInputConnection); |
| 3794 |
p.println(" mInputStarted=" + mInputStarted |
| 3795 |
+ " mInputViewStarted=" + mInputViewStarted |
| 3796 |
+ " mCandidatesViewStarted=" + mCandidatesViewStarted); |
| 3797 |
|
| 3798 |
if (mInputEditorInfo != null) { |
| 3799 |
p.println(" mInputEditorInfo:"); |
| 3800 |
mInputEditorInfo.dump(p, " "); |
| 3801 |
} else { |
| 3802 |
p.println(" mInputEditorInfo: null"); |
| 3803 |
} |
| 3804 |
|
| 3805 |
p.println(" mShowInputRequested=" + mShowInputRequested |
| 3806 |
+ " mLastShowInputRequested=" + mLastShowInputRequested |
| 3807 |
+ " mShowInputFlags=0x" + Integer.toHexString(mShowInputFlags)); |
| 3808 |
p.println(" mCandidatesVisibility=" + mCandidatesVisibility |
| 3809 |
+ " mFullscreenApplied=" + mFullscreenApplied |
| 3810 |
+ " mIsFullscreen=" + mIsFullscreen |
| 3811 |
+ " mExtractViewHidden=" + mExtractViewHidden); |
| 3812 |
|
| 3813 |
if (mExtractedText != null) { |
| 3814 |
p.println(" mExtractedText:"); |
| 3815 |
p.println(" text=" + mExtractedText.text.length() + " chars" |
| 3816 |
+ " startOffset=" + mExtractedText.startOffset); |
| 3817 |
p.println(" selectionStart=" + mExtractedText.selectionStart |
| 3818 |
+ " selectionEnd=" + mExtractedText.selectionEnd |
| 3819 |
+ " flags=0x" + Integer.toHexString(mExtractedText.flags)); |
| 3820 |
} else { |
| 3821 |
p.println(" mExtractedText: null"); |
| 3822 |
} |
| 3823 |
p.println(" mExtractedToken=" + mExtractedToken); |
| 3824 |
p.println(" mIsInputViewShown=" + mIsInputViewShown |
| 3825 |
+ " mStatusIcon=" + mStatusIcon); |
| 3826 |
p.println("Last computed insets:"); |
| 3827 |
p.println(" contentTopInsets=" + mTmpInsets.contentTopInsets |
| 3828 |
+ " visibleTopInsets=" + mTmpInsets.visibleTopInsets |
| 3829 |
+ " touchableInsets=" + mTmpInsets.touchableInsets |
| 3830 |
+ " touchableRegion=" + mTmpInsets.touchableRegion); |
| 3831 |
p.println(" mSettingsObserver=" + mSettingsObserver); |
| 3832 |
p.println(" mNavigationBarController=" + mNavigationBarController.toDebugString()); |
| 3833 |
} |
| 3834 |
|
| 3835 |
private final ImeTracing.ServiceDumper mDumper = new ImeTracing.ServiceDumper() { |
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
@Override |
| 3840 |
public void dumpToProto(ProtoOutputStream proto, @Nullable byte[] icProto) { |
| 3841 |
final long token = proto.start(InputMethodServiceTraceProto.INPUT_METHOD_SERVICE); |
| 3842 |
mWindow.dumpDebug(proto, SOFT_INPUT_WINDOW); |
| 3843 |
proto.write(VIEWS_CREATED, mViewsCreated); |
| 3844 |
proto.write(DECOR_VIEW_VISIBLE, mDecorViewVisible); |
| 3845 |
proto.write(DECOR_VIEW_WAS_VISIBLE, mDecorViewWasVisible); |
| 3846 |
proto.write(WINDOW_VISIBLE, mWindowVisible); |
| 3847 |
proto.write(IN_SHOW_WINDOW, mInShowWindow); |
| 3848 |
proto.write(CONFIGURATION, getResources().getConfiguration().toString()); |
| 3849 |
proto.write(TOKEN, Objects.toString(mToken)); |
| 3850 |
proto.write(INPUT_BINDING, Objects.toString(mInputBinding)); |
| 3851 |
proto.write(INPUT_STARTED, mInputStarted); |
| 3852 |
proto.write(INPUT_VIEW_STARTED, mInputViewStarted); |
| 3853 |
proto.write(CANDIDATES_VIEW_STARTED, mCandidatesViewStarted); |
| 3854 |
if (mInputEditorInfo != null) { |
| 3855 |
mInputEditorInfo.dumpDebug(proto, INPUT_EDITOR_INFO); |
| 3856 |
} |
| 3857 |
proto.write(SHOW_INPUT_REQUESTED, mShowInputRequested); |
| 3858 |
proto.write(LAST_SHOW_INPUT_REQUESTED, mLastShowInputRequested); |
| 3859 |
proto.write(SHOW_INPUT_FLAGS, mShowInputFlags); |
| 3860 |
proto.write(CANDIDATES_VISIBILITY, mCandidatesVisibility); |
| 3861 |
proto.write(FULLSCREEN_APPLIED, mFullscreenApplied); |
| 3862 |
proto.write(IS_FULLSCREEN, mIsFullscreen); |
| 3863 |
proto.write(EXTRACT_VIEW_HIDDEN, mExtractViewHidden); |
| 3864 |
proto.write(EXTRACTED_TOKEN, mExtractedToken); |
| 3865 |
proto.write(IS_INPUT_VIEW_SHOWN, mIsInputViewShown); |
| 3866 |
proto.write(STATUS_ICON, mStatusIcon); |
| 3867 |
mTmpInsets.dumpDebug(proto, LAST_COMPUTED_INSETS); |
| 3868 |
proto.write(SETTINGS_OBSERVER, Objects.toString(mSettingsObserver)); |
| 3869 |
if (icProto != null) { |
| 3870 |
proto.write(INPUT_CONNECTION_CALL, icProto); |
| 3871 |
} |
| 3872 |
proto.end(token); |
| 3873 |
} |
| 3874 |
}; |
| 3875 |
|
| 3876 |
private void compatHandleBack() { |
| 3877 |
if (!mDecorViewVisible) { |
| 3878 |
Log.e(TAG, "Back callback invoked on a hidden IME. Removing the callback..."); |
| 3879 |
unregisterCompatOnBackInvokedCallback(); |
| 3880 |
return; |
| 3881 |
} |
| 3882 |
final KeyEvent downEvent = createBackKeyEvent( |
| 3883 |
KeyEvent.ACTION_DOWN, false ); |
| 3884 |
onKeyDown(KeyEvent.KEYCODE_BACK, downEvent); |
| 3885 |
final boolean hasStartedTracking = |
| 3886 |
(downEvent.getFlags() & KeyEvent.FLAG_START_TRACKING) != 0; |
| 3887 |
final KeyEvent upEvent = createBackKeyEvent(KeyEvent.ACTION_UP, hasStartedTracking); |
| 3888 |
onKeyUp(KeyEvent.KEYCODE_BACK, upEvent); |
| 3889 |
} |
| 3890 |
} |