1 /*
2  * Copyright (C) 2023 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 android.content.ContentResolver;
20 import android.net.Uri;
21 import android.provider.SettingsSlicesContract;
22 
23 /**
24  * A utility class to check slice Uris for restriction.
25  */
26 public class RestrictedSliceUtils {
27 
28     /**
29      * Uri for the notifying open networks Slice.
30      */
31     private static final Uri NOTIFY_OPEN_NETWORKS_SLICE_URI = new Uri.Builder()
32         .scheme(ContentResolver.SCHEME_CONTENT)
33         .authority(SettingsSliceProvider.SLICE_AUTHORITY)
34         .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
35         .appendPath("notify_open_networks")
36         .build();
37 
38     /**
39      * Uri for the auto turning on Wi-Fi Slice.
40      */
41     private static final Uri AUTO_TURN_ON_WIFI_SLICE_URI = new Uri.Builder()
42         .scheme(ContentResolver.SCHEME_CONTENT)
43         .authority(SettingsSliceProvider.SLICE_AUTHORITY)
44         .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
45         .appendPath("enable_wifi_wakeup")
46         .build();
47 
48     /**
49      * Uri for the usb tethering Slice.
50      */
51     private static final Uri USB_TETHERING_SLICE_URI = new Uri.Builder()
52         .scheme(ContentResolver.SCHEME_CONTENT)
53         .authority(SettingsSliceProvider.SLICE_AUTHORITY)
54         .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
55         .appendPath("enable_usb_tethering")
56         .build();
57 
58     /**
59      * Uri for the bluetooth tethering Slice.
60      */
61     private static final Uri BLUETOOTH_TETHERING_SLICE_URI = new Uri.Builder()
62         .scheme(ContentResolver.SCHEME_CONTENT)
63         .authority(SettingsSliceProvider.SLICE_AUTHORITY)
64         .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
65         .appendPath("enable_bluetooth_tethering_2")
66         .build();
67 
68     /**
69      * Returns true if the slice Uri restricts access to guest user.
70      */
isGuestRestricted(Uri sliceUri)71     public static boolean isGuestRestricted(Uri sliceUri) {
72         if (AUTO_TURN_ON_WIFI_SLICE_URI.equals(sliceUri)
73             || NOTIFY_OPEN_NETWORKS_SLICE_URI.equals(sliceUri)
74             || BLUETOOTH_TETHERING_SLICE_URI.equals(sliceUri)
75             || USB_TETHERING_SLICE_URI.equals(sliceUri)
76             || CustomSliceRegistry.MOBILE_DATA_SLICE_URI.equals(sliceUri)) {
77             return true;
78         }
79         return false;
80     }
81 }
82