diff options
author | Sohani Rao <sohanirao@google.com> | 2016-11-18 10:18:22 -0800 |
---|---|---|
committer | Sohani Rao <sohanirao@google.com> | 2016-12-16 10:41:10 -0800 |
commit | 7275c974c1d7b9451d1e67ae8d56a9d57742303c (patch) | |
tree | 24e221b56fe778e40313ca9c4a7df3c1d78672fb /service | |
parent | 227865949b847b2598867947b96e63ee6a04860c (diff) |
Subclass Handler to log incoming messages
A new class WifiHandler that overrides handleMessage() method to log
incoming messages and associated unit tests. In order to instantiate
WifiLog, an instance of WifiInjector is required. WifiHandler is
expected to be used by any service in wifi, including WifiP2pService.
Since this service is started before WifiService is started,
WifiInjector which is created in WifiServiceImpl would not be available
to instantiate WifiHandler if is required in the constructor. For now,
we use lazy initialization and invoke WifiInjector.getInstance() once
to get the WifiInjector and then make a WifiLog object the first time
a message is logged. In order to enable testing of this class, a hidden
API is exposed only for testing to set the logging field in the class.
Bug: 33085782
Test: Unit test suite, Sanity tests (power on, Wifi connection)
Change-Id: I9110eacb28a5faea331a818998ef25295aa589a8
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/util/WifiHandler.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/util/WifiHandler.java b/service/java/com/android/server/wifi/util/WifiHandler.java new file mode 100644 index 000000000..875060153 --- /dev/null +++ b/service/java/com/android/server/wifi/util/WifiHandler.java @@ -0,0 +1,68 @@ +/* + * 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.Handler; +import android.os.Looper; +import android.os.Message; + +import com.android.internal.annotations.VisibleForTesting; + +import com.android.server.wifi.WifiInjector; +import com.android.server.wifi.WifiLog; + +/** + * This class subclasses Handler to log incoming messages + */ +public class WifiHandler extends Handler { + private static final String LOG_TAG = "WifiHandler"; + private WifiLog mLog; + private String mTag; + + public WifiHandler(String tag, Looper looper) { + super(looper); + mTag = LOG_TAG + "." + tag; + } + + @NonNull + private WifiLog getOrInitLog() { + // Lazy initialization of mLog + if (mLog == null) { + mLog = WifiInjector.getInstance().makeLog(mTag); + } + return mLog; + } + + @Override + public void handleMessage(Message msg) { + getOrInitLog().trace("Received message=%d sendingUid=%") + .c(msg.what) + .c(msg.sendingUid) + .flush(); + } + + /** + * @hide + */ + @VisibleForTesting + public void setWifiLog(WifiLog wifiLog) { + // TODO WifiInjector should be passed as a variable in the constructor + // b/33308811 tracks removing lazy initializations of mLog + mLog = wifiLog; + } +} |