2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.applications.defaultapps;
19 import android.content.Context;
20 import android.content.pm.ComponentInfo;
21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
24 import android.util.ArraySet;
25 import com.android.internal.logging.nano.MetricsProto;
26 import com.android.settings.R;
28 import com.android.settingslib.applications.DefaultAppInfo;
30 import java.util.ArrayList;
31 import java.util.List;
35 * Fragment for choosing default browser.
37 public class DefaultBrowserPicker extends DefaultAppPickerFragment {
40 protected int getPreferenceScreenResId() {
41 return R.xml.default_browser_settings;
45 public int getMetricsCategory() {
46 return MetricsProto.MetricsEvent.DEFAULT_BROWSER_PICKER;
50 protected String getDefaultKey() {
51 return mPm.getDefaultBrowserPackageNameAsUser(mUserId);
55 protected boolean setDefaultKey(String packageName) {
56 return mPm.setDefaultBrowserPackageNameAsUser(packageName, mUserId);
60 protected List<DefaultAppInfo> getCandidates() {
61 final List<DefaultAppInfo> candidates = new ArrayList<>();
62 final Context context = getContext();
63 // Resolve that intent and check that the handleAllWebDataURI boolean is set
64 final List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(
65 DefaultBrowserPreferenceController.BROWSE_PROBE, PackageManager.MATCH_ALL, mUserId);
67 final int count = list.size();
68 final Set<String> addedPackages = new ArraySet<>();
69 for (int i = 0; i < count; i++) {
70 ResolveInfo info = list.get(i);
71 if (info.activityInfo == null || !info.handleAllWebDataURI) {
74 final String packageName = info.activityInfo.packageName;
75 if (addedPackages.contains(packageName)) {
79 candidates.add(new DefaultAppInfo(context, mPm,
80 mPm.getApplicationInfoAsUser(packageName, 0, mUserId)));
81 addedPackages.add(packageName);
82 } catch (PackageManager.NameNotFoundException e) {
83 // Skip unknown packages.