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.statusbar.notification.collection.render
18 
19 import com.android.systemui.log.LogBuffer
20 import com.android.systemui.log.LogLevel
21 import com.android.systemui.log.dagger.NotificationLog
22 import java.lang.RuntimeException
23 import javax.inject.Inject
24 
25 class ShadeViewDifferLogger @Inject constructor(
26     @NotificationLog private val buffer: LogBuffer
27 ) {
28     fun logDetachingChild(
29         key: String,
30         isTransfer: Boolean,
31         oldParent: String?,
32         newParent: String?
33     ) {
34         buffer.log(TAG, LogLevel.DEBUG, {
35             str1 = key
36             bool1 = isTransfer
37             str2 = oldParent
38             str3 = newParent
39         }, {
40             "Detach $str1 isTransfer=$bool1 oldParent=$str2 newParent=$str3"
41         })
42     }
43 
44     fun logSkippingDetach(key: String, parent: String?) {
45         buffer.log(TAG, LogLevel.DEBUG, {
46             str1 = key
47             str2 = parent
48         }, {
49             "Skipping detach of $str1 because its parent $str2 is also being detached"
50         })
51     }
52 
53     fun logAttachingChild(key: String, parent: String) {
54         buffer.log(TAG, LogLevel.DEBUG, {
55             str1 = key
56             str2 = parent
57         }, {
58             "Attaching view $str1 to $str2"
59         })
60     }
61 
62     fun logMovingChild(key: String, parent: String, toIndex: Int) {
63         buffer.log(TAG, LogLevel.DEBUG, {
64             str1 = key
65             str2 = parent
66             int1 = toIndex
67         }, {
68             "Moving child view $str1 in $str2 to index $int1"
69         })
70     }
71 
72     fun logDuplicateNodeInTree(node: NodeSpec, ex: RuntimeException) {
73         buffer.log(TAG, LogLevel.ERROR, {
74             str1 = ex.toString()
75             str2 = treeSpecToStr(node)
76         }, {
77             "$str1 when mapping tree: $str2"
78         })
79     }
80 }
81 
82 private const val TAG = "NotifViewManager"