Merge "Don't declare package-listener in Manifest but instead in code."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e6e0337..722fc46 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -409,26 +409,6 @@
</intent-filter>
</activity>
- <!-- Flushes the QuickContact IntentCache -->
- <receiver android:name=".quickcontact.PackageIntentReceiver">
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_ADDED" />
- <data android:scheme="package" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_REPLACED" />
- <data android:scheme="package" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_REMOVED" />
- <data android:scheme="package" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_CHANGED" />
- <data android:scheme="package" />
- </intent-filter>
- </receiver>
-
<activity-alias android:name="ContactShortcut"
android:targetActivity=".activities.ContactSelectionActivity"
android:label="@string/shortcutContact"
diff --git a/src/com/android/contacts/quickcontact/PackageIntentReceiver.java b/src/com/android/contacts/quickcontact/PackageIntentReceiver.java
deleted file mode 100644
index 7af4005..0000000
--- a/src/com/android/contacts/quickcontact/PackageIntentReceiver.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.contacts.quickcontact;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-/**
- * Package intent receiver that flushes the {@link ResolveCache} so that Packages are rescanned next
- * time
- */
-public class PackageIntentReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- ResolveCache.flush();
- }
-}
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 0588c7d..2c62fe4 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -18,7 +18,6 @@
import com.android.contacts.Collapser;
import com.android.contacts.ContactPhotoManager;
-import com.android.contacts.ContactPresenceIconUtil;
import com.android.contacts.R;
import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.model.DataKind;
diff --git a/src/com/android/contacts/quickcontact/ResolveCache.java b/src/com/android/contacts/quickcontact/ResolveCache.java
index 08a6cf8..aae2ee7 100644
--- a/src/com/android/contacts/quickcontact/ResolveCache.java
+++ b/src/com/android/contacts/quickcontact/ResolveCache.java
@@ -19,6 +19,7 @@
import com.android.contacts.util.PhoneCapabilityTester;
import com.google.android.collect.Sets;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -65,16 +66,35 @@
*/
public synchronized static ResolveCache getInstance(Context context) {
if (sInstance == null) {
- return sInstance = new ResolveCache(context.getApplicationContext());
+ final Context applicationContext = context.getApplicationContext();
+ sInstance = new ResolveCache(applicationContext);
+
+ // Register for package-changes so that we can flush our cache
+ final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+ filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ filter.addDataScheme("package");
+ applicationContext.registerReceiver(sInstance.mPackageIntentReceiver, filter);
}
return sInstance;
}
- public synchronized static void flush() {
+ private synchronized static void flush() {
sInstance = null;
}
/**
+ * Called anytime a package is installed, uninstalled etc, so that we can wipe our cache
+ */
+ private BroadcastReceiver mPackageIntentReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ flush();
+ }
+ };
+
+ /**
* Cached entry holding the best {@link ResolveInfo} for a specific
* MIME-type, along with a {@link SoftReference} to its icon.
*/