• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.slices;
18 
19 import static android.provider.SettingsSlicesContract.KEY_LOCATION;
20 import static android.provider.SettingsSlicesContract.KEY_WIFI;
21 
22 import android.content.ContentResolver;
23 import android.net.Uri;
24 import android.provider.SettingsSlicesContract;
25 import android.util.ArrayMap;
26 
27 import androidx.annotation.VisibleForTesting;
28 
29 import com.android.settings.flashlight.FlashlightSlice;
30 import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
31 import com.android.settings.homepage.contextualcards.deviceinfo.DataUsageSlice;
32 import com.android.settings.homepage.contextualcards.deviceinfo.DeviceInfoSlice;
33 import com.android.settings.homepage.contextualcards.deviceinfo.EmergencyInfoSlice;
34 import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice;
35 import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
36 import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice;
37 import com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice;
38 import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
39 import com.android.settings.homepage.contextualcards.slices.NotificationChannelSlice;
40 import com.android.settings.location.LocationSlice;
41 import com.android.settings.media.MediaOutputIndicatorSlice;
42 import com.android.settings.media.MediaOutputSlice;
43 import com.android.settings.network.telephony.MobileDataSlice;
44 import com.android.settings.notification.ZenModeButtonPreferenceController;
45 import com.android.settings.wifi.calling.WifiCallingSliceHelper;
46 import com.android.settings.wifi.slice.ContextualWifiSlice;
47 import com.android.settings.wifi.slice.WifiSlice;
48 import com.android.settingslib.media.MediaOutputSliceConstants;
49 
50 import java.util.Map;
51 
52 /**
53  * A registry of custom slice Uris.
54  */
55 public class CustomSliceRegistry {
56 
57     /**
58      * Uri for Airplane mode Slice.
59      */
60     public static final Uri AIRPLANE_URI = new Uri.Builder()
61             .scheme(ContentResolver.SCHEME_CONTENT)
62             .authority(SettingsSlicesContract.AUTHORITY)
63             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
64             .appendPath(SettingsSlicesContract.KEY_AIRPLANE_MODE)
65             .build();
66 
67     /**
68      * Uri for Battery Fix Slice.
69      */
70     public static final Uri BATTERY_FIX_SLICE_URI = new Uri.Builder()
71             .scheme(ContentResolver.SCHEME_CONTENT)
72             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
73             .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT)
74             .appendPath(BatteryTipPreferenceController.PREF_NAME)
75             .build();
76 
77     /**
78      * Backing Uri for the Bluetooth Slice.
79      */
80     public static final Uri BLUETOOTH_URI = new Uri.Builder()
81             .scheme(ContentResolver.SCHEME_CONTENT)
82             .authority(SettingsSlicesContract.AUTHORITY)
83             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
84             .appendPath(SettingsSlicesContract.KEY_BLUETOOTH)
85             .build();
86 
87     /**
88      * Backing Uri for Bluetooth devices Slice.
89      */
90     public static final Uri BLUETOOTH_DEVICES_SLICE_URI = new Uri.Builder()
91             .scheme(ContentResolver.SCHEME_CONTENT)
92             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
93             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
94             .appendPath("bluetooth_devices")
95             .build();
96 
97     /**
98      * Backing Uri for Contextual Notification channel Slice.
99      */
100     public static final Uri CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI = new Uri.Builder()
101             .scheme(ContentResolver.SCHEME_CONTENT)
102             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
103             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
104             .appendPath("contextual_notification_channel")
105             .build();
106 
107     /**
108      * Backing Uri for the Wifi Slice.
109      */
110     public static final Uri CONTEXTUAL_WIFI_SLICE_URI = new Uri.Builder()
111             .scheme(ContentResolver.SCHEME_CONTENT)
112             .authority(SettingsSlicesContract.AUTHORITY)
113             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
114             .appendPath("contextual_wifi")
115             .build();
116 
117     /**
118      * Backing Uri for the Data usage Slice.
119      */
120     public static final Uri DATA_USAGE_SLICE_URI = new Uri.Builder()
121             .scheme(ContentResolver.SCHEME_CONTENT)
122             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
123             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
124             .appendPath("data_usage_card")
125             .build();
126     /**
127      * Backing Uri for the Device info Slice.
128      */
129     public static final Uri DEVICE_INFO_SLICE_URI = new Uri.Builder()
130             .scheme(ContentResolver.SCHEME_CONTENT)
131             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
132             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
133             .appendPath("device_info_card")
134             .build();
135     /**
136      * Backing Uri for the Emergency Info Slice.
137      */
138     public static final Uri EMERGENCY_INFO_SLICE_URI = new Uri.Builder()
139             .scheme(ContentResolver.SCHEME_CONTENT)
140             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
141             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
142             .appendPath("emergency_info_card")
143             .build();
144     /**
145      * Slice Uri for Enhanced 4G slice
146      */
147     public static final Uri ENHANCED_4G_SLICE_URI = new Uri.Builder()
148             .scheme(ContentResolver.SCHEME_CONTENT)
149             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
150             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
151             .appendPath("enhanced_4g_lte")
152             .build();
153     /**
154      * Backing Uri for the Flashlight Slice.
155      */
156     public static final Uri FLASHLIGHT_SLICE_URI = new Uri.Builder()
157             .scheme(ContentResolver.SCHEME_CONTENT)
158             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
159             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
160             .appendPath("flashlight")
161             .build();
162     /**
163      * Backing Uri for the Location Slice.
164      */
165     public static final Uri LOCATION_SLICE_URI = new Uri.Builder()
166             .scheme(ContentResolver.SCHEME_CONTENT)
167             .authority(SettingsSlicesContract.AUTHORITY)
168             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
169             .appendPath(KEY_LOCATION)
170             .build();
171     /**
172      * Backing Uri for Low storage Slice.
173      */
174     public static final Uri LOW_STORAGE_SLICE_URI = new Uri.Builder()
175             .scheme(ContentResolver.SCHEME_CONTENT)
176             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
177             .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT)
178             .appendPath("low_storage")
179             .build();
180     /**
181      * Backing Uri for NFC Slice
182      */
183     public static final Uri NFC_SLICE_URI = new Uri.Builder()
184             .scheme(ContentResolver.SCHEME_CONTENT)
185             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
186             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
187             .appendPath("toggle_nfc")
188             .build();
189 
190     /**
191      * Backing Uri for Mobile Data Slice.
192      */
193     public static final Uri MOBILE_DATA_SLICE_URI = new Uri.Builder()
194             .scheme(ContentResolver.SCHEME_CONTENT)
195             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
196             .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_ACTION)
197             .appendPath("mobile_data")
198             .build();
199     /**
200      * Backing Uri for Notification channel Slice.
201      */
202     public static final Uri NOTIFICATION_CHANNEL_SLICE_URI = new Uri.Builder()
203             .scheme(ContentResolver.SCHEME_CONTENT)
204             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
205             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
206             .appendPath("notification_channel")
207             .build();
208     /**
209      * Backing Uri for the storage slice.
210      */
211     public static final Uri STORAGE_SLICE_URI = new Uri.Builder()
212             .scheme(ContentResolver.SCHEME_CONTENT)
213             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
214             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
215             .appendPath("storage_card")
216             .build();
217     /**
218      * Full {@link Uri} for the Alarm volume Slice.
219      */
220     public static final Uri VOLUME_ALARM_URI = new Uri.Builder()
221             .scheme(ContentResolver.SCHEME_CONTENT)
222             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
223             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
224             .appendPath("alarm_volume")
225             .build();
226     /**
227      * Full {@link Uri} for the Call Volume Slice.
228      */
229     public static final Uri VOLUME_CALL_URI = new Uri.Builder()
230             .scheme(ContentResolver.SCHEME_CONTENT)
231             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
232             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
233             .appendPath("call_volume")
234             .build();
235     /**
236      * Full {@link Uri} for the Media Volume Slice.
237      */
238     public static final Uri VOLUME_MEDIA_URI = new Uri.Builder()
239             .scheme(ContentResolver.SCHEME_CONTENT)
240             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
241             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
242             .appendPath("media_volume")
243             .build();
244 
245     /**
246      * Full {@link Uri} for the Remote Media Volume Slice.
247      */
248     public static final Uri VOLUME_REMOTE_MEDIA_URI = new Uri.Builder()
249             .scheme(ContentResolver.SCHEME_CONTENT)
250             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
251             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
252             .appendPath("remote_volume")
253             .build();
254 
255     /**
256      * Full {@link Uri} for the Ringer volume Slice.
257      */
258     public static final Uri VOLUME_RINGER_URI = new Uri.Builder()
259             .scheme(ContentResolver.SCHEME_CONTENT)
260             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
261             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
262             .appendPath("ring_volume")
263             .build();
264 
265     /**
266      * Full {@link Uri} for the Wifi Calling Slice.
267      */
268     public static final Uri WIFI_CALLING_URI = new Uri.Builder()
269             .scheme(ContentResolver.SCHEME_CONTENT)
270             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
271             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
272             .appendPath(WifiCallingSliceHelper.PATH_WIFI_CALLING)
273             .build();
274     /**
275      * Full {@link Uri} for the Wifi Calling Preference Slice.
276      */
277     public static final Uri WIFI_CALLING_PREFERENCE_URI = new Uri.Builder()
278             .scheme(ContentResolver.SCHEME_CONTENT)
279             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
280             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
281             .appendPath(WifiCallingSliceHelper.PATH_WIFI_CALLING_PREFERENCE)
282             .build();
283     /**
284      * Backing Uri for the Wifi Slice.
285      */
286     public static final Uri WIFI_SLICE_URI = new Uri.Builder()
287             .scheme(ContentResolver.SCHEME_CONTENT)
288             .authority(SettingsSlicesContract.AUTHORITY)
289             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
290             .appendPath(KEY_WIFI)
291             .build();
292 
293     /**
294      * Backing Uri for the Zen Mode Slice.
295      */
296     public static final Uri ZEN_MODE_SLICE_URI = new Uri.Builder()
297             .scheme(ContentResolver.SCHEME_CONTENT)
298             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
299             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
300             .appendPath(ZenModeButtonPreferenceController.KEY)
301             .build();
302 
303     /**
304      * Backing Uri for the Media output Slice.
305      */
306     public static Uri MEDIA_OUTPUT_SLICE_URI = new Uri.Builder()
307             .scheme(ContentResolver.SCHEME_CONTENT)
308             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
309             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
310             .appendPath(MediaOutputSliceConstants.KEY_MEDIA_OUTPUT)
311             .build();
312 
313     /**
314      * Backing Uri for the Media output indicator Slice.
315      */
316     public static Uri MEDIA_OUTPUT_INDICATOR_SLICE_URI = new Uri.Builder()
317             .scheme(ContentResolver.SCHEME_CONTENT)
318             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
319             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
320             .appendPath("media_output_indicator")
321             .build();
322 
323     @VisibleForTesting
324     static final Map<Uri, Class<? extends CustomSliceable>> sUriToSlice;
325 
326     static {
327         sUriToSlice = new ArrayMap<>();
328 
sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class)329         sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class)330         sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
sUriToSlice.put(CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI, ContextualNotificationChannelSlice.class)331         sUriToSlice.put(CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI,
332                 ContextualNotificationChannelSlice.class);
sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class)333         sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class);
sUriToSlice.put(DATA_USAGE_SLICE_URI, DataUsageSlice.class)334         sUriToSlice.put(DATA_USAGE_SLICE_URI, DataUsageSlice.class);
sUriToSlice.put(DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class)335         sUriToSlice.put(DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class);
sUriToSlice.put(EMERGENCY_INFO_SLICE_URI, EmergencyInfoSlice.class)336         sUriToSlice.put(EMERGENCY_INFO_SLICE_URI, EmergencyInfoSlice.class);
sUriToSlice.put(FLASHLIGHT_SLICE_URI, FlashlightSlice.class)337         sUriToSlice.put(FLASHLIGHT_SLICE_URI, FlashlightSlice.class);
sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class)338         sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class);
sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class)339         sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class);
sUriToSlice.put(MOBILE_DATA_SLICE_URI, MobileDataSlice.class)340         sUriToSlice.put(MOBILE_DATA_SLICE_URI, MobileDataSlice.class);
sUriToSlice.put(NOTIFICATION_CHANNEL_SLICE_URI, NotificationChannelSlice.class)341         sUriToSlice.put(NOTIFICATION_CHANNEL_SLICE_URI, NotificationChannelSlice.class);
sUriToSlice.put(STORAGE_SLICE_URI, StorageSlice.class)342         sUriToSlice.put(STORAGE_SLICE_URI, StorageSlice.class);
sUriToSlice.put(WIFI_SLICE_URI, WifiSlice.class)343         sUriToSlice.put(WIFI_SLICE_URI, WifiSlice.class);
sUriToSlice.put(MEDIA_OUTPUT_SLICE_URI, MediaOutputSlice.class)344         sUriToSlice.put(MEDIA_OUTPUT_SLICE_URI, MediaOutputSlice.class);
sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class)345         sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
346     }
347 
getSliceClassByUri(Uri uri)348     public static Class<? extends CustomSliceable> getSliceClassByUri(Uri uri) {
349         return sUriToSlice.get(removeParameterFromUri(uri));
350     }
351 
removeParameterFromUri(Uri uri)352     public static Uri removeParameterFromUri(Uri uri) {
353         return uri != null ? uri.buildUpon().clearQuery().build() : null;
354     }
355 
356     /**
357      * Returns {@code true} if {@param uri} is a valid Slice Uri handled by
358      * {@link CustomSliceRegistry}.
359      */
isValidUri(Uri uri)360     public static boolean isValidUri(Uri uri) {
361         return sUriToSlice.containsKey(removeParameterFromUri(uri));
362     }
363 
364     /**
365      * Returns {@code true} if {@param action} is a valid intent action handled by
366      * {@link CustomSliceRegistry}.
367      */
isValidAction(String action)368     public static boolean isValidAction(String action) {
369         return isValidUri(Uri.parse(action));
370     }
371 }
372