• 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 static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
19 
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.net.Uri;
23 import android.provider.DeviceConfig;
24 import android.text.TextUtils;
25 import android.util.Log;
26 
27 import androidx.annotation.VisibleForTesting;
28 
29 import com.android.settings.R;
30 import com.android.settings.SettingsActivity;
31 import com.android.settings.Utils;
32 import com.android.settings.core.SettingsUIDeviceConfig;
33 import com.android.settings.dashboard.DashboardFragment;
34 import com.android.settings.search.BaseSearchIndexProvider;
35 import com.android.settings.slices.SlicePreferenceController;
36 import com.android.settingslib.search.SearchIndexable;
37 
38 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
39 public class ConnectedDeviceDashboardFragment extends DashboardFragment {
40 
41     private static final String TAG = "ConnectedDeviceFrag";
42     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
43     private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE";
44 
45     @VisibleForTesting
46     static final String KEY_CONNECTED_DEVICES = "connected_device_list";
47     @VisibleForTesting
48     static final String KEY_AVAILABLE_DEVICES = "available_device_list";
49 
50     @Override
getMetricsCategory()51     public int getMetricsCategory() {
52         return SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY;
53     }
54 
55     @Override
getLogTag()56     protected String getLogTag() {
57         return TAG;
58     }
59 
60     @Override
getHelpResource()61     public int getHelpResource() {
62         return R.string.help_url_connected_devices;
63     }
64 
65     @Override
getPreferenceScreenResId()66     protected int getPreferenceScreenResId() {
67         return R.xml.connected_devices;
68     }
69 
70     @Override
onAttach(Context context)71     public void onAttach(Context context) {
72         super.onAttach(context);
73         final boolean nearbyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
74                 SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true);
75         String callingAppPackageName = ((SettingsActivity) getActivity())
76                 .getInitialCallingPackage();
77         String action = getIntent() != null ? getIntent().getAction() : "";
78         if (DEBUG) {
79             Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName
80                     + ", action : " + action);
81         }
82         use(AvailableMediaDeviceGroupController.class).init(this);
83         use(ConnectedDeviceGroupController.class).init(this);
84         use(PreviouslyConnectedDevicePreferenceController.class).init(this);
85         use(SlicePreferenceController.class).setSliceUri(nearbyEnabled
86                 ? Uri.parse(getString(R.string.config_nearby_devices_slice_uri))
87                 : null);
88         use(DiscoverableFooterPreferenceController.class)
89                 .setAlwaysDiscoverable(isAlwaysDiscoverable(callingAppPackageName, action));
90     }
91 
92     @VisibleForTesting
isAlwaysDiscoverable(String callingAppPackageName, String action)93     boolean isAlwaysDiscoverable(String callingAppPackageName, String action) {
94         return TextUtils.equals(SLICE_ACTION, action) ? false
95                 : TextUtils.equals(Utils.SETTINGS_PACKAGE_NAME, callingAppPackageName)
96                 || TextUtils.equals(Utils.SYSTEMUI_PACKAGE_NAME, callingAppPackageName);
97     }
98 
99     /**
100      * For Search.
101      */
102     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
103             new BaseSearchIndexProvider(R.xml.connected_devices);
104 }
105