From e4395bd751032131d89506b9588721944ee45763 Mon Sep 17 00:00:00 2001 From: gaochong Date: Wed, 21 Dec 2016 20:06:37 +0800 Subject: [PATCH] Handle SubSettings instance leaks in Index.java Index's constructor will hold context of caller. context.getApplicationContext() instead of context to prevent activity leaks. Bug: https://code.google.com/p/android/issues/detail?id=223322 Test: manual-start a new activity call Index constructor ,then pressed back. Change-Id: Ic12af62f9b718d328610a57985f64ca4629bab99 Signed-off-by: gaochong --- src/com/android/settings/search/Index.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java index ccedd627c44..084f9c35fed 100644 --- a/src/com/android/settings/search/Index.java +++ b/src/com/android/settings/search/Index.java @@ -217,20 +217,20 @@ public class Index { */ public static Index getInstance(Context context) { if (sInstance == null) { - sInstance = new Index(context.getApplicationContext(), BASE_AUTHORITY); + synchronized (Index.class) { + if (sInstance == null) { + sInstance = new Index(context.getApplicationContext(), BASE_AUTHORITY); + } + } } return sInstance; } - public Index(Context context, String baseAuthority) { + private Index(Context context, String baseAuthority) { mContext = context; mBaseAuthority = baseAuthority; } - public void setContext(Context context) { - mContext = context; - } - public boolean isAvailable() { return mIsAvailable.get(); }