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