• 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.display.AlwaysOnDisplaySlice;
30 import com.android.settings.display.ScreenTimeoutPreferenceController;
31 import com.android.settings.flashlight.FlashlightSlice;
32 import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
33 import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
34 import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice;
35 import com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice;
36 import com.android.settings.homepage.contextualcards.slices.DarkThemeSlice;
37 import com.android.settings.homepage.contextualcards.slices.FaceSetupSlice;
38 import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
39 import com.android.settings.location.LocationSlice;
40 import com.android.settings.media.MediaOutputIndicatorSlice;
41 import com.android.settings.media.RemoteMediaSlice;
42 import com.android.settings.network.ProviderModelSlice;
43 import com.android.settings.network.telephony.MobileDataSlice;
44 import com.android.settings.notification.zen.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.MediaOutputConstants;
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 Contextual Adaptive Sleep Slice
59      */
60     public static final Uri CONTEXTUAL_ADAPTIVE_SLEEP_URI = new Uri.Builder()
61             .scheme(ContentResolver.SCHEME_CONTENT)
62             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
63             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
64             .appendPath(ScreenTimeoutPreferenceController.PREF_NAME)
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 the Wifi Slice.
99      */
100     public static final Uri CONTEXTUAL_WIFI_SLICE_URI = new Uri.Builder()
101             .scheme(ContentResolver.SCHEME_CONTENT)
102             .authority(SettingsSlicesContract.AUTHORITY)
103             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
104             .appendPath("contextual_wifi")
105             .build();
106     /**
107      * Slice Uri for Enhanced 4G slice
108      */
109     public static final Uri ENHANCED_4G_SLICE_URI = new Uri.Builder()
110             .scheme(ContentResolver.SCHEME_CONTENT)
111             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
112             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
113             .appendPath("enhanced_4g_lte")
114             .build();
115     /**
116      * Slice Uri for Face Enrollment
117      */
118     public static final Uri FACE_ENROLL_SLICE_URI = new Uri.Builder()
119             .scheme(ContentResolver.SCHEME_CONTENT)
120             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
121             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
122             .appendPath("face_unlock_greeting_card")
123             .build();
124     /**
125      * Backing Uri for the Flashlight Slice.
126      */
127     public static final Uri FLASHLIGHT_SLICE_URI = new Uri.Builder()
128             .scheme(ContentResolver.SCHEME_CONTENT)
129             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
130             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
131             .appendPath("flashlight")
132             .build();
133     /**
134      * Backing Uri for the Location Slice.
135      */
136     public static final Uri LOCATION_SLICE_URI = new Uri.Builder()
137             .scheme(ContentResolver.SCHEME_CONTENT)
138             .authority(SettingsSlicesContract.AUTHORITY)
139             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
140             .appendPath(KEY_LOCATION)
141             .build();
142     /**
143      * Backing Uri for Low storage Slice.
144      */
145     public static final Uri LOW_STORAGE_SLICE_URI = new Uri.Builder()
146             .scheme(ContentResolver.SCHEME_CONTENT)
147             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
148             .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT)
149             .appendPath("low_storage")
150             .build();
151     /**
152      * Backing Uri for NFC Slice
153      */
154     public static final Uri NFC_SLICE_URI = new Uri.Builder()
155             .scheme(ContentResolver.SCHEME_CONTENT)
156             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
157             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
158             .appendPath("toggle_nfc")
159             .build();
160 
161     /**
162      * Backing Uri for Mobile Data Slice.
163      */
164     public static final Uri MOBILE_DATA_SLICE_URI = new Uri.Builder()
165             .scheme(ContentResolver.SCHEME_CONTENT)
166             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
167             .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_ACTION)
168             .appendPath("mobile_data")
169             .build();
170 
171     /**
172      * Full {@link Uri} for the Provider Model Slice.
173      */
174     public static final Uri PROVIDER_MODEL_SLICE_URI = new Uri.Builder()
175             .scheme(ContentResolver.SCHEME_CONTENT)
176             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
177             .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_ACTION)
178             .appendPath("provider_model")
179             .build();
180 
181     /**
182      * Full {@link Uri} for the Alarm volume Slice.
183      */
184     public static final Uri VOLUME_ALARM_URI = new Uri.Builder()
185             .scheme(ContentResolver.SCHEME_CONTENT)
186             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
187             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
188             .appendPath("alarm_volume")
189             .build();
190 
191     /**
192      * Full {@link Uri} for the Call Volume Slice.
193      */
194     public static final Uri VOLUME_CALL_URI = new Uri.Builder()
195             .scheme(ContentResolver.SCHEME_CONTENT)
196             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
197             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
198             .appendPath("call_volume")
199             .build();
200     /**
201      * Full {@link Uri} for the Media Volume Slice.
202      */
203     public static final Uri VOLUME_MEDIA_URI = new Uri.Builder()
204             .scheme(ContentResolver.SCHEME_CONTENT)
205             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
206             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
207             .appendPath("media_volume")
208             .build();
209 
210     /**
211      * Full {@link Uri} for the Ringer volume Slice.
212      */
213     public static final Uri VOLUME_RINGER_URI = new Uri.Builder()
214             .scheme(ContentResolver.SCHEME_CONTENT)
215             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
216             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
217             .appendPath("ring_volume")
218             .build();
219 
220     /**
221      * Full {@link Uri} for the all volume Slices.
222      */
223     public static final Uri VOLUME_SLICES_URI = new Uri.Builder()
224             .scheme(ContentResolver.SCHEME_CONTENT)
225             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
226             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
227             .appendPath("volume_slices")
228             .build();
229 
230     /**
231      * Full {@link Uri} for the Wifi Calling Slice.
232      */
233     public static final Uri WIFI_CALLING_URI = new Uri.Builder()
234             .scheme(ContentResolver.SCHEME_CONTENT)
235             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
236             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
237             .appendPath(WifiCallingSliceHelper.PATH_WIFI_CALLING)
238             .build();
239     /**
240      * Full {@link Uri} for the Wifi Calling Preference Slice.
241      */
242     public static final Uri WIFI_CALLING_PREFERENCE_URI = new Uri.Builder()
243             .scheme(ContentResolver.SCHEME_CONTENT)
244             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
245             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
246             .appendPath(WifiCallingSliceHelper.PATH_WIFI_CALLING_PREFERENCE)
247             .build();
248     /**
249      * Backing Uri for the Wifi Slice.
250      */
251     public static final Uri WIFI_SLICE_URI = new Uri.Builder()
252             .scheme(ContentResolver.SCHEME_CONTENT)
253             .authority(SettingsSlicesContract.AUTHORITY)
254             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
255             .appendPath(KEY_WIFI)
256             .build();
257 
258     /**
259      * Backing Uri for the Zen Mode Slice.
260      */
261     public static final Uri ZEN_MODE_SLICE_URI = new Uri.Builder()
262             .scheme(ContentResolver.SCHEME_CONTENT)
263             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
264             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
265             .appendPath(ZenModeButtonPreferenceController.KEY)
266             .build();
267 
268     /**
269      * Backing Uri for the Media output indicator Slice.
270      */
271     public static Uri MEDIA_OUTPUT_INDICATOR_SLICE_URI = new Uri.Builder()
272             .scheme(ContentResolver.SCHEME_CONTENT)
273             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
274             .appendPath(SettingsSlicesContract.PATH_SETTING_INTENT)
275             .appendPath("media_output_indicator")
276             .build();
277 
278     /**
279      * Backing Uri for the Dark theme Slice.
280      */
281     public static final Uri DARK_THEME_SLICE_URI = new Uri.Builder()
282             .scheme(ContentResolver.SCHEME_CONTENT)
283             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
284             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
285             .appendPath("dark_theme")
286             .build();
287 
288     /**
289      * Backing Uri for the Remote Media Slice.
290      */
291     public static Uri REMOTE_MEDIA_SLICE_URI = new Uri.Builder()
292             .scheme(ContentResolver.SCHEME_CONTENT)
293             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
294             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
295             .appendPath(MediaOutputConstants.KEY_REMOTE_MEDIA)
296             .build();
297 
298     /**
299      * Backing Uri for the Always On Slice.
300      */
301     public static final Uri ALWAYS_ON_SLICE_URI = new Uri.Builder()
302             .scheme(ContentResolver.SCHEME_CONTENT)
303             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
304             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
305             .appendPath("always_on_display")
306             .build();
307 
308     /**
309      * Backing Uri for the Turn on Wi-Fi Slice.
310      */
311     public static final Uri TURN_ON_WIFI_SLICE_URI = new Uri.Builder()
312             .scheme(ContentResolver.SCHEME_CONTENT)
313             .authority(SettingsSliceProvider.SLICE_AUTHORITY)
314             .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
315             .appendPath("turn_on_wifi")
316             .build();
317 
318     @VisibleForTesting
319     static final Map<Uri, Class<? extends CustomSliceable>> sUriToSlice;
320 
321     static {
322         sUriToSlice = new ArrayMap<>();
323 
sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class)324         sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class)325         sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class)326         sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class);
sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class)327         sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class);
sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class)328         sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class);
sUriToSlice.put(FLASHLIGHT_SLICE_URI, FlashlightSlice.class)329         sUriToSlice.put(FLASHLIGHT_SLICE_URI, FlashlightSlice.class);
sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class)330         sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class);
sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class)331         sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class);
sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class)332         sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
sUriToSlice.put(MOBILE_DATA_SLICE_URI, MobileDataSlice.class)333         sUriToSlice.put(MOBILE_DATA_SLICE_URI, MobileDataSlice.class);
sUriToSlice.put(PROVIDER_MODEL_SLICE_URI, ProviderModelSlice.class)334         sUriToSlice.put(PROVIDER_MODEL_SLICE_URI, ProviderModelSlice.class);
sUriToSlice.put(WIFI_SLICE_URI, WifiSlice.class)335         sUriToSlice.put(WIFI_SLICE_URI, WifiSlice.class);
sUriToSlice.put(DARK_THEME_SLICE_URI, DarkThemeSlice.class)336         sUriToSlice.put(DARK_THEME_SLICE_URI, DarkThemeSlice.class);
sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class)337         sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class);
sUriToSlice.put(ALWAYS_ON_SLICE_URI, AlwaysOnDisplaySlice.class)338         sUriToSlice.put(ALWAYS_ON_SLICE_URI, AlwaysOnDisplaySlice.class);
339     }
340 
getSliceClassByUri(Uri uri)341     public static Class<? extends CustomSliceable> getSliceClassByUri(Uri uri) {
342         return sUriToSlice.get(removeParameterFromUri(uri));
343     }
344 
removeParameterFromUri(Uri uri)345     public static Uri removeParameterFromUri(Uri uri) {
346         return uri != null ? uri.buildUpon().clearQuery().build() : null;
347     }
348 
349     /**
350      * Returns {@code true} if {@param uri} is a valid Slice Uri handled by
351      * {@link CustomSliceRegistry}.
352      */
isValidUri(Uri uri)353     public static boolean isValidUri(Uri uri) {
354         return sUriToSlice.containsKey(removeParameterFromUri(uri));
355     }
356 
357     /**
358      * Returns {@code true} if {@param action} is a valid intent action handled by
359      * {@link CustomSliceRegistry}.
360      */
isValidAction(String action)361     public static boolean isValidAction(String action) {
362         return isValidUri(Uri.parse(action));
363     }
364 }
365