Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [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 | |
Abodunrinwa Toki | 88be5a6 | 2018-03-23 04:01:28 +0000 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 21 | import android.annotation.SystemService; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 22 | import android.annotation.UnsupportedAppUsage; |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 23 | import android.app.ActivityThread; |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 24 | import android.content.Context; |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 25 | import android.database.ContentObserver; |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 26 | import android.os.ServiceManager; |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 27 | import android.provider.DeviceConfig; |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 28 | import android.provider.Settings; |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 29 | import android.service.textclassifier.TextClassifierService; |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 30 | import android.view.textclassifier.TextClassifier.TextClassifierType; |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 31 | |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 32 | import com.android.internal.annotations.GuardedBy; |
Tony Mak | f93e9e5 | 2018-07-16 14:46:29 +0200 | [diff] [blame] | 33 | import com.android.internal.util.IndentingPrintWriter; |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 34 | import com.android.internal.util.Preconditions; |
| 35 | |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 36 | import java.lang.ref.WeakReference; |
| 37 | |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 38 | /** |
| 39 | * Interface to the text classification service. |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 40 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 41 | @SystemService(Context.TEXT_CLASSIFICATION_SERVICE) |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 42 | public final class TextClassificationManager { |
| 43 | |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 44 | private static final String LOG_TAG = "TextClassificationManager"; |
| 45 | |
| 46 | private final Object mLock = new Object(); |
Abodunrinwa Toki | 88be5a6 | 2018-03-23 04:01:28 +0000 | [diff] [blame] | 47 | private final TextClassificationSessionFactory mDefaultSessionFactory = |
| 48 | classificationContext -> new TextClassificationSession( |
| 49 | classificationContext, getTextClassifier()); |
Abodunrinwa Toki | b89cf02 | 2017-02-06 19:53:22 +0000 | [diff] [blame] | 50 | |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 51 | private final Context mContext; |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 52 | private final SettingsObserver mSettingsObserver; |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 53 | |
| 54 | @GuardedBy("mLock") |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 55 | @Nullable |
| 56 | private TextClassifier mCustomTextClassifier; |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 57 | @GuardedBy("mLock") |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 58 | @Nullable |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 59 | private TextClassifier mLocalTextClassifier; |
| 60 | @GuardedBy("mLock") |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 61 | @Nullable |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 62 | private TextClassifier mSystemTextClassifier; |
Abodunrinwa Toki | 88be5a6 | 2018-03-23 04:01:28 +0000 | [diff] [blame] | 63 | @GuardedBy("mLock") |
| 64 | private TextClassificationSessionFactory mSessionFactory; |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 65 | @GuardedBy("mLock") |
| 66 | private TextClassificationConstants mSettings; |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 67 | |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 68 | /** @hide */ |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 69 | public TextClassificationManager(Context context) { |
| 70 | mContext = Preconditions.checkNotNull(context); |
Abodunrinwa Toki | 88be5a6 | 2018-03-23 04:01:28 +0000 | [diff] [blame] | 71 | mSessionFactory = mDefaultSessionFactory; |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 72 | mSettingsObserver = new SettingsObserver(this); |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 73 | } |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 74 | |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 75 | /** |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 76 | * Returns the text classifier that was set via {@link #setTextClassifier(TextClassifier)}. |
| 77 | * If this is null, this method returns a default text classifier (i.e. either the system text |
Tony Mak | 31ff135 | 2019-01-22 21:26:05 +0000 | [diff] [blame] | 78 | * classifier if one exists, or a local text classifier running in this process.) |
| 79 | * <p> |
Abodunrinwa Toki | 324572e | 2019-02-12 19:01:01 +0000 | [diff] [blame] | 80 | * Note that requests to the TextClassifier may be handled in an OEM-provided process rather |
| 81 | * than in the calling app's process. |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 82 | * |
| 83 | * @see #setTextClassifier(TextClassifier) |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 84 | */ |
Abodunrinwa Toki | 88be5a6 | 2018-03-23 04:01:28 +0000 | [diff] [blame] | 85 | @NonNull |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 86 | public TextClassifier getTextClassifier() { |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 87 | synchronized (mLock) { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 88 | if (mCustomTextClassifier != null) { |
| 89 | return mCustomTextClassifier; |
| 90 | } else if (isSystemTextClassifierEnabled()) { |
| 91 | return getSystemTextClassifier(); |
| 92 | } else { |
| 93 | return getLocalTextClassifier(); |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 94 | } |
Abodunrinwa Toki | df61b03 | 2017-03-29 22:41:57 +0100 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Sets the text classifier. |
| 100 | * Set to null to use the system default text classifier. |
| 101 | * Set to {@link TextClassifier#NO_OP} to disable text classifier features. |
| 102 | */ |
| 103 | public void setTextClassifier(@Nullable TextClassifier textClassifier) { |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 104 | synchronized (mLock) { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 105 | mCustomTextClassifier = textClassifier; |
Abodunrinwa Toki | 43e0350 | 2017-01-13 13:46:33 -0800 | [diff] [blame] | 106 | } |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 107 | } |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 108 | |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 109 | /** |
| 110 | * Returns a specific type of text classifier. |
| 111 | * If the specified text classifier cannot be found, this returns {@link TextClassifier#NO_OP}. |
| 112 | * |
| 113 | * @see TextClassifier#LOCAL |
| 114 | * @see TextClassifier#SYSTEM |
| 115 | * @hide |
| 116 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 117 | @UnsupportedAppUsage |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 118 | public TextClassifier getTextClassifier(@TextClassifierType int type) { |
| 119 | switch (type) { |
| 120 | case TextClassifier.LOCAL: |
| 121 | return getLocalTextClassifier(); |
| 122 | default: |
| 123 | return getSystemTextClassifier(); |
| 124 | } |
| 125 | } |
| 126 | |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 127 | private TextClassificationConstants getSettings() { |
| 128 | synchronized (mLock) { |
| 129 | if (mSettings == null) { |
| 130 | mSettings = TextClassificationConstants.loadFromString(Settings.Global.getString( |
Michael Wright | b112f26 | 2018-05-24 13:41:50 +0100 | [diff] [blame] | 131 | getApplicationContext().getContentResolver(), |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 132 | Settings.Global.TEXT_CLASSIFIER_CONSTANTS)); |
| 133 | } |
| 134 | return mSettings; |
| 135 | } |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Abodunrinwa Toki | 88be5a6 | 2018-03-23 04:01:28 +0000 | [diff] [blame] | 138 | /** |
| 139 | * Call this method to start a text classification session with the given context. |
| 140 | * A session is created with a context helping the classifier better understand |
| 141 | * what the user needs and consists of queries and feedback events. The queries |
| 142 | * are directly related to providing useful functionality to the user and the events |
| 143 | * are a feedback loop back to the classifier helping it learn and better serve |
| 144 | * future queries. |
| 145 | * |
| 146 | * <p> All interactions with the returned classifier are considered part of a single |
| 147 | * session and are logically grouped. For example, when a text widget is focused |
| 148 | * all user interactions around text editing (selection, editing, etc) can be |
| 149 | * grouped together to allow the classifier get better. |
| 150 | * |
| 151 | * @param classificationContext The context in which classification would occur |
| 152 | * |
| 153 | * @return An instance to perform classification in the given context |
| 154 | */ |
| 155 | @NonNull |
| 156 | public TextClassifier createTextClassificationSession( |
| 157 | @NonNull TextClassificationContext classificationContext) { |
| 158 | Preconditions.checkNotNull(classificationContext); |
| 159 | final TextClassifier textClassifier = |
| 160 | mSessionFactory.createTextClassificationSession(classificationContext); |
| 161 | Preconditions.checkNotNull(textClassifier, "Session Factory should never return null"); |
| 162 | return textClassifier; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @see #createTextClassificationSession(TextClassificationContext, TextClassifier) |
| 167 | * @hide |
| 168 | */ |
| 169 | public TextClassifier createTextClassificationSession( |
| 170 | TextClassificationContext classificationContext, TextClassifier textClassifier) { |
| 171 | Preconditions.checkNotNull(classificationContext); |
| 172 | Preconditions.checkNotNull(textClassifier); |
| 173 | return new TextClassificationSession(classificationContext, textClassifier); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Sets a TextClassificationSessionFactory to be used to create session-aware TextClassifiers. |
| 178 | * |
| 179 | * @param factory the textClassification session factory. If this is null, the default factory |
| 180 | * will be used. |
| 181 | */ |
| 182 | public void setTextClassificationSessionFactory( |
| 183 | @Nullable TextClassificationSessionFactory factory) { |
| 184 | synchronized (mLock) { |
| 185 | if (factory != null) { |
| 186 | mSessionFactory = factory; |
| 187 | } else { |
| 188 | mSessionFactory = mDefaultSessionFactory; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 193 | @Override |
| 194 | protected void finalize() throws Throwable { |
| 195 | try { |
| 196 | // Note that fields could be null if the constructor threw. |
Michael Wright | b112f26 | 2018-05-24 13:41:50 +0100 | [diff] [blame] | 197 | if (mSettingsObserver != null) { |
| 198 | getApplicationContext().getContentResolver() |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 199 | .unregisterContentObserver(mSettingsObserver); |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 200 | DeviceConfig.removeOnPropertyChangedListener(mSettingsObserver); |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 201 | } |
| 202 | } finally { |
| 203 | super.finalize(); |
| 204 | } |
| 205 | } |
| 206 | |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 207 | private TextClassifier getSystemTextClassifier() { |
| 208 | synchronized (mLock) { |
| 209 | if (mSystemTextClassifier == null && isSystemTextClassifierEnabled()) { |
| 210 | try { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 211 | mSystemTextClassifier = new SystemTextClassifier(mContext, getSettings()); |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 212 | Log.d(LOG_TAG, "Initialized SystemTextClassifier"); |
| 213 | } catch (ServiceManager.ServiceNotFoundException e) { |
| 214 | Log.e(LOG_TAG, "Could not initialize SystemTextClassifier", e); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | if (mSystemTextClassifier != null) { |
| 219 | return mSystemTextClassifier; |
| 220 | } |
| 221 | return TextClassifier.NO_OP; |
| 222 | } |
| 223 | |
Tony Mak | 31ff135 | 2019-01-22 21:26:05 +0000 | [diff] [blame] | 224 | /** |
| 225 | * Returns a local textclassifier, which is running in this process. |
Tony Mak | 31ff135 | 2019-01-22 21:26:05 +0000 | [diff] [blame] | 226 | */ |
| 227 | @NonNull |
Abodunrinwa Toki | 324572e | 2019-02-12 19:01:01 +0000 | [diff] [blame] | 228 | private TextClassifier getLocalTextClassifier() { |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 229 | synchronized (mLock) { |
| 230 | if (mLocalTextClassifier == null) { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 231 | if (getSettings().isLocalTextClassifierEnabled()) { |
Abodunrinwa Toki | 253827f | 2018-04-24 19:19:48 +0100 | [diff] [blame] | 232 | mLocalTextClassifier = |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 233 | new TextClassifierImpl(mContext, getSettings(), TextClassifier.NO_OP); |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 234 | } else { |
| 235 | Log.d(LOG_TAG, "Local TextClassifier disabled"); |
Abodunrinwa Toki | 253827f | 2018-04-24 19:19:48 +0100 | [diff] [blame] | 236 | mLocalTextClassifier = TextClassifier.NO_OP; |
Abodunrinwa Toki | c7073a4 | 2018-02-28 23:02:13 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | return mLocalTextClassifier; |
| 240 | } |
| 241 | } |
| 242 | |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 243 | private boolean isSystemTextClassifierEnabled() { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 244 | return getSettings().isSystemTextClassifierEnabled() |
Abodunrinwa Toki | d32906c | 2018-01-18 04:34:44 -0800 | [diff] [blame] | 245 | && TextClassifierService.getServiceComponentName(mContext) != null; |
| 246 | } |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 247 | |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 248 | private void invalidate() { |
| 249 | synchronized (mLock) { |
| 250 | mSettings = null; |
| 251 | mLocalTextClassifier = null; |
| 252 | mSystemTextClassifier = null; |
| 253 | } |
| 254 | } |
| 255 | |
Michael Wright | b112f26 | 2018-05-24 13:41:50 +0100 | [diff] [blame] | 256 | Context getApplicationContext() { |
| 257 | return mContext.getApplicationContext() != null |
| 258 | ? mContext.getApplicationContext() |
| 259 | : mContext; |
| 260 | } |
| 261 | |
Tony Mak | f93e9e5 | 2018-07-16 14:46:29 +0200 | [diff] [blame] | 262 | /** @hide **/ |
| 263 | public void dump(IndentingPrintWriter pw) { |
| 264 | getLocalTextClassifier().dump(pw); |
| 265 | getSystemTextClassifier().dump(pw); |
| 266 | getSettings().dump(pw); |
| 267 | } |
| 268 | |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 269 | /** @hide */ |
| 270 | public static TextClassificationConstants getSettings(Context context) { |
| 271 | Preconditions.checkNotNull(context); |
| 272 | final TextClassificationManager tcm = |
| 273 | context.getSystemService(TextClassificationManager.class); |
| 274 | if (tcm != null) { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 275 | return tcm.getSettings(); |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 276 | } else { |
| 277 | return TextClassificationConstants.loadFromString(Settings.Global.getString( |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 278 | context.getApplicationContext().getContentResolver(), |
| 279 | Settings.Global.TEXT_CLASSIFIER_CONSTANTS)); |
| 280 | } |
| 281 | } |
| 282 | |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 283 | private static final class SettingsObserver extends ContentObserver |
| 284 | implements DeviceConfig.OnPropertyChangedListener { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 285 | |
| 286 | private final WeakReference<TextClassificationManager> mTcm; |
| 287 | |
| 288 | SettingsObserver(TextClassificationManager tcm) { |
| 289 | super(null); |
| 290 | mTcm = new WeakReference<>(tcm); |
Michael Wright | b112f26 | 2018-05-24 13:41:50 +0100 | [diff] [blame] | 291 | tcm.getApplicationContext().getContentResolver().registerContentObserver( |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 292 | Settings.Global.getUriFor(Settings.Global.TEXT_CLASSIFIER_CONSTANTS), |
| 293 | false /* notifyForDescendants */, |
| 294 | this); |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 295 | DeviceConfig.addOnPropertyChangedListener( |
| 296 | DeviceConfig.NAMESPACE_TEXTCLASSIFIER, |
| 297 | ActivityThread.currentApplication().getMainExecutor(), |
| 298 | this); |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void onChange(boolean selfChange) { |
Tony Mak | fc37457 | 2019-03-05 14:46:24 +0000 | [diff] [blame] | 303 | invalidateSettings(); |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public void onPropertyChanged(String namespace, String name, String value) { |
| 308 | invalidateSettings(); |
| 309 | } |
| 310 | |
| 311 | private void invalidateSettings() { |
Abodunrinwa Toki | c2449b8 | 2018-05-01 21:36:48 +0100 | [diff] [blame] | 312 | final TextClassificationManager tcm = mTcm.get(); |
| 313 | if (tcm != null) { |
| 314 | tcm.invalidate(); |
| 315 | } |
Abodunrinwa Toki | db8fc31 | 2018-02-26 21:37:51 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
Abodunrinwa Toki | f001fef | 2017-01-04 23:51:42 +0000 | [diff] [blame] | 318 | } |