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

Commit db99b31c authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiConfiguration: Add a field to mark network as trusted

The |ephemeral| field (added for WFA) is currently used for 2 purposes:
a) Network is not persisted & network config
is automatically removed at the end of the connection.
b) Network is marked untrusted (in NetworkInfo capabilities) after connection.

For the new network request API, we want (a), but not (b) (Network should
be marked trusted because user explicitly allowed it).

Add a new flag to explicitly mark the network as trusted or not. Hence
(a) & (b) are now indicated by different flags.

Bug: 113878056
Test: ./frameworks/base/wifi/tests/runtests.sh
Change-Id: If4da84ca4fc03fd6a835b71a3e18e966c3b11f05
parent dc69f468
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -761,6 +761,13 @@ public class WifiConfiguration implements Parcelable {
      return ephemeral;
    }

    /**
     * Indicate whther the network is trusted or not. Networks are considered trusted
     * if the user explicitly allowed this network connection.
     * @hide
     */
    public boolean trusted;

    /**
     * Indicates if the creator of this configuration has expressed that it
     * should be considered metered.
@@ -1638,6 +1645,7 @@ public class WifiConfiguration implements Parcelable {
        selfAdded = false;
        didSelfAdd = false;
        ephemeral = false;
        trusted = true; // Networks are considered trusted by default.
        meteredHint = false;
        meteredOverride = METERED_OVERRIDE_NONE;
        useExternalScores = false;
@@ -1747,10 +1755,11 @@ public class WifiConfiguration implements Parcelable {
        if (this.selfAdded) sbuf.append(" selfAdded");
        if (this.validatedInternetAccess) sbuf.append(" validatedInternetAccess");
        if (this.ephemeral) sbuf.append(" ephemeral");
        if (this.trusted) sbuf.append(" trusted");
        if (this.meteredHint) sbuf.append(" meteredHint");
        if (this.useExternalScores) sbuf.append(" useExternalScores");
        if (this.didSelfAdd || this.selfAdded || this.validatedInternetAccess
            || this.ephemeral || this.meteredHint || this.useExternalScores) {
                || this.ephemeral || this.trusted || this.meteredHint || this.useExternalScores) {
            sbuf.append("\n");
        }
        if (this.meteredOverride != METERED_OVERRIDE_NONE) {
@@ -2235,6 +2244,7 @@ public class WifiConfiguration implements Parcelable {
            validatedInternetAccess = source.validatedInternetAccess;
            isLegacyPasspointConfig = source.isLegacyPasspointConfig;
            ephemeral = source.ephemeral;
            trusted = source.trusted;
            meteredHint = source.meteredHint;
            meteredOverride = source.meteredOverride;
            useExternalScores = source.useExternalScores;
@@ -2310,6 +2320,7 @@ public class WifiConfiguration implements Parcelable {
        dest.writeInt(validatedInternetAccess ? 1 : 0);
        dest.writeInt(isLegacyPasspointConfig ? 1 : 0);
        dest.writeInt(ephemeral ? 1 : 0);
        dest.writeInt(trusted ? 1 : 0);
        dest.writeInt(meteredHint ? 1 : 0);
        dest.writeInt(meteredOverride);
        dest.writeInt(useExternalScores ? 1 : 0);
@@ -2379,6 +2390,7 @@ public class WifiConfiguration implements Parcelable {
                config.validatedInternetAccess = in.readInt() != 0;
                config.isLegacyPasspointConfig = in.readInt() != 0;
                config.ephemeral = in.readInt() != 0;
                config.trusted = in.readInt() != 0;
                config.meteredHint = in.readInt() != 0;
                config.meteredOverride = in.readInt();
                config.useExternalScores = in.readInt() != 0;
+16 −0
Original line number Diff line number Diff line
@@ -110,6 +110,8 @@ public class WifiInfo implements Parcelable {

    private boolean mEphemeral;

    private boolean mTrusted;

    /**
     * Running total count of lost (not ACKed) transmitted unicast data packets.
     * @hide
@@ -215,6 +217,7 @@ public class WifiInfo implements Parcelable {
            mMacAddress = source.mMacAddress;
            mMeteredHint = source.mMeteredHint;
            mEphemeral = source.mEphemeral;
            mTrusted = source.mTrusted;
            txBad = source.txBad;
            txRetries = source.txRetries;
            txSuccess = source.txSuccess;
@@ -397,6 +400,17 @@ public class WifiInfo implements Parcelable {
        return mEphemeral;
    }

    /** {@hide} */
    public void setTrusted(boolean trusted) {
        mTrusted = trusted;
    }

    /** {@hide} */
    public boolean isTrusted() {
        return mTrusted;
    }


    /** @hide */
    @UnsupportedAppUsage
    public void setNetworkId(int id) {
@@ -539,6 +553,7 @@ public class WifiInfo implements Parcelable {
        dest.writeString(mMacAddress);
        dest.writeInt(mMeteredHint ? 1 : 0);
        dest.writeInt(mEphemeral ? 1 : 0);
        dest.writeInt(mTrusted ? 1 : 0);
        dest.writeInt(score);
        dest.writeLong(txSuccess);
        dest.writeDouble(txSuccessRate);
@@ -573,6 +588,7 @@ public class WifiInfo implements Parcelable {
                info.mMacAddress = in.readString();
                info.mMeteredHint = in.readInt() != 0;
                info.mEphemeral = in.readInt() != 0;
                info.mTrusted = in.readInt() != 0;
                info.score = in.readInt();
                info.txSuccess = in.readLong();
                info.txSuccessRate = in.readDouble();
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class WifiConfigurationTest {
        String cookie = "C O.o |<IE";
        WifiConfiguration config = new WifiConfiguration();
        config.setPasspointManagementObjectTree(cookie);
        config.trusted = false;
        MacAddress macBeforeParcel = config.getOrCreateRandomizedMacAddress();
        Parcel parcelW = Parcel.obtain();
        config.writeToParcel(parcelW, 0);
@@ -71,6 +72,7 @@ public class WifiConfigurationTest {
        // lacking a useful config.equals, check two fields near the end.
        assertEquals(cookie, reconfig.getMoTree());
        assertEquals(macBeforeParcel, reconfig.getOrCreateRandomizedMacAddress());
        assertFalse(reconfig.trusted);

        Parcel parcelWW = Parcel.obtain();
        reconfig.writeToParcel(parcelWW, 0);
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net.wifi;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.os.Parcel;
import android.support.test.filters.SmallTest;
@@ -44,6 +45,7 @@ public class WifiInfoTest {
        writeWifiInfo.txRetries = TEST_TX_RETRIES;
        writeWifiInfo.txBad = TEST_TX_BAD;
        writeWifiInfo.rxSuccess = TEST_RX_SUCCESS;
        writeWifiInfo.setTrusted(true);

        Parcel parcel = Parcel.obtain();
        writeWifiInfo.writeToParcel(parcel, 0);
@@ -56,5 +58,6 @@ public class WifiInfoTest {
        assertEquals(TEST_TX_RETRIES, readWifiInfo.txRetries);
        assertEquals(TEST_TX_BAD, readWifiInfo.txBad);
        assertEquals(TEST_RX_SUCCESS, readWifiInfo.rxSuccess);
        assertTrue(readWifiInfo.isTrusted());
    }
}