am 20ec8ac5: Merge "Improve Wifi display discovery API." into jb-mr1-dev
* commit '20ec8ac58665e6e2991988c134ba3b8590911648': Improve Wifi display discovery API.
This commit is contained in:
@@ -32,18 +32,27 @@ import java.util.Arrays;
|
|||||||
*/
|
*/
|
||||||
public final class WifiDisplayStatus implements Parcelable {
|
public final class WifiDisplayStatus implements Parcelable {
|
||||||
private final boolean mEnabled;
|
private final boolean mEnabled;
|
||||||
private final WifiDisplay mConnectedDisplay;
|
private final int mScanState;
|
||||||
|
private final int mActiveDisplayState;
|
||||||
|
private final WifiDisplay mActiveDisplay;
|
||||||
private final WifiDisplay[] mKnownDisplays;
|
private final WifiDisplay[] mKnownDisplays;
|
||||||
private final boolean mScanInProgress;
|
|
||||||
private final boolean mConnectionInProgress;
|
public static final int SCAN_STATE_NOT_SCANNING = 0;
|
||||||
|
public static final int SCAN_STATE_SCANNING = 1;
|
||||||
|
|
||||||
|
public static final int DISPLAY_STATE_NOT_CONNECTED = 0;
|
||||||
|
public static final int DISPLAY_STATE_CONNECTING = 1;
|
||||||
|
public static final int DISPLAY_STATE_CONNECTED = 2;
|
||||||
|
|
||||||
public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
|
public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
|
||||||
public WifiDisplayStatus createFromParcel(Parcel in) {
|
public WifiDisplayStatus createFromParcel(Parcel in) {
|
||||||
boolean enabled = (in.readInt() != 0);
|
boolean enabled = (in.readInt() != 0);
|
||||||
|
int scanState = in.readInt();
|
||||||
|
int activeDisplayState= in.readInt();
|
||||||
|
|
||||||
WifiDisplay connectedDisplay = null;
|
WifiDisplay activeDisplay = null;
|
||||||
if (in.readInt() != 0) {
|
if (in.readInt() != 0) {
|
||||||
connectedDisplay = WifiDisplay.CREATOR.createFromParcel(in);
|
activeDisplay = WifiDisplay.CREATOR.createFromParcel(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiDisplay[] knownDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
|
WifiDisplay[] knownDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
|
||||||
@@ -51,11 +60,8 @@ public final class WifiDisplayStatus implements Parcelable {
|
|||||||
knownDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
|
knownDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean scanInProgress = (in.readInt() != 0);
|
return new WifiDisplayStatus(enabled, scanState, activeDisplayState,
|
||||||
boolean connectionInProgress = (in.readInt() != 0);
|
activeDisplay, knownDisplays);
|
||||||
|
|
||||||
return new WifiDisplayStatus(enabled, connectedDisplay, knownDisplays,
|
|
||||||
scanInProgress, connectionInProgress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WifiDisplayStatus[] newArray(int size) {
|
public WifiDisplayStatus[] newArray(int size) {
|
||||||
@@ -64,21 +70,21 @@ public final class WifiDisplayStatus implements Parcelable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public WifiDisplayStatus() {
|
public WifiDisplayStatus() {
|
||||||
this(false, null, WifiDisplay.EMPTY_ARRAY, false, false);
|
this(false, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
|
||||||
|
null, WifiDisplay.EMPTY_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WifiDisplayStatus(boolean enabled,
|
public WifiDisplayStatus(boolean enabled, int scanState, int activeDisplayState,
|
||||||
WifiDisplay connectedDisplay, WifiDisplay[] knownDisplays,
|
WifiDisplay activeDisplay, WifiDisplay[] knownDisplays) {
|
||||||
boolean scanInProgress, boolean connectionInProgress) {
|
|
||||||
if (knownDisplays == null) {
|
if (knownDisplays == null) {
|
||||||
throw new IllegalArgumentException("knownDisplays must not be null");
|
throw new IllegalArgumentException("knownDisplays must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
mEnabled = enabled;
|
mEnabled = enabled;
|
||||||
mConnectedDisplay = connectedDisplay;
|
mScanState = scanState;
|
||||||
|
mActiveDisplayState = activeDisplayState;
|
||||||
|
mActiveDisplay = activeDisplay;
|
||||||
mKnownDisplays = knownDisplays;
|
mKnownDisplays = knownDisplays;
|
||||||
mScanInProgress = scanInProgress;
|
|
||||||
mConnectionInProgress = connectionInProgress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,10 +100,30 @@ public final class WifiDisplayStatus implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the currently connected Wifi display or null if none.
|
* Returns the current state of the Wifi display scan.
|
||||||
|
*
|
||||||
|
* @return One of: {@link #SCAN_STATE_NOT_SCANNING} or {@link #SCAN_STATE_SCANNING}.
|
||||||
*/
|
*/
|
||||||
public WifiDisplay getConnectedDisplay() {
|
public int getScanState() {
|
||||||
return mConnectedDisplay;
|
return mScanState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the state of the currently active display.
|
||||||
|
*
|
||||||
|
* @return One of: {@link #DISPLAY_STATE_NOT_CONNECTED}, {@link #DISPLAY_STATE_CONNECTING},
|
||||||
|
* or {@link #DISPLAY_STATE_CONNECTED}.
|
||||||
|
*/
|
||||||
|
public int getActiveDisplayState() {
|
||||||
|
return mActiveDisplayState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Wifi display that is currently active. It may be connecting or
|
||||||
|
* connected.
|
||||||
|
*/
|
||||||
|
public WifiDisplay getActiveDisplay() {
|
||||||
|
return mActiveDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,27 +133,15 @@ public final class WifiDisplayStatus implements Parcelable {
|
|||||||
return mKnownDisplays;
|
return mKnownDisplays;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if there is currently a Wifi display scan in progress.
|
|
||||||
*/
|
|
||||||
public boolean isScanInProgress() {
|
|
||||||
return mScanInProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if there is currently a Wifi display connection in progress.
|
|
||||||
*/
|
|
||||||
public boolean isConnectionInProgress() {
|
|
||||||
return mConnectionInProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeInt(mEnabled ? 1 : 0);
|
dest.writeInt(mEnabled ? 1 : 0);
|
||||||
|
dest.writeInt(mScanState);
|
||||||
|
dest.writeInt(mActiveDisplayState);
|
||||||
|
|
||||||
if (mConnectedDisplay != null) {
|
if (mActiveDisplay != null) {
|
||||||
dest.writeInt(1);
|
dest.writeInt(1);
|
||||||
mConnectedDisplay.writeToParcel(dest, flags);
|
mActiveDisplay.writeToParcel(dest, flags);
|
||||||
} else {
|
} else {
|
||||||
dest.writeInt(0);
|
dest.writeInt(0);
|
||||||
}
|
}
|
||||||
@@ -136,9 +150,6 @@ public final class WifiDisplayStatus implements Parcelable {
|
|||||||
for (WifiDisplay display : mKnownDisplays) {
|
for (WifiDisplay display : mKnownDisplays) {
|
||||||
display.writeToParcel(dest, flags);
|
display.writeToParcel(dest, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
dest.writeInt(mScanInProgress ? 1 : 0);
|
|
||||||
dest.writeInt(mConnectionInProgress ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -150,10 +161,10 @@ public final class WifiDisplayStatus implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "WifiDisplayStatus{enabled=" + mEnabled
|
return "WifiDisplayStatus{enabled=" + mEnabled
|
||||||
+ ", connectedDisplay=" + mConnectedDisplay
|
+ ", scanState=" + mScanState
|
||||||
|
+ ", activeDisplayState=" + mActiveDisplayState
|
||||||
|
+ ", activeDisplay=" + mActiveDisplay
|
||||||
+ ", knownDisplays=" + Arrays.toString(mKnownDisplays)
|
+ ", knownDisplays=" + Arrays.toString(mKnownDisplays)
|
||||||
+ ", scanInProgress=" + mScanInProgress
|
|
||||||
+ ", connectionInProgress=" + mConnectionInProgress
|
|
||||||
+ "}";
|
+ "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
|
|
||||||
private WifiDisplayStatus mCurrentStatus;
|
private WifiDisplayStatus mCurrentStatus;
|
||||||
private boolean mEnabled;
|
private boolean mEnabled;
|
||||||
private WifiDisplay mConnectedDisplay;
|
private int mScanState;
|
||||||
|
private int mActiveDisplayState;
|
||||||
|
private WifiDisplay mActiveDisplay;
|
||||||
private WifiDisplay[] mKnownDisplays = WifiDisplay.EMPTY_ARRAY;
|
private WifiDisplay[] mKnownDisplays = WifiDisplay.EMPTY_ARRAY;
|
||||||
private boolean mScanInProgress;
|
|
||||||
private boolean mConnectionInProgress;
|
|
||||||
|
|
||||||
private boolean mPendingStatusChangeBroadcast;
|
private boolean mPendingStatusChangeBroadcast;
|
||||||
|
|
||||||
@@ -80,10 +80,10 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
|
|
||||||
pw.println("mCurrentStatus=" + getWifiDisplayStatusLocked());
|
pw.println("mCurrentStatus=" + getWifiDisplayStatusLocked());
|
||||||
pw.println("mEnabled=" + mEnabled);
|
pw.println("mEnabled=" + mEnabled);
|
||||||
pw.println("mConnectedDisplay=" + mConnectedDisplay);
|
pw.println("mScanState=" + mScanState);
|
||||||
|
pw.println("mActiveDisplayState=" + mActiveDisplayState);
|
||||||
|
pw.println("mActiveDisplay=" + mActiveDisplay);
|
||||||
pw.println("mKnownDisplays=" + Arrays.toString(mKnownDisplays));
|
pw.println("mKnownDisplays=" + Arrays.toString(mKnownDisplays));
|
||||||
pw.println("mScanInProgress=" + mScanInProgress);
|
|
||||||
pw.println("mConnectionInProgress=" + mConnectionInProgress);
|
|
||||||
pw.println("mPendingStatusChangeBroadcast=" + mPendingStatusChangeBroadcast);
|
pw.println("mPendingStatusChangeBroadcast=" + mPendingStatusChangeBroadcast);
|
||||||
|
|
||||||
// Try to dump the controller state.
|
// Try to dump the controller state.
|
||||||
@@ -145,9 +145,8 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
|
|
||||||
public WifiDisplayStatus getWifiDisplayStatusLocked() {
|
public WifiDisplayStatus getWifiDisplayStatusLocked() {
|
||||||
if (mCurrentStatus == null) {
|
if (mCurrentStatus == null) {
|
||||||
mCurrentStatus = new WifiDisplayStatus(mEnabled,
|
mCurrentStatus = new WifiDisplayStatus(mEnabled, mScanState, mActiveDisplayState,
|
||||||
mConnectedDisplay, mKnownDisplays,
|
mActiveDisplay, mKnownDisplays);
|
||||||
mScanInProgress, mConnectionInProgress);
|
|
||||||
}
|
}
|
||||||
return mCurrentStatus;
|
return mCurrentStatus;
|
||||||
}
|
}
|
||||||
@@ -211,9 +210,9 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onScanStarted() {
|
public void onScanStarted() {
|
||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
if (!mScanInProgress) {
|
if (mScanState != WifiDisplayStatus.SCAN_STATE_SCANNING) {
|
||||||
mCurrentStatus = null;
|
mCurrentStatus = null;
|
||||||
mScanInProgress = true;
|
mScanState = WifiDisplayStatus.SCAN_STATE_SCANNING;
|
||||||
scheduleStatusChangedBroadcastLocked();
|
scheduleStatusChangedBroadcastLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,10 +220,11 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
|
|
||||||
public void onScanFinished(WifiDisplay[] knownDisplays) {
|
public void onScanFinished(WifiDisplay[] knownDisplays) {
|
||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
if (!Arrays.equals(mKnownDisplays, knownDisplays) || mScanInProgress) {
|
if (mScanState != WifiDisplayStatus.SCAN_STATE_NOT_SCANNING
|
||||||
|
|| !Arrays.equals(mKnownDisplays, knownDisplays)) {
|
||||||
mCurrentStatus = null;
|
mCurrentStatus = null;
|
||||||
|
mScanState = WifiDisplayStatus.SCAN_STATE_NOT_SCANNING;
|
||||||
mKnownDisplays = knownDisplays;
|
mKnownDisplays = knownDisplays;
|
||||||
mScanInProgress = false;
|
|
||||||
scheduleStatusChangedBroadcastLocked();
|
scheduleStatusChangedBroadcastLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,9 +233,12 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisplayConnecting(WifiDisplay display) {
|
public void onDisplayConnecting(WifiDisplay display) {
|
||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
if (!mConnectionInProgress) {
|
if (mActiveDisplayState != WifiDisplayStatus.DISPLAY_STATE_CONNECTING
|
||||||
|
|| mActiveDisplay == null
|
||||||
|
|| !mActiveDisplay.equals(display)) {
|
||||||
mCurrentStatus = null;
|
mCurrentStatus = null;
|
||||||
mConnectionInProgress = true;
|
mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_CONNECTING;
|
||||||
|
mActiveDisplay = display;
|
||||||
scheduleStatusChangedBroadcastLocked();
|
scheduleStatusChangedBroadcastLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,9 +247,11 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisplayConnectionFailed() {
|
public void onDisplayConnectionFailed() {
|
||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
if (mConnectionInProgress) {
|
if (mActiveDisplayState != WifiDisplayStatus.DISPLAY_STATE_NOT_CONNECTED
|
||||||
|
|| mActiveDisplay != null) {
|
||||||
mCurrentStatus = null;
|
mCurrentStatus = null;
|
||||||
mConnectionInProgress = false;
|
mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_NOT_CONNECTED;
|
||||||
|
mActiveDisplay = null;
|
||||||
scheduleStatusChangedBroadcastLocked();
|
scheduleStatusChangedBroadcastLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,11 +262,12 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
handleConnectLocked(display, iface);
|
handleConnectLocked(display, iface);
|
||||||
|
|
||||||
if (mConnectedDisplay == null || !mConnectedDisplay.equals(display)
|
if (mActiveDisplayState != WifiDisplayStatus.DISPLAY_STATE_CONNECTED
|
||||||
|| mConnectionInProgress) {
|
|| mActiveDisplay == null
|
||||||
|
|| !mActiveDisplay.equals(display)) {
|
||||||
mCurrentStatus = null;
|
mCurrentStatus = null;
|
||||||
mConnectedDisplay = display;
|
mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_CONNECTED;
|
||||||
mConnectionInProgress = false;
|
mActiveDisplay = display;
|
||||||
scheduleStatusChangedBroadcastLocked();
|
scheduleStatusChangedBroadcastLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,10 +279,11 @@ final class WifiDisplayAdapter extends DisplayAdapter {
|
|||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
handleDisconnectLocked();
|
handleDisconnectLocked();
|
||||||
|
|
||||||
if (mConnectedDisplay != null || mConnectionInProgress) {
|
if (mActiveDisplayState != WifiDisplayStatus.DISPLAY_STATE_NOT_CONNECTED
|
||||||
|
|| mActiveDisplay != null) {
|
||||||
mCurrentStatus = null;
|
mCurrentStatus = null;
|
||||||
mConnectedDisplay = null;
|
mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_NOT_CONNECTED;
|
||||||
mConnectionInProgress = false;
|
mActiveDisplay = null;
|
||||||
scheduleStatusChangedBroadcastLocked();
|
scheduleStatusChangedBroadcastLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ final class WifiDisplayController implements DumpUtils.Dump {
|
|||||||
|
|
||||||
private void handleConnectionChanged(NetworkInfo networkInfo) {
|
private void handleConnectionChanged(NetworkInfo networkInfo) {
|
||||||
mNetworkInfo = networkInfo;
|
mNetworkInfo = networkInfo;
|
||||||
if (mWifiP2pEnabled && mWfdEnabled && networkInfo.isConnected()) {
|
if (mWfdEnabled && networkInfo.isConnected()) {
|
||||||
if (mDesiredDevice != null) {
|
if (mDesiredDevice != null) {
|
||||||
mWifiP2pManager.requestGroupInfo(mWifiP2pChannel, new GroupInfoListener() {
|
mWifiP2pManager.requestGroupInfo(mWifiP2pChannel, new GroupInfoListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -573,6 +573,13 @@ final class WifiDisplayController implements DumpUtils.Dump {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
|
// After disconnection for a group, for some reason we have a tendency
|
||||||
|
// to get a peer change notification with an empty list of peers.
|
||||||
|
// Perform a fresh scan.
|
||||||
|
if (mWfdEnabled) {
|
||||||
|
requestPeers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user