1 /*
2  * Copyright (C) 2024 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.navigationbar
18 
19 import android.view.Surface
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
22 import com.android.systemui.log.dagger.NavbarOrientationTrackingLog
23 import javax.inject.Inject
24 
25 class NavbarOrientationTrackingLogger
26 @Inject
27 constructor(@NavbarOrientationTrackingLog private val buffer: LogBuffer) {
logPrimaryAndSecondaryVisibilitynull28     fun logPrimaryAndSecondaryVisibility(
29         methodName: String,
30         isViewVisible: Boolean,
31         isImmersiveMode: Boolean,
32         isSecondaryHandleVisible: Boolean,
33         currentRotation: Int,
34         startingQuickSwitchRotation: Int
35     ) {
36         buffer.log(
37             TAG,
38             LogLevel.DEBUG,
39             {
40                 str1 = methodName
41                 bool1 = isViewVisible
42                 bool2 = isImmersiveMode
43                 bool3 = isSecondaryHandleVisible
44                 int1 = startingQuickSwitchRotation
45                 int2 = currentRotation
46             },
47             {
48                 "Caller Method: $str1\n" +
49                     "\tNavbar Visible: $bool1\n" +
50                     "\tImmersive Mode: $bool2\n" +
51                     "\tSecondary Handle Visible: $bool3\n" +
52                     "\tDelta Rotation: ${getDeltaRotation(int1, int2)}\n" +
53                     "\tStarting QuickSwitch Rotation: $int1\n" +
54                     "\tCurrent Rotation: $int2\n"
55             }
56         )
57     }
58 
getDeltaRotationnull59     private fun getDeltaRotation(oldRotation: Int, newRotation: Int): String {
60         var rotation: String = "0"
61         when (deltaRotation(oldRotation, newRotation)) {
62             Surface.ROTATION_90 -> {
63                 rotation = "90"
64             }
65             Surface.ROTATION_180 -> {
66                 rotation = "180"
67             }
68             Surface.ROTATION_270 -> {
69                 rotation = "270"
70             }
71         }
72         return rotation
73     }
74 
deltaRotationnull75     private fun deltaRotation(oldRotation: Int, newRotation: Int): Int {
76         var delta = newRotation - oldRotation
77         if (delta < 0) delta += 4
78         return delta
79     }
80 }
81 
82 private const val TAG = "NavbarOrientationTracking"
83