Skip to content

Commit e08ae38

Browse files
author
Jeff Brown
committed
Add new wifi display discovery API.
The API is quite simple. There are a few extra functions on DisplayManager to scan, connect and disconnect from wifi displays and get status, and a single protected broadcast sent when the status changes. Change-Id: Ic91dbab5ee818e790b27fa32e1a1e93788793be0
1 parent 0cfebf2 commit e08ae38

File tree

13 files changed

+759
-35
lines changed

13 files changed

+759
-35
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ public final class DisplayManager {
4040
private final Object mLock = new Object();
4141
private final SparseArray<Display> mDisplays = new SparseArray<Display>();
4242

43+
/**
44+
* Broadcast receiver that indicates when the Wifi display status changes.
45+
* <p>
46+
* The status is provided as a {@link WifiDisplayStatus} object in the
47+
* {@link #EXTRA_WIFI_DISPLAY_STATUS} extra.
48+
* </p><p>
49+
* This broadcast is only sent to registered receivers with the
50+
* {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY} permission and can
51+
* only be sent by the system.
52+
* </p>
53+
* @hide
54+
*/
55+
public static final String ACTION_WIFI_DISPLAY_STATUS_CHANGED =
56+
"android.hardware.display.action.WIFI_DISPLAY_STATUS_CHANGED";
57+
58+
/**
59+
* Contains a {@link WifiDisplayStatus} object.
60+
* @hide
61+
*/
62+
public static final String EXTRA_WIFI_DISPLAY_STATUS =
63+
"android.hardware.display.extra.WIFI_DISPLAY_STATUS";
64+
4365
/** @hide */
4466
public DisplayManager(Context context) {
4567
mContext = context;
@@ -126,6 +148,47 @@ public void unregisterDisplayListener(DisplayListener listener) {
126148
mGlobal.unregisterDisplayListener(listener);
127149
}
128150

151+
/**
152+
* Initiates a fresh scan of availble Wifi displays.
153+
* The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
154+
* @hide
155+
*/
156+
public void scanWifiDisplays() {
157+
mGlobal.scanWifiDisplays();
158+
}
159+
160+
/**
161+
* Connects to a Wifi display.
162+
* The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
163+
*
164+
* @param deviceAddress The MAC address of the device to which we should connect.
165+
* @hide
166+
*/
167+
public void connectWifiDisplay(String deviceAddress) {
168+
mGlobal.connectWifiDisplay(deviceAddress);
169+
}
170+
171+
/**
172+
* Disconnects from the current Wifi display.
173+
* The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
174+
* @hide
175+
*/
176+
public void disconnectWifiDisplay() {
177+
mGlobal.disconnectWifiDisplay();
178+
}
179+
180+
/**
181+
* Gets the current Wifi display status.
182+
* Watch for changes in the status by registering a broadcast receiver for
183+
* {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED}.
184+
*
185+
* @return The current Wifi display status.
186+
* @hide
187+
*/
188+
public WifiDisplayStatus getWifiDisplayStatus() {
189+
return mGlobal.getWifiDisplayStatus();
190+
}
191+
129192
/**
130193
* Listens for changes in available display devices.
131194
*/

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,43 @@ private void handleDisplayEvent(int displayId, int event) {
253253
}
254254
}
255255

256+
public void scanWifiDisplays() {
257+
try {
258+
mDm.scanWifiDisplays();
259+
} catch (RemoteException ex) {
260+
Log.e(TAG, "Failed to scan for Wifi displays.", ex);
261+
}
262+
}
263+
264+
public void connectWifiDisplay(String deviceAddress) {
265+
if (deviceAddress == null) {
266+
throw new IllegalArgumentException("deviceAddress must not be null");
267+
}
268+
269+
try {
270+
mDm.connectWifiDisplay(deviceAddress);
271+
} catch (RemoteException ex) {
272+
Log.e(TAG, "Failed to connect to Wifi display " + deviceAddress + ".", ex);
273+
}
274+
}
275+
276+
public void disconnectWifiDisplay() {
277+
try {
278+
mDm.disconnectWifiDisplay();
279+
} catch (RemoteException ex) {
280+
Log.e(TAG, "Failed to disconnect from Wifi display.", ex);
281+
}
282+
}
283+
284+
public WifiDisplayStatus getWifiDisplayStatus() {
285+
try {
286+
return mDm.getWifiDisplayStatus();
287+
} catch (RemoteException ex) {
288+
Log.e(TAG, "Failed to get Wifi display status.", ex);
289+
return new WifiDisplayStatus();
290+
}
291+
}
292+
256293
private final class DisplayManagerCallback extends IDisplayManagerCallback.Stub {
257294
@Override
258295
public void onDisplayEvent(int displayId, int event) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package android.hardware.display;
1818

1919
import android.hardware.display.IDisplayManagerCallback;
20+
import android.hardware.display.WifiDisplay;
21+
import android.hardware.display.WifiDisplayStatus;
2022
import android.view.DisplayInfo;
2123

2224
/** @hide */
@@ -25,4 +27,16 @@ interface IDisplayManager {
2527
int[] getDisplayIds();
2628

2729
void registerCallback(in IDisplayManagerCallback callback);
30+
31+
// Requires CONFIGURE_WIFI_DISPLAY permission.
32+
void scanWifiDisplays();
33+
34+
// Requires CONFIGURE_WIFI_DISPLAY permission.
35+
void connectWifiDisplay(String address);
36+
37+
// Requires CONFIGURE_WIFI_DISPLAY permission.
38+
void disconnectWifiDisplay();
39+
40+
// Requires CONFIGURE_WIFI_DISPLAY permission.
41+
WifiDisplayStatus getWifiDisplayStatus();
2842
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.hardware.display;
18+
19+
parcelable WifiDisplay;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.hardware.display;
18+
19+
import android.os.Parcel;
20+
import android.os.Parcelable;
21+
22+
/**
23+
* Describes the properties of a Wifi display.
24+
* <p>
25+
* This object is immutable.
26+
* </p>
27+
*
28+
* @hide
29+
*/
30+
public final class WifiDisplay implements Parcelable {
31+
private final String mDeviceAddress;
32+
private final String mDeviceName;
33+
34+
public static final WifiDisplay[] EMPTY_ARRAY = new WifiDisplay[0];
35+
36+
public static final Creator<WifiDisplay> CREATOR = new Creator<WifiDisplay>() {
37+
public WifiDisplay createFromParcel(Parcel in) {
38+
String deviceAddress = in.readString();
39+
String deviceName = in.readString();
40+
return new WifiDisplay(deviceAddress, deviceName);
41+
}
42+
43+
public WifiDisplay[] newArray(int size) {
44+
return size == 0 ? EMPTY_ARRAY : new WifiDisplay[size];
45+
}
46+
};
47+
48+
public WifiDisplay(String deviceAddress, String deviceName) {
49+
if (deviceAddress == null) {
50+
throw new IllegalArgumentException("deviceAddress must not be null");
51+
}
52+
if (deviceName == null) {
53+
throw new IllegalArgumentException("deviceName must not be null");
54+
}
55+
56+
mDeviceAddress = deviceAddress;
57+
mDeviceName = deviceName;
58+
}
59+
60+
/**
61+
* Gets the MAC address of the Wifi display device.
62+
*/
63+
public String getDeviceAddress() {
64+
return mDeviceAddress;
65+
}
66+
67+
/**
68+
* Gets the name of the Wifi display device.
69+
*/
70+
public String getDeviceName() {
71+
return mDeviceName;
72+
}
73+
74+
@Override
75+
public boolean equals(Object o) {
76+
return o instanceof WifiDisplay && equals((WifiDisplay)o);
77+
}
78+
79+
public boolean equals(WifiDisplay other) {
80+
return other != null
81+
&& mDeviceAddress.equals(other.mDeviceAddress)
82+
&& mDeviceName.equals(other.mDeviceName);
83+
}
84+
85+
@Override
86+
public int hashCode() {
87+
// The address on its own should be sufficiently unique for hashing purposes.
88+
return mDeviceAddress.hashCode();
89+
}
90+
91+
@Override
92+
public void writeToParcel(Parcel dest, int flags) {
93+
dest.writeString(mDeviceAddress);
94+
dest.writeString(mDeviceName);
95+
}
96+
97+
@Override
98+
public int describeContents() {
99+
return 0;
100+
}
101+
102+
// For debugging purposes only.
103+
@Override
104+
public String toString() {
105+
return mDeviceName + " (" + mDeviceAddress + ")";
106+
}
107+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.hardware.display;
18+
19+
parcelable WifiDisplayStatus;

0 commit comments

Comments
 (0)