|
| 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.net.wifi.p2p; |
| 18 | + |
| 19 | +import android.os.Parcelable; |
| 20 | +import android.os.Parcel; |
| 21 | + |
| 22 | +/** |
| 23 | + * A class representing Wifi Display information for a device |
| 24 | + * @hide |
| 25 | + */ |
| 26 | +public class WifiP2pWfdInfo implements Parcelable { |
| 27 | + |
| 28 | + private static final String TAG = "WifiP2pWfdInfo"; |
| 29 | + |
| 30 | + private boolean mWfdEnabled; |
| 31 | + |
| 32 | + private int mDeviceInfo; |
| 33 | + |
| 34 | + public static final int WFD_SOURCE = 0; |
| 35 | + public static final int PRIMARY_SINK = 1; |
| 36 | + public static final int SECONDARY_SINK = 2; |
| 37 | + public static final int SOURCE_OR_PRIMARY_SINK = 3; |
| 38 | + |
| 39 | + /* Device information bitmap */ |
| 40 | + /** One of {@link #WFD_SOURCE}, {@link #PRIMARY_SINK}, {@link #SECONDARY_SINK} |
| 41 | + * or {@link #SOURCE_OR_PRIMARY_SINK} |
| 42 | + */ |
| 43 | + private static final int DEVICE_TYPE = 0x3; |
| 44 | + private static final int COUPLED_SINK_SUPPORT_AT_SOURCE = 0x4; |
| 45 | + private static final int COUPLED_SINK_SUPPORT_AT_SINK = 0x8; |
| 46 | + private static final int SESSION_AVAILABLE = 0x30; |
| 47 | + private static final int SESSION_AVAILABLE_BIT1 = 0x10; |
| 48 | + private static final int SESSION_AVAILABLE_BIT2 = 0x20; |
| 49 | + |
| 50 | + private int mCtrlPort; |
| 51 | + |
| 52 | + private int mMaxThroughput; |
| 53 | + |
| 54 | + public WifiP2pWfdInfo() { |
| 55 | + } |
| 56 | + |
| 57 | + public boolean isWfdEnabled() { |
| 58 | + return mWfdEnabled; |
| 59 | + } |
| 60 | + |
| 61 | + public void setWfdEnabled(boolean enabled) { |
| 62 | + mWfdEnabled = enabled; |
| 63 | + } |
| 64 | + |
| 65 | + public int getDeviceType() { |
| 66 | + return (mDeviceInfo & DEVICE_TYPE); |
| 67 | + } |
| 68 | + |
| 69 | + public boolean setDeviceType(int deviceType) { |
| 70 | + if (deviceType >= WFD_SOURCE && deviceType <= SOURCE_OR_PRIMARY_SINK) { |
| 71 | + mDeviceInfo |= deviceType; |
| 72 | + return true; |
| 73 | + } |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + public boolean isCoupledSinkSupportedAtSource() { |
| 78 | + return (mDeviceInfo & COUPLED_SINK_SUPPORT_AT_SINK) != 0; |
| 79 | + } |
| 80 | + |
| 81 | + public void setCoupledSinkSupportAtSource(boolean enabled) { |
| 82 | + if (enabled ) { |
| 83 | + mDeviceInfo |= COUPLED_SINK_SUPPORT_AT_SINK; |
| 84 | + } else { |
| 85 | + mDeviceInfo &= ~COUPLED_SINK_SUPPORT_AT_SINK; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + public boolean isCoupledSinkSupportedAtSink() { |
| 90 | + return (mDeviceInfo & COUPLED_SINK_SUPPORT_AT_SINK) != 0; |
| 91 | + } |
| 92 | + |
| 93 | + public void setCoupledSinkSupportAtSink(boolean enabled) { |
| 94 | + if (enabled ) { |
| 95 | + mDeviceInfo |= COUPLED_SINK_SUPPORT_AT_SINK; |
| 96 | + } else { |
| 97 | + mDeviceInfo &= ~COUPLED_SINK_SUPPORT_AT_SINK; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + public boolean isSessionAvailable() { |
| 102 | + return (mDeviceInfo & SESSION_AVAILABLE) != 0; |
| 103 | + } |
| 104 | + |
| 105 | + public void setSessionAvailable(boolean enabled) { |
| 106 | + if (enabled) { |
| 107 | + mDeviceInfo |= SESSION_AVAILABLE_BIT1; |
| 108 | + mDeviceInfo &= ~SESSION_AVAILABLE_BIT2; |
| 109 | + } else { |
| 110 | + mDeviceInfo &= ~SESSION_AVAILABLE; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + public int getControlPort() { |
| 115 | + return mCtrlPort; |
| 116 | + } |
| 117 | + |
| 118 | + public void setControlPort(int port) { |
| 119 | + mCtrlPort = port; |
| 120 | + } |
| 121 | + |
| 122 | + public void setMaxThroughput(int maxThroughput) { |
| 123 | + mMaxThroughput = maxThroughput; |
| 124 | + } |
| 125 | + |
| 126 | + public int getMaxThroughput() { |
| 127 | + return mMaxThroughput; |
| 128 | + } |
| 129 | + |
| 130 | + public String getDeviceInfoHex() { |
| 131 | + return String.format("%04x%04x%04x%04x", 6, mDeviceInfo, mCtrlPort, mMaxThroughput); |
| 132 | + } |
| 133 | + |
| 134 | + public String toString() { |
| 135 | + StringBuffer sbuf = new StringBuffer(); |
| 136 | + sbuf.append("WFD enabled: ").append(mWfdEnabled); |
| 137 | + sbuf.append("WFD DeviceInfo: ").append(mDeviceInfo); |
| 138 | + sbuf.append("\n WFD CtrlPort: ").append(mCtrlPort); |
| 139 | + sbuf.append("\n WFD MaxThroughput: ").append(mMaxThroughput); |
| 140 | + return sbuf.toString(); |
| 141 | + } |
| 142 | + |
| 143 | + /** Implement the Parcelable interface */ |
| 144 | + public int describeContents() { |
| 145 | + return 0; |
| 146 | + } |
| 147 | + |
| 148 | + /** copy constructor */ |
| 149 | + public WifiP2pWfdInfo(WifiP2pWfdInfo source) { |
| 150 | + if (source != null) { |
| 151 | + mDeviceInfo = source.mDeviceInfo; |
| 152 | + mCtrlPort = source.mCtrlPort; |
| 153 | + mMaxThroughput = source.mMaxThroughput; |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + /** Implement the Parcelable interface */ |
| 158 | + public void writeToParcel(Parcel dest, int flags) { |
| 159 | + dest.writeInt(mWfdEnabled ? 1 : 0); |
| 160 | + dest.writeInt(mDeviceInfo); |
| 161 | + dest.writeInt(mCtrlPort); |
| 162 | + dest.writeInt(mMaxThroughput); |
| 163 | + } |
| 164 | + |
| 165 | + public void readFromParcel(Parcel in) { |
| 166 | + mWfdEnabled = (in.readInt() == 1); |
| 167 | + mDeviceInfo = in.readInt(); |
| 168 | + mCtrlPort = in.readInt(); |
| 169 | + mMaxThroughput = in.readInt(); |
| 170 | + } |
| 171 | + |
| 172 | + /** Implement the Parcelable interface */ |
| 173 | + public static final Creator<WifiP2pWfdInfo> CREATOR = |
| 174 | + new Creator<WifiP2pWfdInfo>() { |
| 175 | + public WifiP2pWfdInfo createFromParcel(Parcel in) { |
| 176 | + WifiP2pWfdInfo device = new WifiP2pWfdInfo(); |
| 177 | + device.readFromParcel(in); |
| 178 | + return device; |
| 179 | + } |
| 180 | + |
| 181 | + public WifiP2pWfdInfo[] newArray(int size) { |
| 182 | + return new WifiP2pWfdInfo[size]; |
| 183 | + } |
| 184 | + }; |
| 185 | +} |
0 commit comments