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.dagger.NotificationLog
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
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         isParentRemoved: Boolean,
32         oldParent: String?,
33         newParent: String?
34     ) {
35         buffer.log(TAG, LogLevel.DEBUG, {
36             str1 = key
37             bool1 = isTransfer
38             bool2 = isParentRemoved
39             str2 = oldParent
40             str3 = newParent
41         }, {
42             "Detach $str1 isTransfer=$bool1 isParentRemoved=$bool2 oldParent=$str2 newParent=$str3"
43         })
44     }
45 
46     fun logSkipDetachingChild(
47             key: String,
48             parentKey: String?,
49             isTransfer: Boolean,
50             isParentRemoved: Boolean
51     ) {
52         buffer.log(TAG, LogLevel.DEBUG, {
53             str1 = key
54             str2 = parentKey
55             bool1 = isTransfer
56             bool2 = isParentRemoved
57         }, { "Skip detaching $str1 from $str2 isTransfer=$bool1 isParentRemoved=$bool2" })
58     }
59 
60     fun logAttachingChild(key: String, parent: String, atIndex: Int) {
61         buffer.log(TAG, LogLevel.DEBUG, {
62             str1 = key
63             str2 = parent
64             int1 = atIndex
65         }, {
66             "Attaching view $str1 to $str2 at index $int1"
67         })
68     }
69 
70     fun logMovingChild(key: String, parent: String, toIndex: Int) {
71         buffer.log(TAG, LogLevel.DEBUG, {
72             str1 = key
73             str2 = parent
74             int1 = toIndex
75         }, {
76             "Moving child view $str1 in $str2 to index $int1"
77         })
78     }
79 
80     fun logDuplicateNodeInTree(node: NodeSpec, ex: RuntimeException) {
81         buffer.log(TAG, LogLevel.ERROR, {
82             str1 = ex.toString()
83             str2 = treeSpecToStr(node)
84         }, {
85             "$str1 when mapping tree: $str2"
86         })
87     }
88 }
89 
90 private const val TAG = "NotifViewManager"