Restrict WifiSlice functionality for guest user
- Hide Wi-Fi toggle and show Wi-Fi status only if the user is a guest. Bug: 232798363 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=WifiSliceTest Change-Id: I35418477808eb5082f4651f5689f018dbb8e42ac
This commit is contained in:
@@ -34,7 +34,9 @@ import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.EventLog;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -96,10 +98,18 @@ public class WifiSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
// If user is a guest just return a slice without a toggle.
|
||||
if (isGuestUser(mContext)) {
|
||||
Log.e(TAG, "Guest user is not allowed to configure Wi-Fi!");
|
||||
EventLog.writeEvent(0x534e4554, "232798363", -1 /* UID */, "User is a guest");
|
||||
return getListBuilder(isWifiEnabled, null /* wifiSliceItem */,
|
||||
false /* isWiFiPermissionGranted */).build();
|
||||
}
|
||||
|
||||
// If external calling package doesn't have Wi-Fi permission.
|
||||
final boolean isPermissionGranted =
|
||||
Utils.isSettingsIntelligence(mContext) || isPermissionGranted(mContext);
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
ListBuilder listBuilder = getListBuilder(isWifiEnabled, null /* wifiSliceItem */,
|
||||
isPermissionGranted);
|
||||
// If the caller doesn't have the permission granted, just return a slice without a toggle.
|
||||
@@ -139,6 +149,13 @@ public class WifiSlice implements CustomSliceable {
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
protected static boolean isGuestUser(Context context) {
|
||||
if (context == null) return false;
|
||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||
if (userManager == null) return false;
|
||||
return userManager.isGuestUser();
|
||||
}
|
||||
|
||||
private static boolean isPermissionGranted(Context settingsContext) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
final String callingPackage = settingsContext.getPackageManager()
|
||||
|
Reference in New Issue
Block a user