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