Bug 881861 - Listen to package removed notifications in the quick share menu. r=mfinkle

This commit is contained in:
Wes Johnston 2014-01-30 12:47:57 -08:00
parent 0f4ec447f4
commit 41212e337e

View File

@ -20,9 +20,11 @@
//package android.widget;
package org.mozilla.gecko.widget;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.database.DataSetObservable;
import android.os.AsyncTask;
@ -47,6 +49,7 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -253,9 +256,9 @@ public class ActivityChooserModel extends DataSetObservable {
* Monitor for added and removed packages.
*/
/**
* Mozilla: Not needed for the application.
* Mozilla: Converted from a PackageMonitor to a DataModelPackageMonitor to avoid importing a new class.
*/
//private final PackageMonitor mPackageMonitor = new DataModelPackageMonitor();
private final DataModelPackageMonitor mPackageMonitor = new DataModelPackageMonitor();
/**
* Context for accessing resources.
@ -372,9 +375,9 @@ public class ActivityChooserModel extends DataSetObservable {
}
/**
* Mozilla: Not needed for the application.
* Mozilla: Uses modified receiver
*/
//mPackageMonitor.register(mContext, null, true);
mPackageMonitor.register(mContext);
}
/**
@ -506,7 +509,7 @@ public class ActivityChooserModel extends DataSetObservable {
HistoricalRecord historicalRecord = new HistoricalRecord(chosenName,
System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT);
addHisoricalRecord(historicalRecord);
addHistoricalRecord(historicalRecord);
return choiceIntent;
}
@ -573,7 +576,7 @@ public class ActivityChooserModel extends DataSetObservable {
newDefaultActivity.resolveInfo.activityInfo.name);
HistoricalRecord historicalRecord = new HistoricalRecord(defaultName,
System.currentTimeMillis(), weight);
addHisoricalRecord(historicalRecord);
addHistoricalRecord(historicalRecord);
}
}
@ -689,7 +692,7 @@ public class ActivityChooserModel extends DataSetObservable {
/**
* Mozilla: Not needed for the application.
*/
//mPackageMonitor.unregister();
mPackageMonitor.unregister();
}
/**
@ -771,7 +774,7 @@ public class ActivityChooserModel extends DataSetObservable {
* @param historicalRecord The record to add.
* @return True if the record was added.
*/
private boolean addHisoricalRecord(HistoricalRecord historicalRecord) {
private boolean addHistoricalRecord(HistoricalRecord historicalRecord) {
final boolean added = mHistoricalRecords.add(historicalRecord);
if (added) {
mHistoricalRecordsChanged = true;
@ -783,6 +786,33 @@ public class ActivityChooserModel extends DataSetObservable {
return added;
}
/**
* Removes all historical records for this pkg.
*
* @param historicalRecord The pkg to delete records for.
* @return True if the record was added.
*/
private boolean removeHistoricalRecordsForPackage(final String pkg) {
boolean removed = false;
for (Iterator<HistoricalRecord> i = mHistoricalRecords.iterator(); i.hasNext();) {
final HistoricalRecord record = i.next();
if (record.activity.getPackageName().equals(pkg)) {
removed = mHistoricalRecords.remove(record);
}
}
if (removed) {
mHistoricalRecordsChanged = true;
pruneExcessiveHistoricalRecordsIfNeeded();
persistHistoricalDataIfNeeded();
sortActivitiesIfNeeded();
notifyChanged();
}
return removed;
}
/**
* Prunes older excessive records to guarantee maxHistorySize.
*/
@ -1151,16 +1181,45 @@ public class ActivityChooserModel extends DataSetObservable {
* Keeps in sync the historical records and activities with the installed applications.
*/
/**
* Mozilla: Not needed for the application.
* Mozilla: Adapted significantly
*/
/*
private final class DataModelPackageMonitor extends PackageMonitor {
private static final String LOGTAG = "GeckoActivityChooserModel";
private final class DataModelPackageMonitor extends BroadcastReceiver {
private Context mContext;
public DataModelPackageMonitor() { }
public void register(Context context) {
mContext = context;
String[] intents = new String[] {
Intent.ACTION_PACKAGE_REMOVED,
Intent.ACTION_PACKAGE_ADDED,
Intent.ACTION_PACKAGE_CHANGED
};
for (String intent : intents) {
IntentFilter removeFilter = new IntentFilter(intent);
removeFilter.addDataScheme("package");
context.registerReceiver(this, removeFilter);
}
}
public void unregister() {
mContext.unregisterReceiver(this);
mContext = null;
}
@Override
public void onSomePackagesChanged() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
String packageName = intent.getData().getSchemeSpecificPart();
removeHistoricalRecordsForPackage(packageName);
}
mReloadActivities = true;
}
}
*/
}