1 /* 2 * Copyright (C) 2016 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 com.android.server.wifi.util; 18 19 import android.annotation.NonNull; 20 import android.os.Handler; 21 import android.os.Looper; 22 import android.os.Message; 23 24 import com.android.internal.annotations.VisibleForTesting; 25 import com.android.server.wifi.WifiInjector; 26 import com.android.server.wifi.WifiLog; 27 28 /** 29 * This class subclasses Handler to log incoming messages 30 */ 31 public class WifiHandler extends Handler { 32 private static final String LOG_TAG = "WifiHandler"; 33 private WifiLog mLog; 34 private String mTag; 35 WifiHandler(String tag, Looper looper)36 public WifiHandler(String tag, Looper looper) { 37 super(looper); 38 mTag = LOG_TAG + "." + tag; 39 } 40 41 @NonNull getOrInitLog()42 private WifiLog getOrInitLog() { 43 // Lazy initialization of mLog 44 if (mLog == null) { 45 mLog = WifiInjector.getInstance().makeLog(mTag); 46 } 47 return mLog; 48 } 49 50 @Override handleMessage(Message msg)51 public void handleMessage(Message msg) { 52 getOrInitLog().trace("Received message=% sendingUid=%") 53 .c(msg.what) 54 .c(msg.sendingUid) 55 .flush(); 56 } 57 58 /** 59 * @hide 60 */ 61 @VisibleForTesting setWifiLog(WifiLog wifiLog)62 public void setWifiLog(WifiLog wifiLog) { 63 // TODO WifiInjector should be passed as a variable in the constructor 64 // b/33308811 tracks removing lazy initializations of mLog 65 mLog = wifiLog; 66 } 67 } 68