summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michael Wright <michaelwr@google.com> 2018-05-24 12:58:15 -0700
committer android-build-merger <android-build-merger@google.com> 2018-05-24 12:58:15 -0700
commitc4e7c86a6069b892e6a7b0692c8a4ece2ef0829b (patch)
tree3f976cbb5dbe1d9e79fd084c7bce9b37a928f47d
parent2c2424a0917749ba114c2ac97b3d99605f5c61e4 (diff)
parent87631c2d29d8f5eaa83c769a7eaa9cb82e85eb9b (diff)
Merge "Use TCM context if application context is unavailble." into pi-dev
am: 87631c2d29 Change-Id: I8ec20d2c5815dfffeb60f11c0b8f9490feed5e94
-rw-r--r--core/java/android/view/textclassifier/TextClassificationManager.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/core/java/android/view/textclassifier/TextClassificationManager.java b/core/java/android/view/textclassifier/TextClassificationManager.java
index aee0aa719bc2..dc1194bbe07c 100644
--- a/core/java/android/view/textclassifier/TextClassificationManager.java
+++ b/core/java/android/view/textclassifier/TextClassificationManager.java
@@ -120,7 +120,7 @@ public final class TextClassificationManager {
synchronized (mLock) {
if (mSettings == null) {
mSettings = TextClassificationConstants.loadFromString(Settings.Global.getString(
- mContext.getApplicationContext().getContentResolver(),
+ getApplicationContext().getContentResolver(),
Settings.Global.TEXT_CLASSIFIER_CONSTANTS));
}
return mSettings;
@@ -186,8 +186,8 @@ public final class TextClassificationManager {
protected void finalize() throws Throwable {
try {
// Note that fields could be null if the constructor threw.
- if (mContext != null && mSettingsObserver != null) {
- mContext.getApplicationContext().getContentResolver()
+ if (mSettingsObserver != null) {
+ getApplicationContext().getContentResolver()
.unregisterContentObserver(mSettingsObserver);
}
} finally {
@@ -240,6 +240,12 @@ public final class TextClassificationManager {
}
}
+ Context getApplicationContext() {
+ return mContext.getApplicationContext() != null
+ ? mContext.getApplicationContext()
+ : mContext;
+ }
+
/** @hide */
public static TextClassificationConstants getSettings(Context context) {
Preconditions.checkNotNull(context);
@@ -261,7 +267,7 @@ public final class TextClassificationManager {
SettingsObserver(TextClassificationManager tcm) {
super(null);
mTcm = new WeakReference<>(tcm);
- tcm.mContext.getApplicationContext().getContentResolver().registerContentObserver(
+ tcm.getApplicationContext().getContentResolver().registerContentObserver(
Settings.Global.getUriFor(Settings.Global.TEXT_CLASSIFIER_CONSTANTS),
false /* notifyForDescendants */,
this);