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

Commit 56f06c59 authored by Alex Johnston's avatar Alex Johnston Committed by Android (Google) Code Review
Browse files

Merge "Update Wi-Fi configs restrictions" into rvc-dev

parents a10969bf d1a31ab6
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -491,7 +491,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment

        // "forget" for normal saved network. And "disconnect" for ephemeral network because it
        // could only be disconnected and be put in blacklists so it won't be used again.
        if (mSelectedWifiEntry.canForget()) {
        if (canForgetNetwork()) {
            menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
        }

@@ -507,6 +507,11 @@ public class WifiSettings2 extends RestrictedSettingsFragment
        }
    }

    private boolean canForgetNetwork() {
        return mSelectedWifiEntry.canForget() && !WifiUtils.isNetworkLockedDown(getActivity(),
                mSelectedWifiEntry.getWifiConfiguration());
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
+16 −0
Original line number Diff line number Diff line
@@ -24,9 +24,12 @@ import android.content.pm.PackageManager;
import android.net.NetworkCapabilities;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;

import com.android.settings.Utils;
import com.android.settingslib.wifi.AccessPoint;

import java.nio.charset.StandardCharsets;
@@ -77,6 +80,7 @@ public class WifiUtils {
        final DevicePolicyManager dpm =
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        final PackageManager pm = context.getPackageManager();
        final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);

        // Check if device has DPM capability. If it has and dpm is still null, then we
        // treat this case with suspicion and bail out.
@@ -96,6 +100,18 @@ public class WifiUtils {
                } catch (PackageManager.NameNotFoundException e) {
                    // don't care
                }
            } else if (dpm.isOrganizationOwnedDeviceWithManagedProfile()) {
                int profileOwnerUserId = Utils.getManagedProfileId(um, UserHandle.myUserId());
                final ComponentName profileOwner = dpm.getProfileOwnerAsUser(profileOwnerUserId);
                if (profileOwner != null) {
                    try {
                        final int profileOwnerUid = pm.getPackageUidAsUser(
                                profileOwner.getPackageName(), profileOwnerUserId);
                        isConfigEligibleForLockdown = profileOwnerUid == config.creatorUid;
                    } catch (PackageManager.NameNotFoundException e) {
                        // don't care
                    }
                }
            }
        }
        if (!isConfigEligibleForLockdown) {
+9 −1
Original line number Diff line number Diff line
@@ -660,7 +660,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
    }

    private void refreshButtons() {
        final boolean canForgetNetwork = mWifiEntry.canForget();
        final boolean canForgetNetwork = canForgetNetwork();
        final boolean showCaptivePortalButton = updateCaptivePortalButton();
        final boolean canConnectDisconnectNetwork = mWifiEntry.canConnect()
                || mWifiEntry.canDisconnect();
@@ -787,6 +787,14 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
                && !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration());
    }

    /**
     * Returns whether the network represented by this preference can be forgotten.
     */
    public boolean canForgetNetwork() {
        return mWifiEntry.canForget()
                && !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration());
    }

    /**
     * Returns whether the user can sign into the network represented by this preference.
     */
+17 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.wifi.details2;
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;

import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.net.ConnectivityManager;
@@ -29,6 +30,8 @@ import android.os.Looper;
import android.os.Process;
import android.os.SimpleClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -36,10 +39,12 @@ import android.view.MenuItem;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.wifi.WifiConfigUiBase2;
import com.android.settings.wifi.WifiDialog2;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.wifitrackerlib.NetworkDetailsTracker;
@@ -129,8 +134,18 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
        switch (menuItem.getItemId()) {
            case Menu.FIRST:
                if (!mWifiDetailPreferenceController2.canModifyNetwork()) {
                    RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
                            RestrictedLockUtilsInternal.getDeviceOwner(getContext()));
                    EnforcedAdmin admin = RestrictedLockUtilsInternal.getDeviceOwner(getContext());
                    if (admin == null) {
                        final DevicePolicyManager dpm = (DevicePolicyManager)
                                getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
                        final UserManager um = (UserManager)
                                getContext().getSystemService(Context.USER_SERVICE);
                        int profileOwnerUserId = Utils.getManagedProfileId(
                                um, UserHandle.myUserId());
                        admin = new EnforcedAdmin(dpm.getProfileOwnerAsUser(profileOwnerUserId),
                                null, UserHandle.of(profileOwnerUserId));
                    }
                    RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), admin);
                } else {
                    showDialog(WIFI_DIALOG_ID);
                }