• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.settings.applications;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.provider.SearchIndexableResource;
21 import android.text.TextUtils;
22 
23 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
24 import com.android.settings.R;
25 import com.android.settings.applications.assist.DefaultAssistPreferenceController;
26 import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
27 import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
28 import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
29 import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
30 import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
31 import com.android.settings.applications.defaultapps.DefaultWorkBrowserPreferenceController;
32 import com.android.settings.applications.defaultapps.DefaultWorkPhonePreferenceController;
33 import com.android.settings.applications.defaultapps.DefaultPaymentSettingsPreferenceController;
34 import com.android.settings.dashboard.DashboardFragment;
35 import com.android.settings.dashboard.SummaryLoader;
36 import com.android.settings.search.BaseSearchIndexProvider;
37 import com.android.settings.search.Indexable;
38 import com.android.settingslib.core.AbstractPreferenceController;
39 
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.List;
43 
44 public class DefaultAppSettings extends DashboardFragment {
45 
46     static final String TAG = "DefaultAppSettings";
47 
48     private static final String KEY_ASSIST_VOICE_INPUT = "assist_and_voice_input";
49 
50     @Override
getLogTag()51     protected String getLogTag() {
52         return TAG;
53     }
54 
55     @Override
getPreferenceScreenResId()56     protected int getPreferenceScreenResId() {
57         return R.xml.app_default_settings;
58     }
59 
60     @Override
getPreferenceControllers(Context context)61     protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
62         return buildPreferenceControllers(context);
63     }
64 
65     @Override
getMetricsCategory()66     public int getMetricsCategory() {
67         return MetricsEvent.APPLICATIONS_ADVANCED;
68     }
69 
buildPreferenceControllers(Context context)70     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
71         final List<AbstractPreferenceController> controllers = new ArrayList<>();
72         controllers.add(new DefaultAssistPreferenceController(context, KEY_ASSIST_VOICE_INPUT,
73                 false /* showSetting */));
74         controllers.add(new DefaultBrowserPreferenceController(context));
75         controllers.add(new DefaultWorkBrowserPreferenceController(context));
76         controllers.add(new DefaultPhonePreferenceController(context));
77         controllers.add(new DefaultWorkPhonePreferenceController(context));
78         controllers.add(new DefaultSmsPreferenceController(context));
79         controllers.add(new DefaultEmergencyPreferenceController(context));
80         controllers.add(new DefaultHomePreferenceController(context));
81         controllers.add(new DefaultPaymentSettingsPreferenceController(context));
82         return controllers;
83     }
84 
85     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
86             new BaseSearchIndexProvider() {
87                 @Override
88                 public List<SearchIndexableResource> getXmlResourcesToIndex(
89                         Context context, boolean enabled) {
90                     final SearchIndexableResource sir = new SearchIndexableResource(context);
91                     sir.xmlResId = R.xml.app_default_settings;
92                     return Arrays.asList(sir);
93                 }
94 
95                 @Override
96                 public List<String> getNonIndexableKeys(Context context) {
97                     List<String> keys = super.getNonIndexableKeys(context);
98                     keys.add(KEY_ASSIST_VOICE_INPUT);
99                     // TODO (b/38230148) Remove these keys when we can differentiate work results
100                     keys.add((new DefaultWorkPhonePreferenceController(context))
101                             .getPreferenceKey());
102                     keys.add((new DefaultWorkBrowserPreferenceController(context))
103                             .getPreferenceKey());
104                     return keys;
105                 }
106 
107                 @Override
108                 public List<AbstractPreferenceController> getPreferenceControllers(
109                         Context context) {
110                     return buildPreferenceControllers(context);
111                 }
112             };
113 
114     static class SummaryProvider implements SummaryLoader.SummaryProvider {
115 
116         private final Context mContext;
117         private final SummaryLoader mSummaryLoader;
118         private final DefaultSmsPreferenceController mDefaultSmsPreferenceController;
119         private final DefaultBrowserPreferenceController mDefaultBrowserPreferenceController;
120         private final DefaultPhonePreferenceController mDefaultPhonePreferenceController;
121 
SummaryProvider(Context context, SummaryLoader summaryLoader)122         public SummaryProvider(Context context, SummaryLoader summaryLoader) {
123             mContext = context;
124             mSummaryLoader = summaryLoader;
125             mDefaultSmsPreferenceController = new DefaultSmsPreferenceController(mContext);
126             mDefaultBrowserPreferenceController = new DefaultBrowserPreferenceController(mContext);
127             mDefaultPhonePreferenceController = new DefaultPhonePreferenceController(mContext);
128         }
129 
130         @Override
setListening(boolean listening)131         public void setListening(boolean listening) {
132             if (!listening) {
133                 return;
134             }
135             CharSequence summary = concatSummaryText(
136                     mDefaultSmsPreferenceController.getDefaultAppLabel(),
137                     mDefaultBrowserPreferenceController.getDefaultAppLabel());
138             summary = concatSummaryText(summary,
139                     mDefaultPhonePreferenceController.getDefaultAppLabel());
140             if (!TextUtils.isEmpty(summary)) {
141                 mSummaryLoader.setSummary(this, summary);
142             }
143         }
144 
concatSummaryText(CharSequence summary1, CharSequence summary2)145         private CharSequence concatSummaryText(CharSequence summary1, CharSequence summary2) {
146             if (TextUtils.isEmpty(summary1)) {
147                 return summary2;
148             }
149             if (TextUtils.isEmpty(summary2)) {
150                 return summary1;
151             }
152             return mContext.getString(R.string.join_many_items_middle, summary1, summary2);
153         }
154     }
155 
156     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
157             new SummaryLoader.SummaryProviderFactory() {
158                 @Override
159                 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
160                         SummaryLoader summaryLoader) {
161                     return new DefaultAppSettings.SummaryProvider(activity, summaryLoader);
162                 }
163             };
164 }
165