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.dialer.p13n.logging; 18 19 import android.content.Context; 20 import android.support.annotation.NonNull; 21 import com.android.contacts.common.list.PhoneNumberListAdapter; 22 import com.android.dialer.common.Assert; 23 24 /** Single entry point for all logging for personalization. */ 25 public final class P13nLogging { 26 27 private static P13nLogger logger; 28 P13nLogging()29 private P13nLogging() {} 30 31 @NonNull get(@onNull Context context)32 public static P13nLogger get(@NonNull Context context) { 33 Assert.isNotNull(context); 34 Assert.isMainThread(); 35 if (logger != null) { 36 return logger; 37 } 38 39 Context application = context.getApplicationContext(); 40 if (application instanceof P13nLoggerFactory) { 41 logger = ((P13nLoggerFactory) application).newP13nLogger(context); 42 } 43 44 if (logger == null) { 45 logger = 46 new P13nLogger() { 47 @Override 48 public void onSearchQuery(String query, PhoneNumberListAdapter adapter) {} 49 50 @Override 51 public void reset() {} 52 }; 53 } 54 return logger; 55 } 56 setForTesting(@onNull P13nLogger logger)57 public static void setForTesting(@NonNull P13nLogger logger) { 58 P13nLogging.logger = logger; 59 } 60 } 61