1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.cts.mockime; 18 19 import android.os.Bundle; 20 21 import androidx.annotation.NonNull; 22 import androidx.annotation.Nullable; 23 24 /** 25 * An immutable object that stores several runtime state of {@link MockIme}. 26 */ 27 public final class ImeState { 28 private final boolean mHasInputBinding; 29 private final boolean mHasDummyInputConnection; 30 31 /** 32 * @return {@code true} if {@link MockIme#getCurrentInputBinding()} returned non-null 33 * {@link android.view.inputmethod.InputBinding} when this snapshot was taken. 34 */ 35 public boolean hasInputBinding() { 36 return mHasInputBinding; 37 } 38 39 /** 40 * @return {@code true} if {@link MockIme#getCurrentInputConnection()} returned non-dummy 41 * {@link android.view.inputmethod.InputConnection} when this snapshot was taken. 42 */ 43 public boolean hasDummyInputConnection() { 44 return mHasDummyInputConnection; 45 } 46 47 ImeState(boolean hasInputBinding, boolean hasDummyInputConnection) { 48 mHasInputBinding = hasInputBinding; 49 mHasDummyInputConnection = hasDummyInputConnection; 50 } 51 52 @NonNull 53 Bundle toBundle() { 54 final Bundle bundle = new Bundle(); 55 bundle.putBoolean("mHasInputBinding", mHasInputBinding); 56 bundle.putBoolean("mHasDummyInputConnection", mHasDummyInputConnection); 57 return bundle; 58 } 59 60 @Nullable 61 static ImeState fromBundle(@Nullable Bundle bundle) { 62 if (bundle == null) { 63 return null; 64 } 65 final boolean hasInputBinding = bundle.getBoolean("mHasInputBinding"); 66 final boolean hasDummyInputConnection = bundle.getBoolean("mHasDummyInputConnection"); 67 return new ImeState(hasInputBinding, hasDummyInputConnection); 68 } 69 } 70