Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 922fc606 authored by Edward Savage-Jones's avatar Edward Savage-Jones
Browse files

Only allow clearing of Euicc Data by owner or demo user

Secondary users should not be able to erase downloaded SIMs
is a similar way that they are not be able to factory reset
the device.

Bug: 303488763
Test: On a device with FEATURE_TELEPHONY_EUICC enabled,
      create secondary user, enter Settings->System->Reset Options
      there should be no option to 'Erase downloaded SIMs'
Change-Id: I4f5326732822bc322ab13a00937f94232ca69228
parent fcaf0ace
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.settings.network;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserManager;
import android.text.TextUtils;

import androidx.preference.Preference;

import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.network.telephony.MobileNetworkUtils;
@@ -33,8 +35,11 @@ import com.android.settings.system.ResetDashboardFragment;
public class EraseEuiccDataController extends BasePreferenceController {
    private ResetDashboardFragment mHostFragment;

    private final UserManager mUm;

    public EraseEuiccDataController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mUm = context.getSystemService(UserManager.class);
    }

    public void setFragment(ResetDashboardFragment hostFragment) {
@@ -52,10 +57,12 @@ public class EraseEuiccDataController extends BasePreferenceController {

    @Override
    public int getAvailabilityStatus() {
        return SubscriptionUtil.isSimHardwareVisible(mContext) &&
                (!MobileNetworkUtils.isMobileNetworkUserRestricted(mContext)) &&
                mContext.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TELEPHONY_EUICC) ? AVAILABLE_UNSEARCHABLE
                : UNSUPPORTED_ON_DEVICE;
        boolean isAllowedUser = (mUm.isAdminUser() || Utils.isDemoUser(mContext))
                && !MobileNetworkUtils.isMobileNetworkUserRestricted(mContext);
        boolean hasEuiccFeature = mContext.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TELEPHONY_EUICC);
        return SubscriptionUtil.isSimHardwareVisible(mContext)
                && isAllowedUser
                && hasEuiccFeature ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
    }
}