1 /* 2 * Copyright (C) 2018 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 android.view.inputmethod; 18 19 import android.annotation.Nullable; 20 import android.annotation.TestApi; 21 import android.content.ComponentName; 22 import android.os.Build; 23 import android.os.SystemProperties; 24 25 /** 26 * Various (pseudo) constants about IME behaviors. 27 * 28 * @hide 29 */ 30 @TestApi 31 public class InputMethodSystemProperty { 32 /** 33 * System property key for the production use. The value must be either empty or a valid 34 * (flattened) component name of the multi-client IME. 35 */ 36 private static final String PROP_PROD_MULTI_CLIENT_IME = "ro.sys.multi_client_ime"; 37 38 /** 39 * System property key for debugging purpose. The value must be either empty or a valid 40 * (flattened) component name of the multi-client IME. 41 * 42 * <p>This value will be ignored when {@link Build#IS_DEBUGGABLE} returns {@code false}</p> 43 */ 44 private static final String PROP_DEBUG_MULTI_CLIENT_IME = "persist.debug.multi_client_ime"; 45 46 /** 47 * System property key for debugging purpose. The value must be empty, "1", or "0". 48 * 49 * <p>Values 'y', 'yes', '1', 'true' or 'on' are considered true.</p> 50 * 51 * <p>To set, run "adb root && adb shell setprop persist.debug.per_profile_ime 1".</p> 52 * 53 * <p>This value will be ignored when {@link Build#IS_DEBUGGABLE} returns {@code false}.</p> 54 */ 55 private static final String PROP_DEBUG_PER_PROFILE_IME = "persist.debug.per_profile_ime"; 56 57 @Nullable getMultiClientImeComponentName()58 private static ComponentName getMultiClientImeComponentName() { 59 if (Build.IS_DEBUGGABLE) { 60 // If debuggable, allow developers to override the multi-client IME component name 61 // with a different (writable) key. 62 final ComponentName debugIme = ComponentName.unflattenFromString( 63 SystemProperties.get(PROP_DEBUG_MULTI_CLIENT_IME, "")); 64 if (debugIme != null) { 65 return debugIme; 66 } 67 } 68 return ComponentName.unflattenFromString( 69 SystemProperties.get(PROP_PROD_MULTI_CLIENT_IME, "")); 70 } 71 72 /** 73 * {@link ComponentName} of multi-client IME to be used. 74 * 75 * <p>TODO: Move this back to MultiClientInputMethodManagerService once 76 * {@link #PER_PROFILE_IME_ENABLED} always becomes {@code true}.</p> 77 * 78 * @hide 79 */ 80 @Nullable 81 public static final ComponentName sMultiClientImeComponentName = 82 getMultiClientImeComponentName(); 83 84 /** 85 * {@code true} when multi-client IME is enabled. 86 * 87 * <p>TODO: Move this back to MultiClientInputMethodManagerService once 88 * {@link #PER_PROFILE_IME_ENABLED} always becomes {@code true}.</p> 89 * 90 * @hide 91 */ 92 @TestApi 93 public static final boolean MULTI_CLIENT_IME_ENABLED = (sMultiClientImeComponentName != null); 94 95 /** 96 * {@code true} when per-profile IME is enabled. 97 * @hide 98 */ 99 public static final boolean PER_PROFILE_IME_ENABLED; 100 static { 101 if (MULTI_CLIENT_IME_ENABLED) { 102 PER_PROFILE_IME_ENABLED = true; 103 } else if (Build.IS_DEBUGGABLE) { 104 PER_PROFILE_IME_ENABLED = SystemProperties.getBoolean(PROP_DEBUG_PER_PROFILE_IME, true); 105 } else { 106 PER_PROFILE_IME_ENABLED = true; 107 } 108 } 109 } 110