1956f54b391677d78379729dd14518edddf3c7660Etan Cohen/* 2956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Copyright (C) 2016 The Android Open Source Project 3956f54b391677d78379729dd14518edddf3c7660Etan Cohen * 4956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Licensed under the Apache License, Version 2.0 (the "License"); 5956f54b391677d78379729dd14518edddf3c7660Etan Cohen * you may not use this file except in compliance with the License. 6956f54b391677d78379729dd14518edddf3c7660Etan Cohen * You may obtain a copy of the License at 7956f54b391677d78379729dd14518edddf3c7660Etan Cohen * 8956f54b391677d78379729dd14518edddf3c7660Etan Cohen * http://www.apache.org/licenses/LICENSE-2.0 9956f54b391677d78379729dd14518edddf3c7660Etan Cohen * 10956f54b391677d78379729dd14518edddf3c7660Etan Cohen * Unless required by applicable law or agreed to in writing, software 11956f54b391677d78379729dd14518edddf3c7660Etan Cohen * distributed under the License is distributed on an "AS IS" BASIS, 12956f54b391677d78379729dd14518edddf3c7660Etan Cohen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13956f54b391677d78379729dd14518edddf3c7660Etan Cohen * See the License for the specific language governing permissions and 14956f54b391677d78379729dd14518edddf3c7660Etan Cohen * limitations under the License. 15956f54b391677d78379729dd14518edddf3c7660Etan Cohen */ 16956f54b391677d78379729dd14518edddf3c7660Etan Cohen 17956f54b391677d78379729dd14518edddf3c7660Etan Cohenpackage com.android.server.wifi.nan; 18956f54b391677d78379729dd14518edddf3c7660Etan Cohen 19956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.net.wifi.nan.IWifiNanSessionListener; 20956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.net.wifi.nan.PublishData; 21956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.net.wifi.nan.PublishSettings; 22956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.net.wifi.nan.SubscribeData; 23956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.net.wifi.nan.SubscribeSettings; 24956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.net.wifi.nan.WifiNanSessionListener; 25956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.os.RemoteException; 26956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.util.Log; 27956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport android.util.SparseArray; 28956f54b391677d78379729dd14518edddf3c7660Etan Cohen 29956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport libcore.util.HexEncoding; 30956f54b391677d78379729dd14518edddf3c7660Etan Cohen 31956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport java.io.FileDescriptor; 32956f54b391677d78379729dd14518edddf3c7660Etan Cohenimport java.io.PrintWriter; 33956f54b391677d78379729dd14518edddf3c7660Etan Cohen 34956f54b391677d78379729dd14518edddf3c7660Etan Cohenpublic class WifiNanSessionState { 35956f54b391677d78379729dd14518edddf3c7660Etan Cohen private static final String TAG = "WifiNanSessionState"; 362cb727022e130f0c0b3c549b01c7d88cd57904e3Etan Cohen private static final boolean DBG = false; 37956f54b391677d78379729dd14518edddf3c7660Etan Cohen private static final boolean VDBG = false; // STOPSHIP if true 38956f54b391677d78379729dd14518edddf3c7660Etan Cohen 3922b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen private final SparseArray<String> mMacByRequestorInstanceId = new SparseArray<>(); 40956f54b391677d78379729dd14518edddf3c7660Etan Cohen 41956f54b391677d78379729dd14518edddf3c7660Etan Cohen private int mSessionId; 42956f54b391677d78379729dd14518edddf3c7660Etan Cohen private IWifiNanSessionListener mListener; 43956f54b391677d78379729dd14518edddf3c7660Etan Cohen private int mEvents; 44956f54b391677d78379729dd14518edddf3c7660Etan Cohen 45956f54b391677d78379729dd14518edddf3c7660Etan Cohen private boolean mPubSubIdValid = false; 46956f54b391677d78379729dd14518edddf3c7660Etan Cohen private int mPubSubId; 47956f54b391677d78379729dd14518edddf3c7660Etan Cohen 48956f54b391677d78379729dd14518edddf3c7660Etan Cohen private static final int SESSION_TYPE_NOT_INIT = 0; 49956f54b391677d78379729dd14518edddf3c7660Etan Cohen private static final int SESSION_TYPE_PUBLISH = 1; 50956f54b391677d78379729dd14518edddf3c7660Etan Cohen private static final int SESSION_TYPE_SUBSCRIBE = 2; 51956f54b391677d78379729dd14518edddf3c7660Etan Cohen private int mSessionType = SESSION_TYPE_NOT_INIT; 52956f54b391677d78379729dd14518edddf3c7660Etan Cohen 5322b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen public WifiNanSessionState(int sessionId, IWifiNanSessionListener listener, int events) { 54956f54b391677d78379729dd14518edddf3c7660Etan Cohen mSessionId = sessionId; 55956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener = listener; 56956f54b391677d78379729dd14518edddf3c7660Etan Cohen mEvents = events; 57956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 58956f54b391677d78379729dd14518edddf3c7660Etan Cohen 59956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void destroy() { 6022b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen stop(WifiNanStateManager.getInstance().createNextTransactionId()); 61956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mPubSubIdValid) { 6222b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen mMacByRequestorInstanceId.clear(); 63956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener = null; 64956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = false; 65956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 66956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 67956f54b391677d78379729dd14518edddf3c7660Etan Cohen 68956f54b391677d78379729dd14518edddf3c7660Etan Cohen public int getSessionId() { 69956f54b391677d78379729dd14518edddf3c7660Etan Cohen return mSessionId; 70956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 71956f54b391677d78379729dd14518edddf3c7660Etan Cohen 7222b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen public boolean isPubSubIdSession(int pubSubId) { 7322b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen return mPubSubIdValid && mPubSubId == pubSubId; 7422b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen } 7522b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen 76956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void publish(short transactionId, PublishData data, PublishSettings settings) { 77956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mSessionType == SESSION_TYPE_SUBSCRIBE) { 78956f54b391677d78379729dd14518edddf3c7660Etan Cohen throw new IllegalStateException("A SUBSCRIBE session is being used for publish"); 79956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 80956f54b391677d78379729dd14518edddf3c7660Etan Cohen mSessionType = SESSION_TYPE_PUBLISH; 81956f54b391677d78379729dd14518edddf3c7660Etan Cohen 82956f54b391677d78379729dd14518edddf3c7660Etan Cohen WifiNanNative.getInstance().publish(transactionId, mPubSubIdValid ? mPubSubId : 0, data, 83956f54b391677d78379729dd14518edddf3c7660Etan Cohen settings); 84956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 85956f54b391677d78379729dd14518edddf3c7660Etan Cohen 86956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void subscribe(short transactionId, SubscribeData data, SubscribeSettings settings) { 87956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mSessionType == SESSION_TYPE_PUBLISH) { 88956f54b391677d78379729dd14518edddf3c7660Etan Cohen throw new IllegalStateException("A PUBLISH session is being used for publish"); 89956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 90956f54b391677d78379729dd14518edddf3c7660Etan Cohen mSessionType = SESSION_TYPE_SUBSCRIBE; 91956f54b391677d78379729dd14518edddf3c7660Etan Cohen 92956f54b391677d78379729dd14518edddf3c7660Etan Cohen WifiNanNative.getInstance().subscribe(transactionId, mPubSubIdValid ? mPubSubId : 0, data, 93956f54b391677d78379729dd14518edddf3c7660Etan Cohen settings); 94956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 95956f54b391677d78379729dd14518edddf3c7660Etan Cohen 962e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen public void sendMessage(short transactionId, int peerId, byte[] message, int messageLength, 972e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen int messageId) { 98956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (!mPubSubIdValid) { 99956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.e(TAG, "sendMessage: attempting to send a message on a non-live session " 100956f54b391677d78379729dd14518edddf3c7660Etan Cohen + "(no successful publish or subscribe"); 1012e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen onMessageSendFail(messageId, WifiNanSessionListener.FAIL_REASON_NO_MATCH_SESSION); 102956f54b391677d78379729dd14518edddf3c7660Etan Cohen return; 103956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 104956f54b391677d78379729dd14518edddf3c7660Etan Cohen 10522b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen String peerMacStr = mMacByRequestorInstanceId.get(peerId); 106956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (peerMacStr == null) { 107956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.e(TAG, "sendMessage: attempting to send a message to an address which didn't " 108956f54b391677d78379729dd14518edddf3c7660Etan Cohen + "match/contact us"); 1092e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen onMessageSendFail(messageId, WifiNanSessionListener.FAIL_REASON_NO_MATCH_SESSION); 110956f54b391677d78379729dd14518edddf3c7660Etan Cohen return; 111956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 112956f54b391677d78379729dd14518edddf3c7660Etan Cohen byte[] peerMac = HexEncoding.decode(peerMacStr.toCharArray(), false); 113956f54b391677d78379729dd14518edddf3c7660Etan Cohen 114956f54b391677d78379729dd14518edddf3c7660Etan Cohen WifiNanNative.getInstance().sendMessage(transactionId, mPubSubId, peerId, peerMac, message, 115956f54b391677d78379729dd14518edddf3c7660Etan Cohen messageLength); 116956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 117956f54b391677d78379729dd14518edddf3c7660Etan Cohen 118956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void stop(short transactionId) { 119956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (!mPubSubIdValid || mSessionType == SESSION_TYPE_NOT_INIT) { 120956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.e(TAG, "sendMessage: attempting to stop pub/sub on a non-live session (no " 121956f54b391677d78379729dd14518edddf3c7660Etan Cohen + "successful publish or subscribe"); 122956f54b391677d78379729dd14518edddf3c7660Etan Cohen return; 123956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 124956f54b391677d78379729dd14518edddf3c7660Etan Cohen 125956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mSessionType == SESSION_TYPE_PUBLISH) { 126956f54b391677d78379729dd14518edddf3c7660Etan Cohen WifiNanNative.getInstance().stopPublish(transactionId, mPubSubId); 127956f54b391677d78379729dd14518edddf3c7660Etan Cohen } else if (mSessionType == SESSION_TYPE_SUBSCRIBE) { 128956f54b391677d78379729dd14518edddf3c7660Etan Cohen WifiNanNative.getInstance().stopSubscribe(transactionId, mPubSubId); 129956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 130956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 131956f54b391677d78379729dd14518edddf3c7660Etan Cohen 132956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onPublishSuccess(int publishId) { 133956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubId = publishId; 134956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = true; 135956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 136956f54b391677d78379729dd14518edddf3c7660Etan Cohen 137956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onPublishFail(int status) { 138956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = false; 139956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 140956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null && (mEvents & WifiNanSessionListener.LISTEN_PUBLISH_FAIL) != 0) { 141956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener.onPublishFail(status); 142956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 143956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 144956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onPublishFail: RemoteException (FYI): " + e); 145956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 146956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 147956f54b391677d78379729dd14518edddf3c7660Etan Cohen 148956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onPublishTerminated(int status) { 149956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = false; 150956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 151956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null 152956f54b391677d78379729dd14518edddf3c7660Etan Cohen && (mEvents & WifiNanSessionListener.LISTEN_PUBLISH_TERMINATED) != 0) { 153956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener.onPublishTerminated(status); 154956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 155956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 156956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onPublishTerminated: RemoteException (FYI): " + e); 157956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 158956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 159956f54b391677d78379729dd14518edddf3c7660Etan Cohen 160956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onSubscribeSuccess(int subscribeId) { 161956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubId = subscribeId; 162956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = true; 163956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 164956f54b391677d78379729dd14518edddf3c7660Etan Cohen 165956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onSubscribeFail(int status) { 166956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = false; 167956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 168956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null 169956f54b391677d78379729dd14518edddf3c7660Etan Cohen && (mEvents & WifiNanSessionListener.LISTEN_SUBSCRIBE_FAIL) != 0) { 170956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener.onSubscribeFail(status); 171956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 172956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 173956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onSubscribeFail: RemoteException (FYI): " + e); 174956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 175956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 176956f54b391677d78379729dd14518edddf3c7660Etan Cohen 177956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onSubscribeTerminated(int status) { 178956f54b391677d78379729dd14518edddf3c7660Etan Cohen mPubSubIdValid = false; 179956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 180956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null 181956f54b391677d78379729dd14518edddf3c7660Etan Cohen && (mEvents & WifiNanSessionListener.LISTEN_SUBSCRIBE_TERMINATED) != 0) { 182956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener.onSubscribeTerminated(status); 183956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 184956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 185956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onSubscribeTerminated: RemoteException (FYI): " + e); 186956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 187956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 188956f54b391677d78379729dd14518edddf3c7660Etan Cohen 1892e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen public void onMessageSendSuccess(int messageId) { 190956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 191956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null 192956f54b391677d78379729dd14518edddf3c7660Etan Cohen && (mEvents & WifiNanSessionListener.LISTEN_MESSAGE_SEND_SUCCESS) != 0) { 1932e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen mListener.onMessageSendSuccess(messageId); 194956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 195956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 196956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onMessageSendSuccess: RemoteException (FYI): " + e); 197956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 198956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 199956f54b391677d78379729dd14518edddf3c7660Etan Cohen 2002e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen public void onMessageSendFail(int messageId, int status) { 201956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 202956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null 203956f54b391677d78379729dd14518edddf3c7660Etan Cohen && (mEvents & WifiNanSessionListener.LISTEN_MESSAGE_SEND_FAIL) != 0) { 2042e09c384f5ce86061b115f20fe3ca75a175d87f0Etan Cohen mListener.onMessageSendFail(messageId, status); 205956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 206956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 207956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onMessageSendFail: RemoteException (FYI): " + e); 208956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 209956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 210956f54b391677d78379729dd14518edddf3c7660Etan Cohen 211956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onMatch(int requestorInstanceId, byte[] peerMac, byte[] serviceSpecificInfo, 212956f54b391677d78379729dd14518edddf3c7660Etan Cohen int serviceSpecificInfoLength, byte[] matchFilter, int matchFilterLength) { 21322b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen String prevMac = mMacByRequestorInstanceId.get(requestorInstanceId); 21422b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen mMacByRequestorInstanceId.put(requestorInstanceId, new String(HexEncoding.encode(peerMac))); 215956f54b391677d78379729dd14518edddf3c7660Etan Cohen 216956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (DBG) Log.d(TAG, "onMatch: previous peer MAC replaced - " + prevMac); 217956f54b391677d78379729dd14518edddf3c7660Etan Cohen 218956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 219956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null && (mEvents & WifiNanSessionListener.LISTEN_MATCH) != 0) { 220956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener.onMatch(requestorInstanceId, serviceSpecificInfo, 221956f54b391677d78379729dd14518edddf3c7660Etan Cohen serviceSpecificInfoLength, matchFilter, matchFilterLength); 222956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 223956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 224956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onMatch: RemoteException (FYI): " + e); 225956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 226956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 227956f54b391677d78379729dd14518edddf3c7660Etan Cohen 228956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void onMessageReceived(int requestorInstanceId, byte[] peerMac, byte[] message, 229956f54b391677d78379729dd14518edddf3c7660Etan Cohen int messageLength) { 23022b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen String prevMac = mMacByRequestorInstanceId.get(requestorInstanceId); 23122b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen mMacByRequestorInstanceId.put(requestorInstanceId, new String(HexEncoding.encode(peerMac))); 232956f54b391677d78379729dd14518edddf3c7660Etan Cohen 233956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (DBG) { 234956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.d(TAG, "onMessageReceived: previous peer MAC replaced - " + prevMac); 235956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 236956f54b391677d78379729dd14518edddf3c7660Etan Cohen 237956f54b391677d78379729dd14518edddf3c7660Etan Cohen try { 238956f54b391677d78379729dd14518edddf3c7660Etan Cohen if (mListener != null 239956f54b391677d78379729dd14518edddf3c7660Etan Cohen && (mEvents & WifiNanSessionListener.LISTEN_MESSAGE_RECEIVED) != 0) { 240956f54b391677d78379729dd14518edddf3c7660Etan Cohen mListener.onMessageReceived(requestorInstanceId, message, messageLength); 241956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 242956f54b391677d78379729dd14518edddf3c7660Etan Cohen } catch (RemoteException e) { 243956f54b391677d78379729dd14518edddf3c7660Etan Cohen Log.w(TAG, "onMessageReceived: RemoteException (FYI): " + e); 244956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 245956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 246956f54b391677d78379729dd14518edddf3c7660Etan Cohen 247956f54b391677d78379729dd14518edddf3c7660Etan Cohen public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 248956f54b391677d78379729dd14518edddf3c7660Etan Cohen pw.println("NanSessionState:"); 249956f54b391677d78379729dd14518edddf3c7660Etan Cohen pw.println(" mSessionId: " + mSessionId); 250956f54b391677d78379729dd14518edddf3c7660Etan Cohen pw.println(" mSessionType: " + mSessionType); 251956f54b391677d78379729dd14518edddf3c7660Etan Cohen pw.println(" mEvents: " + mEvents); 252956f54b391677d78379729dd14518edddf3c7660Etan Cohen pw.println(" mPubSubId: " + (mPubSubIdValid ? Integer.toString(mPubSubId) : "not valid")); 25322b4156d2948e3108ae8439dc72f76fb97526aceEtan Cohen pw.println(" mMacByRequestorInstanceId: [" + mMacByRequestorInstanceId + "]"); 254956f54b391677d78379729dd14518edddf3c7660Etan Cohen } 255956f54b391677d78379729dd14518edddf3c7660Etan Cohen} 256