Guard slices from being requested by guest user

According to patch of A-231987122, AOSP restricts app to modify relevant
mobile settings when user is a guest. This change intends to prevent the
slices related to mobile settings from being requested by guest user.

Bug: 278616139
Bug: 277333776
Bug: 262244832
Bug: 278616520
Bug: 278615120
Test: robotests
Change-Id: I4dc4bbfdb5cf76e188e6f62ebfd74ef6fa2fe33b
This commit is contained in:
Mill Chen
2023-05-13 03:40:14 +08:00
parent f2f899106d
commit d4eecf6132
4 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.slices;
import android.content.ContentResolver;
import android.net.Uri;
import android.provider.SettingsSlicesContract;
/**
* A utility class to check slice Uris for restriction.
*/
public class RestrictedSliceUtils {
/**
* Uri for the notifying open networks Slice.
*/
private static final Uri NOTIFY_OPEN_NETWORKS_SLICE_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath("notify_open_networks")
.build();
/**
* Uri for the auto turning on Wi-Fi Slice.
*/
private static final Uri AUTO_TURN_ON_WIFI_SLICE_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath("enable_wifi_wakeup")
.build();
/**
* Uri for the usb tethering Slice.
*/
private static final Uri USB_TETHERING_SLICE_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath("enable_usb_tethering")
.build();
/**
* Uri for the bluetooth tethering Slice.
*/
private static final Uri BLUETOOTH_TETHERING_SLICE_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath("enable_bluetooth_tethering_2")
.build();
/**
* Returns true if the slice Uri restricts access to guest user.
*/
public static boolean isGuestRestricted(Uri sliceUri) {
if (AUTO_TURN_ON_WIFI_SLICE_URI.equals(sliceUri)
|| NOTIFY_OPEN_NETWORKS_SLICE_URI.equals(sliceUri)
|| BLUETOOTH_TETHERING_SLICE_URI.equals(sliceUri)
|| USB_TETHERING_SLICE_URI.equals(sliceUri)
|| CustomSliceRegistry.MOBILE_DATA_SLICE_URI.equals(sliceUri)) {
return true;
}
return false;
}
}

View File

@@ -30,6 +30,7 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Binder;
import android.os.StrictMode;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.SettingsSlicesContract;
import android.text.TextUtils;
@@ -233,6 +234,14 @@ public class SettingsSliceProvider extends SliceProvider {
getContext().getTheme().rebase();
}
// Checking if some semi-sensitive slices are requested by a guest user. If so, will
// return an empty slice.
final UserManager userManager = getContext().getSystemService(UserManager.class);
if (userManager.isGuestUser() && RestrictedSliceUtils.isGuestRestricted(sliceUri)) {
Log.i(TAG, "Guest user access denied.");
return null;
}
// Before adding a slice to {@link CustomSliceManager}, please get approval
// from the Settings team.
if (CustomSliceRegistry.isValidUri(sliceUri)) {