1 /* 2 * Copyright (C) 2022 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.server.inputmethod; 18 19 import static android.inputmethodservice.InputMethodService.FINISH_INPUT_NO_FALLBACK_CONNECTION; 20 import static android.view.inputmethod.InputMethodManager.CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING; 21 22 import android.content.Context; 23 import android.os.RemoteException; 24 import android.os.ServiceManager; 25 26 import com.android.internal.compat.IPlatformCompat; 27 28 /** 29 * A utility class used by {@link InputMethodManagerService} to manage the platform 30 * compatibility changes on IMF (Input Method Framework) side. 31 */ 32 final class ImePlatformCompatUtils { 33 private final IPlatformCompat mPlatformCompat = IPlatformCompat.Stub.asInterface( 34 ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); 35 36 /** 37 * Whether to finish the {@link android.view.inputmethod.InputConnection} when the device 38 * becomes {@link android.os.PowerManager#isInteractive non-interactive}. 39 * 40 * @param imeUid The uid of the IME application 41 */ shouldUseSetInteractiveProtocol(int imeUid)42 public boolean shouldUseSetInteractiveProtocol(int imeUid) { 43 return isChangeEnabledByUid(FINISH_INPUT_NO_FALLBACK_CONNECTION, imeUid); 44 } 45 46 /** 47 * Whether to clear {@link android.view.inputmethod.InputMethodManager#SHOW_FORCED} flag 48 * when the next IME focused application changed. 49 * 50 * @param clientUid The uid of the app 51 */ shouldClearShowForcedFlag(int clientUid)52 public boolean shouldClearShowForcedFlag(int clientUid) { 53 return isChangeEnabledByUid(CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING, clientUid); 54 } 55 isChangeEnabledByUid(long changeFlag, int uid)56 private boolean isChangeEnabledByUid(long changeFlag, int uid) { 57 boolean result = false; 58 try { 59 result = mPlatformCompat.isChangeEnabledByUid(changeFlag, uid); 60 } catch (RemoteException e) { 61 } 62 return result; 63 } 64 } 65