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

Commit 89d5546d authored by Jeff Brown's avatar Jeff Brown
Browse files

Add support for remembering Wifi display devices.

Add a setting to globally disable Wifi display.

Fixed a bug where the wifi display broadcast receiver
was running on the wrong thread.

Removed the wifi-display QuickSettings dialog, all functionality
has been moved to Settings.

Bug: 7178216
Bug: 7192799
Change-Id: I9796baac8245d664cf28fa147b9ed978d81d8ab9
parent 4e7b551f
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -160,6 +160,10 @@ public final class DisplayManager {
    /**
     * Connects to a Wifi display.
     * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
     * <p>
     * Automatically remembers the display after a successful connection, if not
     * already remembered.
     * </p>
     *
     * @param deviceAddress The MAC address of the device to which we should connect.
     * @hide
@@ -177,6 +181,36 @@ public final class DisplayManager {
        mGlobal.disconnectWifiDisplay();
    }

    /**
     * Renames a Wifi display.
     * <p>
     * The display must already be remembered for this call to succeed.  In other words,
     * we must already have successfully connected to the display at least once and then
     * not forgotten it.
     * </p>
     *
     * @param deviceAddress The MAC address of the device to rename.
     * @param alias The alias name by which to remember the device, or null
     * or empty if no alias should be used.
     * @hide
     */
    public void renameWifiDisplay(String deviceAddress, String alias) {
        mGlobal.renameWifiDisplay(deviceAddress, alias);
    }

    /**
     * Forgets a previously remembered Wifi display.
     * <p>
     * Automatically disconnects from the display if currently connected to it.
     * </p>
     *
     * @param deviceAddress The MAC address of the device to forget.
     * @hide
     */
    public void forgetWifiDisplay(String deviceAddress) {
        mGlobal.forgetWifiDisplay(deviceAddress);
    }

    /**
     * Gets the current Wifi display status.
     * Watch for changes in the status by registering a broadcast receiver for
+25 −0
Original line number Diff line number Diff line
@@ -281,6 +281,31 @@ public final class DisplayManagerGlobal {
        }
    }

    public void renameWifiDisplay(String deviceAddress, String alias) {
        if (deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress must not be null");
        }

        try {
            mDm.renameWifiDisplay(deviceAddress, alias);
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to rename Wifi display " + deviceAddress
                    + " with alias " + alias + ".", ex);
        }
    }

    public void forgetWifiDisplay(String deviceAddress) {
        if (deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress must not be null");
        }

        try {
            mDm.forgetWifiDisplay(deviceAddress);
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to forget Wifi display.", ex);
        }
    }

    public WifiDisplayStatus getWifiDisplayStatus() {
        try {
            return mDm.getWifiDisplayStatus();
+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,12 @@ interface IDisplayManager {
    // Requires CONFIGURE_WIFI_DISPLAY permission.
    void disconnectWifiDisplay();

    // Requires CONFIGURE_WIFI_DISPLAY permission.
    void renameWifiDisplay(String address, String alias);

    // Requires CONFIGURE_WIFI_DISPLAY permission.
    void forgetWifiDisplay(String address);

    // Requires CONFIGURE_WIFI_DISPLAY permission.
    WifiDisplayStatus getWifiDisplayStatus();
}
+34 −4
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.hardware.display;
import android.os.Parcel;
import android.os.Parcelable;

import libcore.util.Objects;

/**
 * Describes the properties of a Wifi display.
 * <p>
@@ -30,6 +32,7 @@ import android.os.Parcelable;
public final class WifiDisplay implements Parcelable {
    private final String mDeviceAddress;
    private final String mDeviceName;
    private final String mDeviceAlias;

    public static final WifiDisplay[] EMPTY_ARRAY = new WifiDisplay[0];

@@ -37,7 +40,8 @@ public final class WifiDisplay implements Parcelable {
        public WifiDisplay createFromParcel(Parcel in) {
            String deviceAddress = in.readString();
            String deviceName = in.readString();
            return new WifiDisplay(deviceAddress, deviceName);
            String deviceAlias = in.readString();
            return new WifiDisplay(deviceAddress, deviceName, deviceAlias);
        }

        public WifiDisplay[] newArray(int size) {
@@ -45,7 +49,7 @@ public final class WifiDisplay implements Parcelable {
        }
    };

    public WifiDisplay(String deviceAddress, String deviceName) {
    public WifiDisplay(String deviceAddress, String deviceName, String deviceAlias) {
        if (deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress must not be null");
        }
@@ -55,6 +59,7 @@ public final class WifiDisplay implements Parcelable {

        mDeviceAddress = deviceAddress;
        mDeviceName = deviceName;
        mDeviceAlias = deviceAlias;
    }

    /**
@@ -71,6 +76,25 @@ public final class WifiDisplay implements Parcelable {
        return mDeviceName;
    }

    /**
     * Gets the user-specified alias of the Wifi display device, or null if none.
     * <p>
     * The alias should be used in the UI whenever available.  It is the value
     * provided by the user when renaming the device.
     * </p>
     */
    public String getDeviceAlias() {
        return mDeviceAlias;
    }

    /**
     * Gets the name to show in the UI.
     * Uses the device alias if available, otherwise uses the device name.
     */
    public String getFriendlyDisplayName() {
        return mDeviceAlias != null ? mDeviceAlias : mDeviceName;
    }

    @Override
    public boolean equals(Object o) {
        return o instanceof WifiDisplay && equals((WifiDisplay)o);
@@ -79,7 +103,8 @@ public final class WifiDisplay implements Parcelable {
    public boolean equals(WifiDisplay other) {
        return other != null
                && mDeviceAddress.equals(other.mDeviceAddress)
                && mDeviceName.equals(other.mDeviceName);
                && mDeviceName.equals(other.mDeviceName)
                && Objects.equal(mDeviceAlias, other.mDeviceAlias);
    }

    @Override
@@ -92,6 +117,7 @@ public final class WifiDisplay implements Parcelable {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mDeviceAddress);
        dest.writeString(mDeviceName);
        dest.writeString(mDeviceAlias);
    }

    @Override
@@ -102,6 +128,10 @@ public final class WifiDisplay implements Parcelable {
    // For debugging purposes only.
    @Override
    public String toString() {
        return mDeviceName + " (" + mDeviceAddress + ")";
        String result = mDeviceName + " (" + mDeviceAddress + ")";
        if (mDeviceAlias != null) {
            result += ", alias " + mDeviceAlias;
        }
        return result;
    }
}
+77 −32
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import java.util.Arrays;

/**
 * Describes the current global state of Wifi display connectivity, including the
 * currently connected display and all known displays.
 * currently connected display and all available or remembered displays.
 * <p>
 * This object is immutable.
 * </p>
@@ -31,22 +31,37 @@ import java.util.Arrays;
 * @hide
 */
public final class WifiDisplayStatus implements Parcelable {
    private final boolean mEnabled;
    private final int mFeatureState;
    private final int mScanState;
    private final int mActiveDisplayState;
    private final WifiDisplay mActiveDisplay;
    private final WifiDisplay[] mKnownDisplays;

    private final WifiDisplay[] mAvailableDisplays;
    private final WifiDisplay[] mRememberedDisplays;

    /** Feature state: Wifi display is not available on this device. */
    public static final int FEATURE_STATE_UNAVAILABLE = 0;
    /** Feature state: Wifi display is disabled, probably because Wifi is disabled. */
    public static final int FEATURE_STATE_DISABLED = 1;
    /** Feature state: Wifi display is turned off in settings. */
    public static final int FEATURE_STATE_OFF = 2;
    /** Feature state: Wifi display is turned on in settings. */
    public static final int FEATURE_STATE_ON = 3;

    /** Scan state: Not currently scanning. */
    public static final int SCAN_STATE_NOT_SCANNING = 0;
    /** Scan state: Currently scanning. */
    public static final int SCAN_STATE_SCANNING = 1;

    /** Display state: Not connected. */
    public static final int DISPLAY_STATE_NOT_CONNECTED = 0;
    /** Display state: Connecting to active display. */
    public static final int DISPLAY_STATE_CONNECTING = 1;
    /** Display state: Connected to active display. */
    public static final int DISPLAY_STATE_CONNECTED = 2;

    public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
        public WifiDisplayStatus createFromParcel(Parcel in) {
            boolean enabled = (in.readInt() != 0);
            int featureState = in.readInt();
            int scanState = in.readInt();
            int activeDisplayState= in.readInt();

@@ -55,13 +70,18 @@ public final class WifiDisplayStatus implements Parcelable {
                activeDisplay = WifiDisplay.CREATOR.createFromParcel(in);
            }

            WifiDisplay[] knownDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
            for (int i = 0; i < knownDisplays.length; i++) {
                knownDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
            WifiDisplay[] availableDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
            for (int i = 0; i < availableDisplays.length; i++) {
                availableDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
            }

            WifiDisplay[] rememberedDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
            for (int i = 0; i < rememberedDisplays.length; i++) {
                rememberedDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
            }

            return new WifiDisplayStatus(enabled, scanState, activeDisplayState,
                    activeDisplay, knownDisplays);
            return new WifiDisplayStatus(featureState, scanState, activeDisplayState,
                    activeDisplay, availableDisplays, rememberedDisplays);
        }

        public WifiDisplayStatus[] newArray(int size) {
@@ -70,33 +90,38 @@ public final class WifiDisplayStatus implements Parcelable {
    };

    public WifiDisplayStatus() {
        this(false, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
                null, WifiDisplay.EMPTY_ARRAY);
        this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
                null, WifiDisplay.EMPTY_ARRAY, WifiDisplay.EMPTY_ARRAY);
    }

    public WifiDisplayStatus(boolean enabled, int scanState, int activeDisplayState,
            WifiDisplay activeDisplay, WifiDisplay[] knownDisplays) {
        if (knownDisplays == null) {
            throw new IllegalArgumentException("knownDisplays must not be null");
    public WifiDisplayStatus(int featureState, int scanState,
            int activeDisplayState, WifiDisplay activeDisplay,
            WifiDisplay[] availableDisplays, WifiDisplay[] rememberedDisplays) {
        if (availableDisplays == null) {
            throw new IllegalArgumentException("availableDisplays must not be null");
        }
        if (rememberedDisplays == null) {
            throw new IllegalArgumentException("rememberedDisplays must not be null");
        }

        mEnabled = enabled;
        mFeatureState = featureState;
        mScanState = scanState;
        mActiveDisplayState = activeDisplayState;
        mActiveDisplay = activeDisplay;
        mKnownDisplays = knownDisplays;
        mAvailableDisplays = availableDisplays;
        mRememberedDisplays = rememberedDisplays;
    }

    /**
     * Returns true if the Wifi display feature is enabled and available for use.
     * Returns the state of the Wifi display feature on this device.
     * <p>
     * The value of this property reflects whether Wifi and Wifi P2P functions
     * are enabled.  Enablement is not directly controllable by the user at this
     * time, except indirectly such as by turning off Wifi altogether.
     * The value of this property reflects whether the device supports the Wifi display,
     * whether it has been enabled by the user and whether the prerequisites for
     * connecting to displays have been met.
     * </p>
     */
    public boolean isEnabled() {
        return mEnabled;
    public int getFeatureState() {
        return mFeatureState;
    }

    /**
@@ -127,15 +152,29 @@ public final class WifiDisplayStatus implements Parcelable {
    }

    /**
     * Gets the list of all known Wifi displays, never null.
     * Gets the list of all available Wifi displays as reported by the most recent
     * scan, never null.
     * <p>
     * Some of these displays may already be remembered, others may be unknown.
     * </p>
     */
    public WifiDisplay[] getKnownDisplays() {
        return mKnownDisplays;
    public WifiDisplay[] getAvailableDisplays() {
        return mAvailableDisplays;
    }

    /**
     * Gets the list of all remembered Wifi displays, never null.
     * <p>
     * Not all remembered displays will necessarily be available.
     * </p>
     */
    public WifiDisplay[] getRememberedDisplays() {
        return mRememberedDisplays;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mEnabled ? 1 : 0);
        dest.writeInt(mFeatureState);
        dest.writeInt(mScanState);
        dest.writeInt(mActiveDisplayState);

@@ -146,8 +185,13 @@ public final class WifiDisplayStatus implements Parcelable {
            dest.writeInt(0);
        }

        dest.writeInt(mKnownDisplays.length);
        for (WifiDisplay display : mKnownDisplays) {
        dest.writeInt(mAvailableDisplays.length);
        for (WifiDisplay display : mAvailableDisplays) {
            display.writeToParcel(dest, flags);
        }

        dest.writeInt(mRememberedDisplays.length);
        for (WifiDisplay display : mRememberedDisplays) {
            display.writeToParcel(dest, flags);
        }
    }
@@ -160,11 +204,12 @@ public final class WifiDisplayStatus implements Parcelable {
    // For debugging purposes only.
    @Override
    public String toString() {
        return "WifiDisplayStatus{enabled=" + mEnabled
        return "WifiDisplayStatus{featureState=" + mFeatureState
                + ", scanState=" + mScanState
                + ", activeDisplayState=" + mActiveDisplayState
                + ", activeDisplay=" + mActiveDisplay
                + ", knownDisplays=" + Arrays.toString(mKnownDisplays)
                + ", availableDisplays=" + Arrays.toString(mAvailableDisplays)
                + ", rememberedDisplays=" + Arrays.toString(mRememberedDisplays)
                + "}";
    }
}
Loading