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