Skip to content

Commit 89d5546

Browse files
author
Jeff Brown
committed
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
1 parent 4e7b551 commit 89d5546

File tree

19 files changed

+770
-319
lines changed

19 files changed

+770
-319
lines changed

core/java/android/hardware/display/DisplayManager.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public void scanWifiDisplays() {
160160
/**
161161
* Connects to a Wifi display.
162162
* The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
163+
* <p>
164+
* Automatically remembers the display after a successful connection, if not
165+
* already remembered.
166+
* </p>
163167
*
164168
* @param deviceAddress The MAC address of the device to which we should connect.
165169
* @hide
@@ -177,6 +181,36 @@ public void disconnectWifiDisplay() {
177181
mGlobal.disconnectWifiDisplay();
178182
}
179183

184+
/**
185+
* Renames a Wifi display.
186+
* <p>
187+
* The display must already be remembered for this call to succeed. In other words,
188+
* we must already have successfully connected to the display at least once and then
189+
* not forgotten it.
190+
* </p>
191+
*
192+
* @param deviceAddress The MAC address of the device to rename.
193+
* @param alias The alias name by which to remember the device, or null
194+
* or empty if no alias should be used.
195+
* @hide
196+
*/
197+
public void renameWifiDisplay(String deviceAddress, String alias) {
198+
mGlobal.renameWifiDisplay(deviceAddress, alias);
199+
}
200+
201+
/**
202+
* Forgets a previously remembered Wifi display.
203+
* <p>
204+
* Automatically disconnects from the display if currently connected to it.
205+
* </p>
206+
*
207+
* @param deviceAddress The MAC address of the device to forget.
208+
* @hide
209+
*/
210+
public void forgetWifiDisplay(String deviceAddress) {
211+
mGlobal.forgetWifiDisplay(deviceAddress);
212+
}
213+
180214
/**
181215
* Gets the current Wifi display status.
182216
* Watch for changes in the status by registering a broadcast receiver for

core/java/android/hardware/display/DisplayManagerGlobal.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,31 @@ public void disconnectWifiDisplay() {
281281
}
282282
}
283283

284+
public void renameWifiDisplay(String deviceAddress, String alias) {
285+
if (deviceAddress == null) {
286+
throw new IllegalArgumentException("deviceAddress must not be null");
287+
}
288+
289+
try {
290+
mDm.renameWifiDisplay(deviceAddress, alias);
291+
} catch (RemoteException ex) {
292+
Log.e(TAG, "Failed to rename Wifi display " + deviceAddress
293+
+ " with alias " + alias + ".", ex);
294+
}
295+
}
296+
297+
public void forgetWifiDisplay(String deviceAddress) {
298+
if (deviceAddress == null) {
299+
throw new IllegalArgumentException("deviceAddress must not be null");
300+
}
301+
302+
try {
303+
mDm.forgetWifiDisplay(deviceAddress);
304+
} catch (RemoteException ex) {
305+
Log.e(TAG, "Failed to forget Wifi display.", ex);
306+
}
307+
}
308+
284309
public WifiDisplayStatus getWifiDisplayStatus() {
285310
try {
286311
return mDm.getWifiDisplayStatus();

core/java/android/hardware/display/IDisplayManager.aidl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ interface IDisplayManager {
3737
// Requires CONFIGURE_WIFI_DISPLAY permission.
3838
void disconnectWifiDisplay();
3939

40+
// Requires CONFIGURE_WIFI_DISPLAY permission.
41+
void renameWifiDisplay(String address, String alias);
42+
43+
// Requires CONFIGURE_WIFI_DISPLAY permission.
44+
void forgetWifiDisplay(String address);
45+
4046
// Requires CONFIGURE_WIFI_DISPLAY permission.
4147
WifiDisplayStatus getWifiDisplayStatus();
4248
}

core/java/android/hardware/display/WifiDisplay.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import android.os.Parcel;
2020
import android.os.Parcelable;
2121

22+
import libcore.util.Objects;
23+
2224
/**
2325
* Describes the properties of a Wifi display.
2426
* <p>
@@ -30,22 +32,24 @@
3032
public final class WifiDisplay implements Parcelable {
3133
private final String mDeviceAddress;
3234
private final String mDeviceName;
35+
private final String mDeviceAlias;
3336

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

3639
public static final Creator<WifiDisplay> CREATOR = new Creator<WifiDisplay>() {
3740
public WifiDisplay createFromParcel(Parcel in) {
3841
String deviceAddress = in.readString();
3942
String deviceName = in.readString();
40-
return new WifiDisplay(deviceAddress, deviceName);
43+
String deviceAlias = in.readString();
44+
return new WifiDisplay(deviceAddress, deviceName, deviceAlias);
4145
}
4246

4347
public WifiDisplay[] newArray(int size) {
4448
return size == 0 ? EMPTY_ARRAY : new WifiDisplay[size];
4549
}
4650
};
4751

48-
public WifiDisplay(String deviceAddress, String deviceName) {
52+
public WifiDisplay(String deviceAddress, String deviceName, String deviceAlias) {
4953
if (deviceAddress == null) {
5054
throw new IllegalArgumentException("deviceAddress must not be null");
5155
}
@@ -55,6 +59,7 @@ public WifiDisplay(String deviceAddress, String deviceName) {
5559

5660
mDeviceAddress = deviceAddress;
5761
mDeviceName = deviceName;
62+
mDeviceAlias = deviceAlias;
5863
}
5964

6065
/**
@@ -71,6 +76,25 @@ public String getDeviceName() {
7176
return mDeviceName;
7277
}
7378

79+
/**
80+
* Gets the user-specified alias of the Wifi display device, or null if none.
81+
* <p>
82+
* The alias should be used in the UI whenever available. It is the value
83+
* provided by the user when renaming the device.
84+
* </p>
85+
*/
86+
public String getDeviceAlias() {
87+
return mDeviceAlias;
88+
}
89+
90+
/**
91+
* Gets the name to show in the UI.
92+
* Uses the device alias if available, otherwise uses the device name.
93+
*/
94+
public String getFriendlyDisplayName() {
95+
return mDeviceAlias != null ? mDeviceAlias : mDeviceName;
96+
}
97+
7498
@Override
7599
public boolean equals(Object o) {
76100
return o instanceof WifiDisplay && equals((WifiDisplay)o);
@@ -79,7 +103,8 @@ public boolean equals(Object o) {
79103
public boolean equals(WifiDisplay other) {
80104
return other != null
81105
&& mDeviceAddress.equals(other.mDeviceAddress)
82-
&& mDeviceName.equals(other.mDeviceName);
106+
&& mDeviceName.equals(other.mDeviceName)
107+
&& Objects.equal(mDeviceAlias, other.mDeviceAlias);
83108
}
84109

85110
@Override
@@ -92,6 +117,7 @@ public int hashCode() {
92117
public void writeToParcel(Parcel dest, int flags) {
93118
dest.writeString(mDeviceAddress);
94119
dest.writeString(mDeviceName);
120+
dest.writeString(mDeviceAlias);
95121
}
96122

97123
@Override
@@ -102,6 +128,10 @@ public int describeContents() {
102128
// For debugging purposes only.
103129
@Override
104130
public String toString() {
105-
return mDeviceName + " (" + mDeviceAddress + ")";
131+
String result = mDeviceName + " (" + mDeviceAddress + ")";
132+
if (mDeviceAlias != null) {
133+
result += ", alias " + mDeviceAlias;
134+
}
135+
return result;
106136
}
107137
}

core/java/android/hardware/display/WifiDisplayStatus.java

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,45 @@
2323

2424
/**
2525
* Describes the current global state of Wifi display connectivity, including the
26-
* currently connected display and all known displays.
26+
* currently connected display and all available or remembered displays.
2727
* <p>
2828
* This object is immutable.
2929
* </p>
3030
*
3131
* @hide
3232
*/
3333
public final class WifiDisplayStatus implements Parcelable {
34-
private final boolean mEnabled;
34+
private final int mFeatureState;
3535
private final int mScanState;
3636
private final int mActiveDisplayState;
3737
private final WifiDisplay mActiveDisplay;
38-
private final WifiDisplay[] mKnownDisplays;
39-
38+
private final WifiDisplay[] mAvailableDisplays;
39+
private final WifiDisplay[] mRememberedDisplays;
40+
41+
/** Feature state: Wifi display is not available on this device. */
42+
public static final int FEATURE_STATE_UNAVAILABLE = 0;
43+
/** Feature state: Wifi display is disabled, probably because Wifi is disabled. */
44+
public static final int FEATURE_STATE_DISABLED = 1;
45+
/** Feature state: Wifi display is turned off in settings. */
46+
public static final int FEATURE_STATE_OFF = 2;
47+
/** Feature state: Wifi display is turned on in settings. */
48+
public static final int FEATURE_STATE_ON = 3;
49+
50+
/** Scan state: Not currently scanning. */
4051
public static final int SCAN_STATE_NOT_SCANNING = 0;
52+
/** Scan state: Currently scanning. */
4153
public static final int SCAN_STATE_SCANNING = 1;
4254

55+
/** Display state: Not connected. */
4356
public static final int DISPLAY_STATE_NOT_CONNECTED = 0;
57+
/** Display state: Connecting to active display. */
4458
public static final int DISPLAY_STATE_CONNECTING = 1;
59+
/** Display state: Connected to active display. */
4560
public static final int DISPLAY_STATE_CONNECTED = 2;
4661

4762
public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
4863
public WifiDisplayStatus createFromParcel(Parcel in) {
49-
boolean enabled = (in.readInt() != 0);
64+
int featureState = in.readInt();
5065
int scanState = in.readInt();
5166
int activeDisplayState= in.readInt();
5267

@@ -55,13 +70,18 @@ public WifiDisplayStatus createFromParcel(Parcel in) {
5570
activeDisplay = WifiDisplay.CREATOR.createFromParcel(in);
5671
}
5772

58-
WifiDisplay[] knownDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
59-
for (int i = 0; i < knownDisplays.length; i++) {
60-
knownDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
73+
WifiDisplay[] availableDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
74+
for (int i = 0; i < availableDisplays.length; i++) {
75+
availableDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
76+
}
77+
78+
WifiDisplay[] rememberedDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
79+
for (int i = 0; i < rememberedDisplays.length; i++) {
80+
rememberedDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
6181
}
6282

63-
return new WifiDisplayStatus(enabled, scanState, activeDisplayState,
64-
activeDisplay, knownDisplays);
83+
return new WifiDisplayStatus(featureState, scanState, activeDisplayState,
84+
activeDisplay, availableDisplays, rememberedDisplays);
6585
}
6686

6787
public WifiDisplayStatus[] newArray(int size) {
@@ -70,33 +90,38 @@ public WifiDisplayStatus[] newArray(int size) {
7090
};
7191

7292
public WifiDisplayStatus() {
73-
this(false, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
74-
null, WifiDisplay.EMPTY_ARRAY);
93+
this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
94+
null, WifiDisplay.EMPTY_ARRAY, WifiDisplay.EMPTY_ARRAY);
7595
}
7696

77-
public WifiDisplayStatus(boolean enabled, int scanState, int activeDisplayState,
78-
WifiDisplay activeDisplay, WifiDisplay[] knownDisplays) {
79-
if (knownDisplays == null) {
80-
throw new IllegalArgumentException("knownDisplays must not be null");
97+
public WifiDisplayStatus(int featureState, int scanState,
98+
int activeDisplayState, WifiDisplay activeDisplay,
99+
WifiDisplay[] availableDisplays, WifiDisplay[] rememberedDisplays) {
100+
if (availableDisplays == null) {
101+
throw new IllegalArgumentException("availableDisplays must not be null");
102+
}
103+
if (rememberedDisplays == null) {
104+
throw new IllegalArgumentException("rememberedDisplays must not be null");
81105
}
82106

83-
mEnabled = enabled;
107+
mFeatureState = featureState;
84108
mScanState = scanState;
85109
mActiveDisplayState = activeDisplayState;
86110
mActiveDisplay = activeDisplay;
87-
mKnownDisplays = knownDisplays;
111+
mAvailableDisplays = availableDisplays;
112+
mRememberedDisplays = rememberedDisplays;
88113
}
89114

90115
/**
91-
* Returns true if the Wifi display feature is enabled and available for use.
116+
* Returns the state of the Wifi display feature on this device.
92117
* <p>
93-
* The value of this property reflects whether Wifi and Wifi P2P functions
94-
* are enabled. Enablement is not directly controllable by the user at this
95-
* time, except indirectly such as by turning off Wifi altogether.
118+
* The value of this property reflects whether the device supports the Wifi display,
119+
* whether it has been enabled by the user and whether the prerequisites for
120+
* connecting to displays have been met.
96121
* </p>
97122
*/
98-
public boolean isEnabled() {
99-
return mEnabled;
123+
public int getFeatureState() {
124+
return mFeatureState;
100125
}
101126

102127
/**
@@ -127,15 +152,29 @@ public WifiDisplay getActiveDisplay() {
127152
}
128153

129154
/**
130-
* Gets the list of all known Wifi displays, never null.
155+
* Gets the list of all available Wifi displays as reported by the most recent
156+
* scan, never null.
157+
* <p>
158+
* Some of these displays may already be remembered, others may be unknown.
159+
* </p>
131160
*/
132-
public WifiDisplay[] getKnownDisplays() {
133-
return mKnownDisplays;
161+
public WifiDisplay[] getAvailableDisplays() {
162+
return mAvailableDisplays;
163+
}
164+
165+
/**
166+
* Gets the list of all remembered Wifi displays, never null.
167+
* <p>
168+
* Not all remembered displays will necessarily be available.
169+
* </p>
170+
*/
171+
public WifiDisplay[] getRememberedDisplays() {
172+
return mRememberedDisplays;
134173
}
135174

136175
@Override
137176
public void writeToParcel(Parcel dest, int flags) {
138-
dest.writeInt(mEnabled ? 1 : 0);
177+
dest.writeInt(mFeatureState);
139178
dest.writeInt(mScanState);
140179
dest.writeInt(mActiveDisplayState);
141180

@@ -146,8 +185,13 @@ public void writeToParcel(Parcel dest, int flags) {
146185
dest.writeInt(0);
147186
}
148187

149-
dest.writeInt(mKnownDisplays.length);
150-
for (WifiDisplay display : mKnownDisplays) {
188+
dest.writeInt(mAvailableDisplays.length);
189+
for (WifiDisplay display : mAvailableDisplays) {
190+
display.writeToParcel(dest, flags);
191+
}
192+
193+
dest.writeInt(mRememberedDisplays.length);
194+
for (WifiDisplay display : mRememberedDisplays) {
151195
display.writeToParcel(dest, flags);
152196
}
153197
}
@@ -160,11 +204,12 @@ public int describeContents() {
160204
// For debugging purposes only.
161205
@Override
162206
public String toString() {
163-
return "WifiDisplayStatus{enabled=" + mEnabled
207+
return "WifiDisplayStatus{featureState=" + mFeatureState
164208
+ ", scanState=" + mScanState
165209
+ ", activeDisplayState=" + mActiveDisplayState
166210
+ ", activeDisplay=" + mActiveDisplay
167-
+ ", knownDisplays=" + Arrays.toString(mKnownDisplays)
211+
+ ", availableDisplays=" + Arrays.toString(mAvailableDisplays)
212+
+ ", rememberedDisplays=" + Arrays.toString(mRememberedDisplays)
168213
+ "}";
169214
}
170215
}

0 commit comments

Comments
 (0)