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

Commit 7abd8e47 authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiInfo: App attribution for suggestion/request

Add a field to store package name for suggestion/specifier package name.
Storing these info in WifiInfo is the convention being followed
for ephemeral networks in WifiTracker.

Bug: 115504887
Bug: 113878056
Test: ./frameworks/base/wifi/tests/runtests.sh
Change-Id: Iab6ab93a2a281011499adfff3163c35058600706
parent 59e3189d
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.net.wifi;

import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
import android.net.NetworkInfo.DetailedState;
@@ -120,8 +121,14 @@ public class WifiInfo implements Parcelable {
    @UnsupportedAppUsage
    private String mMacAddress = DEFAULT_MAC_ADDRESS;

    /**
     * Whether the network is ephemeral or not.
     */
    private boolean mEphemeral;

    /**
     * Whether the network is trusted or not.
     */
    private boolean mTrusted;

    /**
@@ -129,6 +136,12 @@ public class WifiInfo implements Parcelable {
     */
    private boolean mOsuAp;

    /**
     * If connected to a network suggestion or specifier, store the package name of the app,
     * else null.
     */
    private String mNetworkSuggestionOrSpecifierPackageName;

    /**
     * Running total count of lost (not ACKed) transmitted unicast data packets.
     * @hide
@@ -209,6 +222,7 @@ public class WifiInfo implements Parcelable {
        setMeteredHint(false);
        setEphemeral(false);
        setOsuAp(false);
        setNetworkSuggestionOrSpecifierPackageName(null);
        txBad = 0;
        txSuccess = 0;
        rxSuccess = 0;
@@ -240,6 +254,8 @@ public class WifiInfo implements Parcelable {
            mMeteredHint = source.mMeteredHint;
            mEphemeral = source.mEphemeral;
            mTrusted = source.mTrusted;
            mNetworkSuggestionOrSpecifierPackageName =
                    source.mNetworkSuggestionOrSpecifierPackageName;
            mOsuAp = source.mOsuAp;
            txBad = source.txBad;
            txRetries = source.txRetries;
@@ -476,6 +492,17 @@ public class WifiInfo implements Parcelable {
        return mOsuAp;
    }

    /** {@hide} */
    public void setNetworkSuggestionOrSpecifierPackageName(@Nullable String packageName) {
        mNetworkSuggestionOrSpecifierPackageName = packageName;
    }

    /** {@hide} */
    public @Nullable String getNetworkSuggestionOrSpecifierPackageName() {
        return mNetworkSuggestionOrSpecifierPackageName;
    }


    /** @hide */
    @UnsupportedAppUsage
    public void setNetworkId(int id) {
@@ -634,6 +661,7 @@ public class WifiInfo implements Parcelable {
        dest.writeDouble(rxSuccessRate);
        mSupplicantState.writeToParcel(dest, flags);
        dest.writeInt(mOsuAp ? 1 : 0);
        dest.writeString(mNetworkSuggestionOrSpecifierPackageName);
    }

    /** Implement the Parcelable interface {@hide} */
@@ -672,6 +700,7 @@ public class WifiInfo implements Parcelable {
                info.rxSuccessRate = in.readDouble();
                info.mSupplicantState = SupplicantState.CREATOR.createFromParcel(in);
                info.mOsuAp = in.readInt() != 0;
                info.mNetworkSuggestionOrSpecifierPackageName = in.readString();
                return info;
            }

+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ public class WifiInfoTest {
    private static final long TEST_TX_RETRIES = 2;
    private static final long TEST_TX_BAD = 3;
    private static final long TEST_RX_SUCCESS = 4;
    private static final String TEST_PACKAGE_NAME = "com.test.example";

    /**
     *  Verify parcel write/read with WifiInfo.
@@ -48,6 +49,7 @@ public class WifiInfoTest {
        writeWifiInfo.rxSuccess = TEST_RX_SUCCESS;
        writeWifiInfo.setTrusted(true);
        writeWifiInfo.setOsuAp(true);
        writeWifiInfo.setNetworkSuggestionOrSpecifierPackageName(TEST_PACKAGE_NAME);

        Parcel parcel = Parcel.obtain();
        writeWifiInfo.writeToParcel(parcel, 0);
@@ -62,5 +64,6 @@ public class WifiInfoTest {
        assertEquals(TEST_RX_SUCCESS, readWifiInfo.rxSuccess);
        assertTrue(readWifiInfo.isTrusted());
        assertTrue(readWifiInfo.isOsuAp());
        assertEquals(TEST_PACKAGE_NAME, readWifiInfo.getNetworkSuggestionOrSpecifierPackageName());
    }
}