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 android.view.textclassifier; 18 19 import android.annotation.Nullable; 20 import android.provider.DeviceConfig; 21 22 import com.android.internal.annotations.VisibleForTesting; 23 import com.android.internal.util.IndentingPrintWriter; 24 25 /** 26 * TextClassifier specific settings. 27 * 28 * <p>Currently, this class does not guarantee co-diverted flags are updated atomically. 29 * 30 * <pre> 31 * adb shell cmd device_config put textclassifier system_textclassifier_enabled true 32 * </pre> 33 * 34 * @see android.provider.DeviceConfig#NAMESPACE_TEXTCLASSIFIER 35 * @hide 36 */ 37 // TODO: Rename to TextClassifierSettings. 38 public final class TextClassificationConstants { 39 /** 40 * Whether the smart linkify feature is enabled. 41 */ 42 private static final String SMART_LINKIFY_ENABLED = "smart_linkify_enabled"; 43 /** 44 * Whether SystemTextClassifier is enabled. 45 */ 46 static final String SYSTEM_TEXT_CLASSIFIER_ENABLED = "system_textclassifier_enabled"; 47 /** 48 * Whether TextClassifierImpl is enabled. 49 */ 50 @VisibleForTesting 51 static final String LOCAL_TEXT_CLASSIFIER_ENABLED = "local_textclassifier_enabled"; 52 /** 53 * Enable smart selection without a visible UI changes. 54 */ 55 private static final String MODEL_DARK_LAUNCH_ENABLED = "model_dark_launch_enabled"; 56 /** 57 * Whether the smart selection feature is enabled. 58 */ 59 private static final String SMART_SELECTION_ENABLED = "smart_selection_enabled"; 60 /** 61 * Whether the smart text share feature is enabled. 62 */ 63 private static final String SMART_TEXT_SHARE_ENABLED = "smart_text_share_enabled"; 64 /** 65 * Whether animation for smart selection is enabled. 66 */ 67 private static final String SMART_SELECT_ANIMATION_ENABLED = 68 "smart_select_animation_enabled"; 69 /** 70 * Max length of text that generateLinks can accept. 71 */ 72 @VisibleForTesting 73 static final String GENERATE_LINKS_MAX_TEXT_LENGTH = "generate_links_max_text_length"; 74 /** 75 * The TextClassifierService which would like to use. Example of setting the package: 76 * <pre> 77 * adb shell cmd device_config put textclassifier textclassifier_service_package_override \ 78 * com.android.textclassifier 79 * </pre> 80 */ 81 @VisibleForTesting 82 static final String TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE = 83 "textclassifier_service_package_override"; 84 85 private static final String DEFAULT_TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE = null; 86 private static final boolean LOCAL_TEXT_CLASSIFIER_ENABLED_DEFAULT = true; 87 private static final boolean SYSTEM_TEXT_CLASSIFIER_ENABLED_DEFAULT = true; 88 private static final boolean MODEL_DARK_LAUNCH_ENABLED_DEFAULT = false; 89 private static final boolean SMART_SELECTION_ENABLED_DEFAULT = true; 90 private static final boolean SMART_TEXT_SHARE_ENABLED_DEFAULT = true; 91 private static final boolean SMART_LINKIFY_ENABLED_DEFAULT = true; 92 private static final boolean SMART_SELECT_ANIMATION_ENABLED_DEFAULT = true; 93 private static final int GENERATE_LINKS_MAX_TEXT_LENGTH_DEFAULT = 100 * 1000; 94 95 @Nullable getTextClassifierServicePackageOverride()96 public String getTextClassifierServicePackageOverride() { 97 return DeviceConfig.getString(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 98 TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE, 99 DEFAULT_TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE); 100 } 101 isLocalTextClassifierEnabled()102 public boolean isLocalTextClassifierEnabled() { 103 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 104 LOCAL_TEXT_CLASSIFIER_ENABLED, LOCAL_TEXT_CLASSIFIER_ENABLED_DEFAULT); 105 } 106 isSystemTextClassifierEnabled()107 public boolean isSystemTextClassifierEnabled() { 108 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 109 SYSTEM_TEXT_CLASSIFIER_ENABLED, 110 SYSTEM_TEXT_CLASSIFIER_ENABLED_DEFAULT); 111 } 112 isModelDarkLaunchEnabled()113 public boolean isModelDarkLaunchEnabled() { 114 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 115 MODEL_DARK_LAUNCH_ENABLED, MODEL_DARK_LAUNCH_ENABLED_DEFAULT); 116 } 117 isSmartSelectionEnabled()118 public boolean isSmartSelectionEnabled() { 119 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 120 SMART_SELECTION_ENABLED, SMART_SELECTION_ENABLED_DEFAULT); 121 } 122 isSmartTextShareEnabled()123 public boolean isSmartTextShareEnabled() { 124 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 125 SMART_TEXT_SHARE_ENABLED, SMART_TEXT_SHARE_ENABLED_DEFAULT); 126 } 127 isSmartLinkifyEnabled()128 public boolean isSmartLinkifyEnabled() { 129 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, SMART_LINKIFY_ENABLED, 130 SMART_LINKIFY_ENABLED_DEFAULT); 131 } 132 isSmartSelectionAnimationEnabled()133 public boolean isSmartSelectionAnimationEnabled() { 134 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 135 SMART_SELECT_ANIMATION_ENABLED, SMART_SELECT_ANIMATION_ENABLED_DEFAULT); 136 } 137 getGenerateLinksMaxTextLength()138 public int getGenerateLinksMaxTextLength() { 139 return DeviceConfig.getInt(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, 140 GENERATE_LINKS_MAX_TEXT_LENGTH, GENERATE_LINKS_MAX_TEXT_LENGTH_DEFAULT); 141 } 142 dump(IndentingPrintWriter pw)143 void dump(IndentingPrintWriter pw) { 144 pw.println("TextClassificationConstants:"); 145 pw.increaseIndent(); 146 pw.printPair("generate_links_max_text_length", getGenerateLinksMaxTextLength()) 147 .println(); 148 pw.printPair("local_textclassifier_enabled", isLocalTextClassifierEnabled()) 149 .println(); 150 pw.printPair("model_dark_launch_enabled", isModelDarkLaunchEnabled()) 151 .println(); 152 pw.printPair("smart_linkify_enabled", isSmartLinkifyEnabled()) 153 .println(); 154 pw.printPair("smart_select_animation_enabled", isSmartSelectionAnimationEnabled()) 155 .println(); 156 pw.printPair("smart_selection_enabled", isSmartSelectionEnabled()) 157 .println(); 158 pw.printPair("smart_text_share_enabled", isSmartTextShareEnabled()) 159 .println(); 160 pw.printPair("system_textclassifier_enabled", isSystemTextClassifierEnabled()) 161 .println(); 162 pw.printPair("textclassifier_service_package_override", 163 getTextClassifierServicePackageOverride()).println(); 164 pw.decreaseIndent(); 165 } 166 }