Files
packages_apps_Settings/src/com/android/settings/applications/defaultapps/DefaultBrowserPicker.java
Doris Ling 688d1d81cb Only add entry with unique package name to default browser list.
When we query the package manager for activities that can handle the
web data uri, different capable activities within the same package will
be returned as separate entries. However, when we show the default
browser apps to the user, the entries are simply base on package name.
So, if there are multiple activities within the same package that can
handle the web data, they will be shown as duplicate entries.

When we process the resolved activities, check the corresponding package
name for duplicate entries before adding it to the default browser list.

Change-Id: I4e1f1e1ea22781efe24d791b367246423ca7a3c4
Merged-In: I70c88866eb3d5fe6466554749e23c85f429dd30c
Fixes: 84207432
Test: make RunSettingsRoboTests
2018-06-05 17:48:30 -07:00

90 lines
2.9 KiB
Java

/*
* Copyright (C) 2017 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.settings.applications.defaultapps;
import android.content.Context;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.ArraySet;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settingslib.applications.DefaultAppInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Fragment for choosing default browser.
*/
public class DefaultBrowserPicker extends DefaultAppPickerFragment {
@Override
protected int getPreferenceScreenResId() {
return R.xml.default_browser_settings;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DEFAULT_BROWSER_PICKER;
}
@Override
protected String getDefaultKey() {
return mPm.getDefaultBrowserPackageNameAsUser(mUserId);
}
@Override
protected boolean setDefaultKey(String packageName) {
return mPm.setDefaultBrowserPackageNameAsUser(packageName, mUserId);
}
@Override
protected List<DefaultAppInfo> getCandidates() {
final List<DefaultAppInfo> candidates = new ArrayList<>();
final Context context = getContext();
// Resolve that intent and check that the handleAllWebDataURI boolean is set
final List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(
DefaultBrowserPreferenceController.BROWSE_PROBE, PackageManager.MATCH_ALL, mUserId);
final int count = list.size();
final Set<String> addedPackages = new ArraySet<>();
for (int i = 0; i < count; i++) {
ResolveInfo info = list.get(i);
if (info.activityInfo == null || !info.handleAllWebDataURI) {
continue;
}
final String packageName = info.activityInfo.packageName;
if (addedPackages.contains(packageName)) {
continue;
}
try {
candidates.add(new DefaultAppInfo(context, mPm,
mPm.getApplicationInfoAsUser(packageName, 0, mUserId)));
addedPackages.add(packageName);
} catch (PackageManager.NameNotFoundException e) {
// Skip unknown packages.
}
}
return candidates;
}
}