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

Commit 8a887616 authored by Nikhil Nayunigari's avatar Nikhil Nayunigari Committed by Android (Google) Code Review
Browse files

Merge "Set the state of edit options based on wifi network ownership" into main

parents 148c7593 e334278f
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.wifi.ScanResult;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -345,4 +346,33 @@ public class WifiUtils extends com.android.settingslib.wifi.WifiUtils {
                    });
        }
    }

    /**
     * Checks if the network is owned by the current user of the settings app or
     * if the userCount is one.
     *
     * @param wifiEntry the network entry for which the ownership check will be made.
     * @param context Context of caller
     * @return true if the network is owned by the current user or if the device
     *         contains single user.
     */
    public static boolean isNetworkEditable(
            @NonNull WifiEntry wifiEntry, @NonNull Context context) {
        if (!com.android.settings.connectivity.Flags.wifiMultiuser()) {
            return true;
        }

        UserManager userManager = context.getSystemService(UserManager.class);
        int userCount = userManager.getUserCount();

        UserHandle currentUserHandle = Process.myUserHandle();

        int currentUserId = currentUserHandle.getIdentifier();

        int creatorUid = wifiEntry.getWifiConfiguration().creatorUid;
        UserHandle userHandle = UserHandle.getUserHandleForUid(creatorUid);

        return (userCount == 1)
                || (userHandle != null && (currentUserId == userHandle.getIdentifier()));
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -127,14 +127,15 @@ public class WifiNetworkDetailsFragment extends RestrictedDashboardFragment impl
        super.onAttach(context);
        String wifiEntryKey = getArguments().getString(KEY_CHOSEN_WIFIENTRY_KEY);
        setupNetworksDetailTracker();
        final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
        use(WifiPrivacyPreferenceController.class)
                .setWifiEntryKey(wifiEntryKey);
                .setWifiEntry(wifiEntry);
        use(CertificateDetailsPreferenceController.class)
                .setWifiEntry(mNetworkDetailsTracker.getWifiEntry());
                .setWifiEntry(wifiEntry);
        use(ServerNamePreferenceController.class)
                .setWifiEntry(mNetworkDetailsTracker.getWifiEntry());
                .setWifiEntry(wifiEntry);
        use(WepLessSecureWarningController.class)
                .setWifiEntry(mNetworkDetailsTracker.getWifiEntry());
                .setWifiEntry(wifiEntry);
    }

    @Override
+11 −0
Original line number Diff line number Diff line
@@ -18,8 +18,12 @@ package com.android.settings.wifi.details2;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.wifi.WifiUtils;
import com.android.wifitrackerlib.WifiEntry;

/**
@@ -45,6 +49,13 @@ public class WifiAutoConnectPreferenceController2 extends TogglePreferenceContro
        return mWifiEntry.canSetAutoJoinEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
    }

    @Override
    public void updateState(@NonNull Preference preference) {
        super.updateState(preference);

        preference.setEnabled(WifiUtils.isNetworkEditable(mWifiEntry, mContext));
    }

    @Override
    public boolean isChecked() {
        return mWifiEntry.isAutoJoinEnabled();
+4 −3
Original line number Diff line number Diff line
@@ -900,21 +900,22 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
     */
    public boolean canForgetNetwork() {
        return mWifiEntry.canForget()
                && !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration());
                && !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration())
                    && WifiUtils.isNetworkEditable(mWifiEntry, mContext);
    }

    /**
     * Returns whether the user can sign into the network represented by this preference.
     */
    private boolean canSignIntoNetwork() {
        return mWifiEntry.canSignIn();
        return mWifiEntry.canSignIn() && WifiUtils.isNetworkEditable(mWifiEntry, mContext);
    }

    /**
     * Returns whether the user can share the network represented by this preference with QR code.
     */
    private boolean canShareNetwork() {
        return mWifiEntry.canShare();
        return mWifiEntry.canShare() && WifiUtils.isNetworkEditable(mWifiEntry, mContext);
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.preference.ListPreference;
import androidx.preference.Preference;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.wifi.WifiUtils;
import com.android.wifitrackerlib.WifiEntry;

/**
@@ -47,6 +48,7 @@ public class WifiMeteredPreferenceController2 extends BasePreferenceController i
        final int meteredOverride = getMeteredOverride();
        preference.setSelectable(mWifiEntry.canSetMeteredChoice());
        listPreference.setValue(Integer.toString(meteredOverride));
        preference.setEnabled(WifiUtils.isNetworkEditable(mWifiEntry, mContext));
        updateSummary(listPreference, meteredOverride);
    }

Loading