Abodunrinwa Toki | 0e6b43e | 2017-09-19 23:18:40 +0100 | [diff] [blame] | 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 | |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
| 20 | import android.provider.DeviceConfig; |
| 21 | |
| 22 | import com.android.internal.annotations.VisibleForTesting; |
Tony Mak | f93e9e5 | 2018-07-16 14:46:29 +0200 | [diff] [blame] | 23 | import com.android.internal.util.IndentingPrintWriter; |
| 24 | |
Abodunrinwa Toki | 0e6b43e | 2017-09-19 23:18:40 +0100 | [diff] [blame] | 25 | /** |
| 26 | * TextClassifier specific settings. |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 27 | * |
| 28 | * <p>Currently, this class does not guarantee co-diverted flags are updated atomically. |
| 29 | * |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 30 | * <pre> |
| 31 | * adb shell cmd device_config put textclassifier system_textclassifier_enabled true |
| 32 | * </pre> |
| 33 | * |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 34 | * @see android.provider.DeviceConfig#NAMESPACE_TEXTCLASSIFIER |
Abodunrinwa Toki | 0e6b43e | 2017-09-19 23:18:40 +0100 | [diff] [blame] | 35 | * @hide |
| 36 | */ |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 37 | // TODO: Rename to TextClassifierSettings. |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 38 | public final class TextClassificationConstants { |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 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 | */ |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 46 | static final String SYSTEM_TEXT_CLASSIFIER_ENABLED = "system_textclassifier_enabled"; |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 47 | /** |
| 48 | * Whether TextClassifierImpl is enabled. |
| 49 | */ |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 50 | @VisibleForTesting |
| 51 | static final String LOCAL_TEXT_CLASSIFIER_ENABLED = "local_textclassifier_enabled"; |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 52 | /** |
| 53 | * Enable smart selection without a visible UI changes. |
| 54 | */ |
| 55 | private static final String MODEL_DARK_LAUNCH_ENABLED = "model_dark_launch_enabled"; |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 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 | */ |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 67 | private static final String SMART_SELECT_ANIMATION_ENABLED = |
| 68 | "smart_select_animation_enabled"; |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 69 | /** |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 70 | * Max length of text that generateLinks can accept. |
| 71 | */ |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 72 | @VisibleForTesting |
Tony Mak | 293bdf3 | 2020-02-18 11:33:43 +0000 | [diff] [blame] | 73 | static final String GENERATE_LINKS_MAX_TEXT_LENGTH = "generate_links_max_text_length"; |
Joanne Chung | b50ab4b | 2019-10-14 16:40:57 +0800 | [diff] [blame] | 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> |
Joanne Chung | b50ab4b | 2019-10-14 16:40:57 +0800 | [diff] [blame] | 80 | */ |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 81 | @VisibleForTesting |
| 82 | static final String TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE = |
Joanne Chung | b50ab4b | 2019-10-14 16:40:57 +0800 | [diff] [blame] | 83 | "textclassifier_service_package_override"; |
| 84 | |
| 85 | private static final String DEFAULT_TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE = null; |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 86 | private static final boolean LOCAL_TEXT_CLASSIFIER_ENABLED_DEFAULT = true; |
| 87 | private static final boolean SYSTEM_TEXT_CLASSIFIER_ENABLED_DEFAULT = true; |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 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; |
Richard Ledley | 9cfa606 | 2018-01-15 13:13:29 +0000 | [diff] [blame] | 91 | private static final boolean SMART_LINKIFY_ENABLED_DEFAULT = true; |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 92 | private static final boolean SMART_SELECT_ANIMATION_ENABLED_DEFAULT = true; |
Jan Althaus | 108aad3 | 2018-01-30 15:26:55 +0100 | [diff] [blame] | 93 | private static final int GENERATE_LINKS_MAX_TEXT_LENGTH_DEFAULT = 100 * 1000; |
Abodunrinwa Toki | 0e6b43e | 2017-09-19 23:18:40 +0100 | [diff] [blame] | 94 | |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 95 | @Nullable |
| 96 | public String getTextClassifierServicePackageOverride() { |
| 97 | return DeviceConfig.getString(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
Joanne Chung | b50ab4b | 2019-10-14 16:40:57 +0800 | [diff] [blame] | 98 | TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE, |
| 99 | DEFAULT_TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE); |
| 100 | } |
| 101 | |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 102 | public boolean isLocalTextClassifierEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 103 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 104 | LOCAL_TEXT_CLASSIFIER_ENABLED, LOCAL_TEXT_CLASSIFIER_ENABLED_DEFAULT); |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | public boolean isSystemTextClassifierEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 108 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 109 | SYSTEM_TEXT_CLASSIFIER_ENABLED, |
| 110 | SYSTEM_TEXT_CLASSIFIER_ENABLED_DEFAULT); |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 113 | public boolean isModelDarkLaunchEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 114 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 115 | MODEL_DARK_LAUNCH_ENABLED, MODEL_DARK_LAUNCH_ENABLED_DEFAULT); |
Abodunrinwa Toki | 0e6b43e | 2017-09-19 23:18:40 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 118 | public boolean isSmartSelectionEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 119 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 120 | SMART_SELECTION_ENABLED, SMART_SELECTION_ENABLED_DEFAULT); |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | public boolean isSmartTextShareEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 124 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 125 | SMART_TEXT_SHARE_ENABLED, SMART_TEXT_SHARE_ENABLED_DEFAULT); |
Abodunrinwa Toki | 0e6b43e | 2017-09-19 23:18:40 +0100 | [diff] [blame] | 126 | } |
Richard Ledley | 9cfa606 | 2018-01-15 13:13:29 +0000 | [diff] [blame] | 127 | |
| 128 | public boolean isSmartLinkifyEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 129 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, SMART_LINKIFY_ENABLED, |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 130 | SMART_LINKIFY_ENABLED_DEFAULT); |
Richard Ledley | 9cfa606 | 2018-01-15 13:13:29 +0000 | [diff] [blame] | 131 | } |
Jan Althaus | 108aad3 | 2018-01-30 15:26:55 +0100 | [diff] [blame] | 132 | |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 133 | public boolean isSmartSelectionAnimationEnabled() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 134 | return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 135 | SMART_SELECT_ANIMATION_ENABLED, SMART_SELECT_ANIMATION_ENABLED_DEFAULT); |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Jan Althaus | 108aad3 | 2018-01-30 15:26:55 +0100 | [diff] [blame] | 138 | public int getGenerateLinksMaxTextLength() { |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 139 | return DeviceConfig.getInt(DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 140 | GENERATE_LINKS_MAX_TEXT_LENGTH, GENERATE_LINKS_MAX_TEXT_LENGTH_DEFAULT); |
Jan Althaus | 108aad3 | 2018-01-30 15:26:55 +0100 | [diff] [blame] | 141 | } |
Jan Althaus | 31efdc3 | 2018-02-19 22:23:13 +0100 | [diff] [blame] | 142 | |
Tony Mak | f93e9e5 | 2018-07-16 14:46:29 +0200 | [diff] [blame] | 143 | void dump(IndentingPrintWriter pw) { |
| 144 | pw.println("TextClassificationConstants:"); |
| 145 | pw.increaseIndent(); |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 146 | pw.printPair("generate_links_max_text_length", getGenerateLinksMaxTextLength()) |
| 147 | .println(); |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 148 | pw.printPair("local_textclassifier_enabled", isLocalTextClassifierEnabled()) |
| 149 | .println(); |
| 150 | pw.printPair("model_dark_launch_enabled", isModelDarkLaunchEnabled()) |
| 151 | .println(); |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 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(); |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 160 | pw.printPair("system_textclassifier_enabled", isSystemTextClassifierEnabled()) |
| 161 | .println(); |
Joanne Chung | c44f529 | 2019-12-02 21:18:43 +0800 | [diff] [blame] | 162 | pw.printPair("textclassifier_service_package_override", |
| 163 | getTextClassifierServicePackageOverride()).println(); |
Tony Mak | f93e9e5 | 2018-07-16 14:46:29 +0200 | [diff] [blame] | 164 | pw.decreaseIndent(); |
Tony Mak | f93e9e5 | 2018-07-16 14:46:29 +0200 | [diff] [blame] | 165 | } |
Abodunrinwa Toki | 0634af3 | 2019-04-04 13:10:59 +0100 | [diff] [blame] | 166 | } |