DefaultBrowserPicker.java revision efa763624a86f77c99b5cac53d8cf81e474ffc4b
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; 24 25import java.util.ArrayList; 26import java.util.List; 27 28/** 29 * Fragment for choosing default browser. 30 */ 31public class DefaultBrowserPicker extends DefaultAppPickerFragment { 32 33 @Override 34 public int getMetricsCategory() { 35 return MetricsProto.MetricsEvent.DEFAULT_BROWSER_PICKER; 36 } 37 38 @Override 39 protected String getDefaultKey() { 40 return mPm.getDefaultBrowserPackageNameAsUser(mUserId); 41 } 42 43 @Override 44 protected boolean setDefaultKey(String packageName) { 45 return mPm.setDefaultBrowserPackageNameAsUser(packageName, mUserId); 46 } 47 48 @Override 49 protected List<DefaultAppInfo> getCandidates() { 50 final List<DefaultAppInfo> candidates = new ArrayList<>(); 51 final Context context = getContext(); 52 // Resolve that intent and check that the handleAllWebDataURI boolean is set 53 final List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser( 54 DefaultBrowserPreferenceController.BROWSE_PROBE, PackageManager.MATCH_ALL, mUserId); 55 56 final int count = list.size(); 57 for (int i = 0; i < count; i++) { 58 ResolveInfo info = list.get(i); 59 if (info.activityInfo == null || !info.handleAllWebDataURI) { 60 continue; 61 } 62 try { 63 candidates.add(new DefaultAppInfo(context, mPm, 64 mPm.getApplicationInfoAsUser(info.activityInfo.packageName, 0, mUserId))); 65 } catch (PackageManager.NameNotFoundException e) { 66 // Skip unknown packages. 67 } 68 } 69 70 return candidates; 71 } 72} 73