Merge "Restore preferred activity filter if it not inside" am: d8c6106f91 am: d45305b25c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1483964 Change-Id: I62a1c68a761d515c7cbccc3868bf91def5fb9d7c
This commit is contained in:
@@ -254,6 +254,43 @@ public class PreferredComponent {
|
|||||||
return numMatch == NS;
|
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) {
|
public boolean isSuperset(List<ResolveInfo> query, boolean excludeSetupWizardPackage) {
|
||||||
if (mSetPackages == null) {
|
if (mSetPackages == null) {
|
||||||
return query == null;
|
return query == null;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.content.IntentFilter;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import com.android.server.IntentResolver;
|
import com.android.server.IntentResolver;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class PreferredIntentResolver
|
public class PreferredIntentResolver
|
||||||
extends IntentResolver<PreferredActivity, PreferredActivity> {
|
extends IntentResolver<PreferredActivity, PreferredActivity> {
|
||||||
@@ -45,4 +46,24 @@ public class PreferredIntentResolver
|
|||||||
protected IntentFilter getIntentFilter(@NonNull PreferredActivity input) {
|
protected IntentFilter getIntentFilter(@NonNull PreferredActivity input) {
|
||||||
return 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);
|
PreferredActivity pa = new PreferredActivity(parser);
|
||||||
if (pa.mPref.getParseError() == null) {
|
if (pa.mPref.getParseError() == null) {
|
||||||
final PreferredIntentResolver resolver = editPreferredActivitiesLPw(userId);
|
final PreferredIntentResolver resolver = editPreferredActivitiesLPw(userId);
|
||||||
ArrayList<PreferredActivity> pal = resolver.findFilters(pa);
|
if (resolver.shouldAddPreferredActivity(pa)) {
|
||||||
if (pal == null || pal.size() == 0 || pa.mPref.mAlways) {
|
|
||||||
resolver.addFilter(pa);
|
resolver.addFilter(pa);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user