Merge "Restore preferred activity filter if it not inside"
This commit is contained in:
@@ -254,6 +254,43 @@ public class PreferredComponent {
|
||||
return numMatch == NS;
|
||||
}
|
||||
|
||||
public boolean sameSet(PreferredComponent pc) {
|
||||
if (mSetPackages == null || pc == null || pc.mSetPackages == null
|
||||
|| !sameComponent(pc.mComponent)) {
|
||||
return false;
|
||||
}
|
||||
final int otherPackageCount = pc.mSetPackages.length;
|
||||
final int packageCount = mSetPackages.length;
|
||||
int numMatch = 0;
|
||||
for (int i = 0; i < otherPackageCount; i++) {
|
||||
boolean good = false;
|
||||
for (int j = 0; j < packageCount; j++) {
|
||||
if (mSetPackages[j].equals(pc.mSetPackages[j])
|
||||
&& mSetClasses[j].equals(pc.mSetClasses[j])) {
|
||||
numMatch++;
|
||||
good = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!good) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return numMatch == packageCount;
|
||||
}
|
||||
|
||||
/** Returns true if the preferred component represents the provided ComponentName. */
|
||||
private boolean sameComponent(ComponentName comp) {
|
||||
if (mComponent == null || comp == null) {
|
||||
return false;
|
||||
}
|
||||
if (mComponent.getPackageName().equals(comp.getPackageName())
|
||||
&& mComponent.getClassName().equals(comp.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSuperset(List<ResolveInfo> query, boolean excludeSetupWizardPackage) {
|
||||
if (mSetPackages == null) {
|
||||
return query == null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.IntentFilter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import com.android.server.IntentResolver;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PreferredIntentResolver
|
||||
extends IntentResolver<PreferredActivity, PreferredActivity> {
|
||||
@@ -45,4 +46,24 @@ public class PreferredIntentResolver
|
||||
protected IntentFilter getIntentFilter(@NonNull PreferredActivity input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
public boolean shouldAddPreferredActivity(PreferredActivity pa) {
|
||||
ArrayList<PreferredActivity> pal = findFilters(pa);
|
||||
if (pal == null || pal.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (!pa.mPref.mAlways) {
|
||||
return false;
|
||||
}
|
||||
final int activityCount = pal.size();
|
||||
for (int i = 0; i < activityCount; i++) {
|
||||
PreferredActivity cur = pal.get(i);
|
||||
if (cur.mPref.mAlways
|
||||
&& cur.mPref.mMatch == (pa.mPref.mMatch & IntentFilter.MATCH_CATEGORY_MASK)
|
||||
&& cur.mPref.sameSet(pa.mPref)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1410,8 +1410,7 @@ public final class Settings {
|
||||
PreferredActivity pa = new PreferredActivity(parser);
|
||||
if (pa.mPref.getParseError() == null) {
|
||||
final PreferredIntentResolver resolver = editPreferredActivitiesLPw(userId);
|
||||
ArrayList<PreferredActivity> pal = resolver.findFilters(pa);
|
||||
if (pal == null || pal.size() == 0 || pa.mPref.mAlways) {
|
||||
if (resolver.shouldAddPreferredActivity(pa)) {
|
||||
resolver.addFilter(pa);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user