Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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.systemui.log.dagger; |
| 18 | |
| 19 | import android.content.ContentResolver; |
| 20 | import android.os.Build; |
| 21 | import android.os.Looper; |
| 22 | |
| 23 | import com.android.systemui.DumpController; |
| 24 | import com.android.systemui.dagger.qualifiers.Main; |
| 25 | import com.android.systemui.log.LogBuffer; |
| 26 | import com.android.systemui.log.LogcatEchoTracker; |
| 27 | import com.android.systemui.log.LogcatEchoTrackerDebug; |
| 28 | import com.android.systemui.log.LogcatEchoTrackerProd; |
| 29 | |
| 30 | import javax.inject.Singleton; |
| 31 | |
| 32 | import dagger.Module; |
| 33 | import dagger.Provides; |
| 34 | |
| 35 | /** |
| 36 | * Dagger module for providing instances of {@link LogBuffer}. |
| 37 | */ |
| 38 | @Module |
| 39 | public class LogModule { |
| 40 | /** Provides a logging buffer for doze-related logs. */ |
| 41 | @Provides |
| 42 | @Singleton |
| 43 | @DozeLog |
| 44 | public static LogBuffer provideDozeLogBuffer( |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 45 | LogcatEchoTracker bufferFilter, |
Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 46 | DumpController dumpController) { |
| 47 | LogBuffer buffer = new LogBuffer("DozeLog", 100, 10, bufferFilter); |
| 48 | buffer.attach(dumpController); |
| 49 | return buffer; |
| 50 | } |
| 51 | |
| 52 | /** Provides a logging buffer for all logs related to the data layer of notifications. */ |
| 53 | @Provides |
| 54 | @Singleton |
| 55 | @NotificationLog |
| 56 | public static LogBuffer provideNotificationsLogBuffer( |
| 57 | LogcatEchoTracker bufferFilter, |
| 58 | DumpController dumpController) { |
| 59 | LogBuffer buffer = new LogBuffer("NotifLog2", 1000, 10, bufferFilter); |
| 60 | buffer.attach(dumpController); |
| 61 | return buffer; |
| 62 | } |
| 63 | |
| 64 | /** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */ |
| 65 | @Provides |
| 66 | @Singleton |
| 67 | public static LogcatEchoTracker provideLogcatEchoTracker( |
| 68 | ContentResolver contentResolver, |
| 69 | @Main Looper looper) { |
| 70 | if (Build.IS_DEBUGGABLE) { |
| 71 | return LogcatEchoTrackerDebug.create(contentResolver, looper); |
| 72 | } else { |
| 73 | return new LogcatEchoTrackerProd(); |
| 74 | } |
| 75 | } |
| 76 | } |