• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.connecteddevice;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 import android.provider.SearchIndexableResource;
22 import android.support.annotation.VisibleForTesting;
23 
24 import com.android.internal.logging.nano.MetricsProto;
25 import com.android.settings.R;
26 import com.android.settings.SettingsActivity;
27 import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
28 import com.android.settings.bluetooth.Utils;
29 import com.android.settings.dashboard.DashboardFragment;
30 import com.android.settings.dashboard.SummaryLoader;
31 import com.android.settings.deviceinfo.UsbBackend;
32 import com.android.settings.nfc.NfcPreferenceController;
33 import com.android.settings.overlay.FeatureFactory;
34 import com.android.settings.search.BaseSearchIndexProvider;
35 import com.android.settings.search.Indexable;
36 import com.android.settingslib.core.AbstractPreferenceController;
37 import com.android.settingslib.core.lifecycle.Lifecycle;
38 
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.List;
42 
43 public class ConnectedDeviceDashboardFragment extends DashboardFragment {
44 
45     private static final String TAG = "ConnectedDeviceFrag";
46     private UsbModePreferenceController mUsbPrefController;
47 
48     @Override
getMetricsCategory()49     public int getMetricsCategory() {
50         return MetricsProto.MetricsEvent.SETTINGS_CONNECTED_DEVICE_CATEGORY;
51     }
52 
53     @Override
getLogTag()54     protected String getLogTag() {
55         return TAG;
56     }
57 
58     @Override
getHelpResource()59     protected int getHelpResource() {
60         return R.string.help_url_connected_devices;
61     }
62 
63     @Override
getPreferenceScreenResId()64     protected int getPreferenceScreenResId() {
65         return R.xml.connected_devices;
66     }
67 
68     @Override
getPreferenceControllers(Context context)69     protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
70         final List<AbstractPreferenceController> controllers = new ArrayList<>();
71         final Lifecycle lifecycle = getLifecycle();
72         final NfcPreferenceController nfcPreferenceController =
73                 new NfcPreferenceController(context);
74         lifecycle.addObserver(nfcPreferenceController);
75         controllers.add(nfcPreferenceController);
76         mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context));
77         lifecycle.addObserver(mUsbPrefController);
78         controllers.add(mUsbPrefController);
79         final BluetoothMasterSwitchPreferenceController bluetoothPreferenceController =
80                 new BluetoothMasterSwitchPreferenceController(
81                         context, Utils.getLocalBtManager(context), this,
82                         (SettingsActivity) getActivity());
83         lifecycle.addObserver(bluetoothPreferenceController);
84         controllers.add(bluetoothPreferenceController);
85 
86         SmsMirroringFeatureProvider smsMirroringFeatureProvider =
87                 FeatureFactory.getFactory(context).getSmsMirroringFeatureProvider();
88         AbstractPreferenceController smsMirroringController =
89                 smsMirroringFeatureProvider.getController(context);
90         controllers.add(smsMirroringController);
91         return controllers;
92     }
93 
94     @VisibleForTesting
95     static class SummaryProvider implements SummaryLoader.SummaryProvider {
96 
97         private final Context mContext;
98         private final SummaryLoader mSummaryLoader;
99         private final NfcPreferenceController mNfcPreferenceController;
100 
SummaryProvider(Context context, SummaryLoader summaryLoader)101         public SummaryProvider(Context context, SummaryLoader summaryLoader) {
102             mContext = context;
103             mSummaryLoader = summaryLoader;
104             mNfcPreferenceController = new NfcPreferenceController(context);
105         }
106 
107 
108         @Override
setListening(boolean listening)109         public void setListening(boolean listening) {
110             if (listening) {
111                 if (mNfcPreferenceController.isAvailable()) {
112                     mSummaryLoader.setSummary(this,
113                             mContext.getString(R.string.connected_devices_dashboard_summary));
114                 } else {
115                     mSummaryLoader.setSummary(this, mContext.getString(
116                             R.string.connected_devices_dashboard_no_nfc_summary));
117                 }
118             }
119         }
120     }
121 
122     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
123             = new SummaryLoader.SummaryProviderFactory() {
124         @Override
125         public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
126                 SummaryLoader summaryLoader) {
127             return new SummaryProvider(activity, summaryLoader);
128         }
129     };
130 
131     /**
132      * For Search.
133      */
134     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
135             new BaseSearchIndexProvider() {
136                 @Override
137                 public List<SearchIndexableResource> getXmlResourcesToIndex(
138                         Context context, boolean enabled) {
139                     final SearchIndexableResource sir = new SearchIndexableResource(context);
140                     sir.xmlResId = R.xml.connected_devices;
141                     return Arrays.asList(sir);
142                 }
143 
144                 @Override
145                 public List<String> getNonIndexableKeys(Context context) {
146                     final List<String> keys = super.getNonIndexableKeys(context);
147                     PackageManager pm = context.getPackageManager();
148                     if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
149                         keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
150                         keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
151                     }
152                     keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
153 
154                     SmsMirroringFeatureProvider smsMirroringFeatureProvider =
155                             FeatureFactory.getFactory(context).getSmsMirroringFeatureProvider();
156                     SmsMirroringPreferenceController smsMirroringController =
157                             smsMirroringFeatureProvider.getController(context);
158                     smsMirroringController.updateNonIndexableKeys(keys);
159 
160                     return keys;
161                 }
162             };
163 }
164