DefaultBrowserPicker.java revision 03a3b518debfb3870d780a6e29c8f115013cd866
1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17package com.android.settings.applications.defaultapps; 18 19import android.content.Context; 20import android.content.pm.PackageManager; 21import android.content.pm.ResolveInfo; 22 23import com.android.internal.logging.nano.MetricsProto; 24import com.android.settings.R; 25 26import java.util.ArrayList; 27import java.util.List; 28 29/** 30 * Fragment for choosing default browser. 31 */ 32public class DefaultBrowserPicker extends DefaultAppPickerFragment { 33 34 @Override 35 protected int getPreferenceScreenResId() { 36 return R.xml.default_browser_settings; 37 } 38 39 @Override 40 public int getMetricsCategory() { 41 return MetricsProto.MetricsEvent.DEFAULT_BROWSER_PICKER; 42 } 43 44 @Override 45 protected String getDefaultKey() { 46 return mPm.getDefaultBrowserPackageNameAsUser(mUserId); 47 } 48 49 @Override 50 protected boolean setDefaultKey(String packageName) { 51 return mPm.setDefaultBrowserPackageNameAsUser(packageName, mUserId); 52 } 53 54 @Override 55 protected List<DefaultAppInfo> getCandidates() { 56 final List<DefaultAppInfo> candidates = new ArrayList<>(); 57 final Context context = getContext(); 58 // Resolve that intent and check that the handleAllWebDataURI boolean is set 59 final List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser( 60 DefaultBrowserPreferenceController.BROWSE_PROBE, PackageManager.MATCH_ALL, mUserId); 61 62 final int count = list.size(); 63 for (int i = 0; i < count; i++) { 64 ResolveInfo info = list.get(i); 65 if (info.activityInfo == null || !info.handleAllWebDataURI) { 66 continue; 67 } 68 try { 69 candidates.add(new DefaultAppInfo(context, mPm, 70 mPm.getApplicationInfoAsUser(info.activityInfo.packageName, 0, mUserId))); 71 } catch (PackageManager.NameNotFoundException e) { 72 // Skip unknown packages. 73 } 74 } 75 76 return candidates; 77 } 78} 79