From cda805612a020057f7363b8e89be72ca9d6958f9 Mon Sep 17 00:00:00 2001 From: Sohani Rao Date: Tue, 18 Oct 2016 17:44:07 -0700 Subject: Async Channel with Logging for Wifi Services Subclassing AsyncChannel to override and add logging calls to - sendMessage() - replyToMessage() - sendMessageSynchronously() Bug: 31746964 Test: Flash and bringup phone, verify logging for services using the WifiAsyncChannel instead of AsyncChanel Change-Id: I0b075f3db16284ffcae0fa2881e5e73310c14e72 --- .../server/wifi/p2p/WifiP2pServiceImpl.java | 6 +- .../android/server/wifi/util/WifiAsyncChannel.java | 98 ++++++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 service/java/com/android/server/wifi/util/WifiAsyncChannel.java (limited to 'service') diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index 876356271..e3e56c8d3 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -82,6 +82,7 @@ import com.android.server.wifi.WifiInjector; import com.android.server.wifi.WifiMonitor; import com.android.server.wifi.WifiNative; import com.android.server.wifi.WifiStateMachine; +import com.android.server.wifi.util.WifiAsyncChannel; import com.android.server.wifi.util.WifiPermissionsUtil; import java.io.FileDescriptor; @@ -114,7 +115,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { private DhcpResults mDhcpResults; private P2pStateMachine mP2pStateMachine; - private AsyncChannel mReplyChannel = new AsyncChannel(); + private AsyncChannel mReplyChannel = new WifiAsyncChannel(TAG); private AsyncChannel mWifiChannel; private static final Boolean JOIN_GROUP = true; @@ -371,7 +372,6 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { HandlerThread wifiP2pThread = new HandlerThread("WifiP2pService"); wifiP2pThread.start(); mClientHandler = new ClientHandler(wifiP2pThread.getLooper()); - mP2pStateMachine = new P2pStateMachine(TAG, wifiP2pThread.getLooper(), mP2pSupported); mP2pStateMachine.start(); } @@ -700,7 +700,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { break; case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: - AsyncChannel ac = new AsyncChannel(); + AsyncChannel ac = new WifiAsyncChannel(TAG); ac.connect(mContext, getHandler(), message.replyTo); break; case BLOCK_DISCOVERY: diff --git a/service/java/com/android/server/wifi/util/WifiAsyncChannel.java b/service/java/com/android/server/wifi/util/WifiAsyncChannel.java new file mode 100644 index 000000000..ccdfb522f --- /dev/null +++ b/service/java/com/android/server/wifi/util/WifiAsyncChannel.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi.util; + +import android.annotation.NonNull; +import android.os.Message; + +import com.android.internal.util.AsyncChannel; +import com.android.server.wifi.WifiInjector; +import com.android.server.wifi.WifiLog; + +/** + * This class subclasses AsyncChannel and adds logging + * to the sendMessage() API + */ +public class WifiAsyncChannel extends AsyncChannel { + private static final String LOG_TAG = "WifiAsyncChannel"; + private WifiLog mLog; + private String mTag; + /** + * AsyncChannelWithLogging constructor + */ + public WifiAsyncChannel(String serviceTag) { + mTag = LOG_TAG + "." + serviceTag; + } + + @NonNull + private WifiLog getOrInitLog() { + // Lazy initization of mLog + if (mLog == null) { + mLog = WifiInjector.getInstance().makeLog(mTag); + } + return mLog; + } + + /** + * Send a message to the destination handler. + * + * @param msg + */ + @Override + public void sendMessage(Message msg) { + getOrInitLog().trace("sendMessage message=%") + .c(msg.what) + .flush(); + super.sendMessage(msg); + } + + /** + * Reply to srcMsg + * + * @param srcMsg + * @param dstMsg + */ + @Override + public void replyToMessage(Message srcMsg, Message dstMsg) { + getOrInitLog() + .trace("replyToMessage recvdMessage=% sendingUid=% sentMessage=%") + .c(srcMsg.what) + .c(srcMsg.sendingUid) + .c(dstMsg.what) + .flush(); + super.replyToMessage(srcMsg, dstMsg); + } + + /** + * Send the Message synchronously. + * + * @param msg to send + * @return reply message or null if an error. + */ + @Override + public Message sendMessageSynchronously(Message msg) { + getOrInitLog().trace("sendMessageSynchronously.send message=%") + .c(msg.what) + .flush(); + Message replyMessage = super.sendMessageSynchronously(msg); + getOrInitLog().trace("sendMessageSynchronously.recv message=% sendingUid=%") + .c(replyMessage.what) + .c(replyMessage.sendingUid) + .flush(); + return replyMessage; + } +} -- cgit v1.2.3