1 /* 2 * Copyright (C) 2021 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.inputmethod; 18 19 import android.os.Bundle; 20 import android.view.KeyEvent; 21 import android.view.inputmethod.CompletionInfo; 22 import android.view.inputmethod.ExtractedText; 23 import android.view.inputmethod.ExtractedTextRequest; 24 import android.view.inputmethod.InputConnection; 25 26 import androidx.annotation.AnyThread; 27 28 /** 29 * A utility class to test compatibility with legacy apps that were built with old SDKs. 30 */ 31 public final class LegacyImeClientTestUtils { 32 33 /** 34 * Not intented to be instantiated. 35 */ LegacyImeClientTestUtils()36 private LegacyImeClientTestUtils() { 37 } 38 39 private static final class MinimallyImplementedNoOpInputConnection implements InputConnection { 40 /** 41 * {@inheritDoc} 42 */ 43 @Override getTextBeforeCursor(int n, int flags)44 public CharSequence getTextBeforeCursor(int n, int flags) { 45 return null; 46 } 47 48 /** 49 * {@inheritDoc} 50 */ 51 @Override getTextAfterCursor(int n, int flags)52 public CharSequence getTextAfterCursor(int n, int flags) { 53 return null; 54 } 55 56 /** 57 * {@inheritDoc} 58 */ 59 @Override getCursorCapsMode(int reqModes)60 public int getCursorCapsMode(int reqModes) { 61 return 0; 62 } 63 64 /** 65 * {@inheritDoc} 66 */ 67 @Override getExtractedText(ExtractedTextRequest request, int flags)68 public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { 69 return null; 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 @Override deleteSurroundingText(int beforeLength, int afterLength)76 public boolean deleteSurroundingText(int beforeLength, int afterLength) { 77 return false; 78 } 79 80 /** 81 * {@inheritDoc} 82 */ 83 @Override setComposingText(CharSequence text, int newCursorPosition)84 public boolean setComposingText(CharSequence text, int newCursorPosition) { 85 return false; 86 } 87 88 /** 89 * {@inheritDoc} 90 */ 91 @Override finishComposingText()92 public boolean finishComposingText() { 93 return false; 94 } 95 96 /** 97 * {@inheritDoc} 98 */ 99 @Override commitText(CharSequence text, int newCursorPosition)100 public boolean commitText(CharSequence text, int newCursorPosition) { 101 return false; 102 } 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override commitCompletion(CompletionInfo text)108 public boolean commitCompletion(CompletionInfo text) { 109 return false; 110 } 111 112 /** 113 * {@inheritDoc} 114 */ 115 @Override setSelection(int start, int end)116 public boolean setSelection(int start, int end) { 117 return false; 118 } 119 120 /** 121 * {@inheritDoc} 122 */ 123 @Override performEditorAction(int editorAction)124 public boolean performEditorAction(int editorAction) { 125 return false; 126 } 127 128 /** 129 * {@inheritDoc} 130 */ 131 @Override performContextMenuAction(int id)132 public boolean performContextMenuAction(int id) { 133 return false; 134 } 135 136 /** 137 * {@inheritDoc} 138 */ 139 @Override beginBatchEdit()140 public boolean beginBatchEdit() { 141 return false; 142 } 143 144 /** 145 * {@inheritDoc} 146 */ 147 @Override endBatchEdit()148 public boolean endBatchEdit() { 149 return false; 150 } 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override sendKeyEvent(KeyEvent event)156 public boolean sendKeyEvent(KeyEvent event) { 157 return false; 158 } 159 160 /** 161 * {@inheritDoc} 162 */ 163 @Override clearMetaKeyStates(int states)164 public boolean clearMetaKeyStates(int states) { 165 return false; 166 } 167 168 /** 169 * {@inheritDoc} 170 */ 171 @Override reportFullscreenMode(boolean enabled)172 public boolean reportFullscreenMode(boolean enabled) { 173 return false; 174 } 175 176 /** 177 * {@inheritDoc} 178 */ 179 @Override performPrivateCommand(String action, Bundle data)180 public boolean performPrivateCommand(String action, Bundle data) { 181 return false; 182 } 183 } 184 185 /** 186 * @return an instance of {@link InputConnection} that implements only methods that were 187 * available in {@link android.os.Build.VERSION_CODES#CUPCAKE}. 188 */ 189 @AnyThread createMinimallyImplementedNoOpInputConnection()190 public static InputConnection createMinimallyImplementedNoOpInputConnection() { 191 return new MinimallyImplementedNoOpInputConnection(); 192 } 193 } 194