Fix incorrect default browser summary.
- move the logic to retrieve browser candidates with unique package name from default browser picker to the controller, so that both uses the same logic to get the candidate list. When there is only 1 package that can handle the web but it has multiple resolved activities, it should be considered as the only app, and hence be set as default. Change-Id: I945bcef3f7de586b19f65ceada3abf7addb0b26e Fixes: 109882811 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -26,12 +26,15 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import androidx.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultBrowserPreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
@@ -48,7 +51,7 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
final List<ResolveInfo> candidates = getCandidates();
|
||||
final List<ResolveInfo> candidates = getCandidates(mPackageManager, mUserId);
|
||||
return candidates != null && !candidates.isEmpty();
|
||||
}
|
||||
|
||||
@@ -103,14 +106,31 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
return getOnlyAppIcon();
|
||||
}
|
||||
|
||||
private List<ResolveInfo> getCandidates() {
|
||||
return mPackageManager.queryIntentActivitiesAsUser(BROWSE_PROBE, PackageManager.MATCH_ALL,
|
||||
mUserId);
|
||||
static List<ResolveInfo> getCandidates(PackageManager packageManager, int userId) {
|
||||
final List<ResolveInfo> candidates = new ArrayList<>();
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
final List<ResolveInfo> list = packageManager.queryIntentActivitiesAsUser(
|
||||
BROWSE_PROBE, PackageManager.MATCH_ALL, userId);
|
||||
if (list != null) {
|
||||
final Set<String> addedPackages = new ArraySet<>();
|
||||
for (ResolveInfo info : list) {
|
||||
if (info.activityInfo == null || !info.handleAllWebDataURI) {
|
||||
continue;
|
||||
}
|
||||
final String packageName = info.activityInfo.packageName;
|
||||
if (addedPackages.contains(packageName)) {
|
||||
continue;
|
||||
}
|
||||
candidates.add(info);
|
||||
addedPackages.add(packageName);
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
private String getOnlyAppLabel() {
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
final List<ResolveInfo> list = getCandidates();
|
||||
final List<ResolveInfo> list = getCandidates(mPackageManager, mUserId);
|
||||
if (list != null && list.size() == 1) {
|
||||
final ResolveInfo info = list.get(0);
|
||||
final String label = info.loadLabel(mPackageManager).toString();
|
||||
@@ -123,7 +143,7 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
}
|
||||
|
||||
private Drawable getOnlyAppIcon() {
|
||||
final List<ResolveInfo> list = getCandidates();
|
||||
final List<ResolveInfo> list = getCandidates(mPackageManager, mUserId);
|
||||
if (list != null && list.size() == 1) {
|
||||
final ResolveInfo info = list.get(0);
|
||||
final ComponentInfo cn = info.getComponentInfo();
|
||||
|
Reference in New Issue
Block a user