Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d21cdc21 authored by Sukesh Ram's avatar Sukesh Ram
Browse files

Add navigation bar/secondary handle visibility logs

Add a historical log for when navigation bar and secondary handle are rendered or have their visibility changed using log buffers to capture and dump this data for debugging purposes. Additional information includes: log’s caller method, navbar/secondary handle visibility, immersive mode status.

Flag: NONE
Test: Manually tested in pixel 7. Check output after running "adb shell dumpsys activity service SystemUIAuxiliaryDumpService" in the terminal.
Bug: 311932306
Change-Id: I7de39d8aa0eda249aa7cccfa228c2376bcde9e43
parent 2fd19818
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -637,4 +637,11 @@ public class LogModule {
        return factory.create("NavBarButtonClick", 50);
    }

    /** Provides a {@link LogBuffer} for NavBar Orientation Tracking. */
    @Provides
    @SysUISingleton
    @NavbarOrientationTrackingLog
    public static LogBuffer provideNavbarOrientationTrackingLogBuffer(LogBufferFactory factory) {
        return factory.create("NavbarOrientationTrackingLog", 50);
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.log.dagger;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.android.systemui.log.LogBuffer;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

/** A {@link LogBuffer} for {@link com.android.systemui.navigationbar.NavigationBar}. */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface NavbarOrientationTrackingLog {
}
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.navigationbar

import android.view.Surface
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.NavbarOrientationTrackingLog
import javax.inject.Inject

class NavbarOrientationTrackingLogger
@Inject
constructor(@NavbarOrientationTrackingLog private val buffer: LogBuffer) {
    fun logPrimaryAndSecondaryVisibility(
        methodName: String,
        isViewVisible: Boolean,
        isImmersiveMode: Boolean,
        isSecondaryHandleVisible: Boolean,
        currentRotation: Int,
        startingQuickSwitchRotation: Int
    ) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = methodName
                bool1 = isViewVisible
                bool2 = isImmersiveMode
                bool3 = isSecondaryHandleVisible
                int1 = startingQuickSwitchRotation
                int2 = currentRotation
            },
            {
                "Caller Method: $str1\n" +
                    "\tNavbar Visible: $bool1\n" +
                    "\tImmersive Mode: $bool2\n" +
                    "\tSecondary Handle Visible: $bool3\n" +
                    "\tDelta Rotation: ${getDeltaRotation(int1, int2)}\n" +
                    "\tStarting QuickSwitch Rotation: $int1\n" +
                    "\tCurrent Rotation: $int2\n"
            }
        )
    }

    private fun getDeltaRotation(oldRotation: Int, newRotation: Int): String {
        var rotation: String = "0"
        when (deltaRotation(oldRotation, newRotation)) {
            Surface.ROTATION_90 -> {
                rotation = "90"
            }
            Surface.ROTATION_180 -> {
                rotation = "180"
            }
            Surface.ROTATION_270 -> {
                rotation = "270"
            }
        }
        return rotation
    }

    private fun deltaRotation(oldRotation: Int, newRotation: Int): Int {
        var delta = newRotation - oldRotation
        if (delta < 0) delta += 4
        return delta
    }
}

private const val TAG = "NavbarOrientationTracking"
+21 −1
Original line number Diff line number Diff line
@@ -282,6 +282,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
    private final Rect mSamplingBounds = new Rect();
    private final Binder mInsetsSourceOwner = new Binder();
    private final NavBarButtonClickLogger mNavBarButtonClickLogger;
    private final NavbarOrientationTrackingLogger mNavbarOrientationTrackingLogger;

    /**
     * When quickswitching between apps of different orientations, we draw a secondary home handle
@@ -557,7 +558,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
            WakefulnessLifecycle wakefulnessLifecycle,
            TaskStackChangeListeners taskStackChangeListeners,
            DisplayTracker displayTracker,
            NavBarButtonClickLogger navBarButtonClickLogger) {
            NavBarButtonClickLogger navBarButtonClickLogger,
            NavbarOrientationTrackingLogger navbarOrientationTrackingLogger) {
        super(navigationBarView);
        mFrame = navigationBarFrame;
        mContext = context;
@@ -600,6 +602,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        mDisplayTracker = displayTracker;
        mEdgeBackGestureHandler = navBarHelper.getEdgeBackGestureHandler();
        mNavBarButtonClickLogger = navBarButtonClickLogger;
        mNavbarOrientationTrackingLogger = navbarOrientationTrackingLogger;

        mNavColorSampleMargin = getResources()
                .getDimensionPixelSize(R.dimen.navigation_handle_sample_horizontal_margin);
@@ -906,6 +909,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
                | WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
        mWindowManager.addView(mOrientationHandle, mOrientationParams);
        mOrientationHandle.setVisibility(View.GONE);

        logNavbarOrientation("initSecondaryHomeHandleForRotation");
        mOrientationParams.setFitInsetsTypes(0 /* types*/);
        mOrientationHandleGlobalLayoutListener =
                () -> {
@@ -966,6 +971,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        mWindowManager.updateViewLayout(mOrientationHandle, mOrientationParams);
        mView.setVisibility(View.GONE);
        mOrientationHandle.setVisibility(View.VISIBLE);
        logNavbarOrientation("orientSecondaryHomeHandle");
    }

    private void resetSecondaryHandle() {
@@ -975,9 +981,23 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
            mOrientationHandle.setVisibility(View.GONE);
        }
        mView.setVisibility(View.VISIBLE);
        logNavbarOrientation("resetSecondaryHandle");
        setOrientedHandleSamplingRegion(null);
    }

    /**
     * Logging method for issues concerning Navbar/secondary handle visibility.
     */
    private void logNavbarOrientation(String methodName) {
        boolean isViewVisible = (mView != null) && (mView.getVisibility() == View.VISIBLE);
        boolean isSecondaryHandleVisible =
                (mOrientationHandle != null) && (mOrientationHandle.getVisibility()
                        == View.VISIBLE);
        mNavbarOrientationTrackingLogger.logPrimaryAndSecondaryVisibility(methodName, isViewVisible,
                mShowOrientedHandleForImmersiveMode, isSecondaryHandleVisible, mCurrentRotation,
                mStartingQuickSwitchRotation);
    }

    private void parseCurrentSysuiState() {
        NavBarHelper.CurrentSysuiState state = mNavBarHelper.getCurrentSysuiState();
        if (state.mWindowStateDisplayId == mDisplayId) {
+4 −1
Original line number Diff line number Diff line
@@ -184,6 +184,8 @@ public class NavigationBarTest extends SysuiTestCase {
    @Mock
    private NavBarButtonClickLogger mNavBarButtonClickLogger;
    @Mock
    private NavbarOrientationTrackingLogger mNavbarOrientationTrackingLogger;
    @Mock
    private ViewTreeObserver mViewTreeObserver;
    NavBarHelper mNavBarHelper;
    @Mock
@@ -599,7 +601,8 @@ public class NavigationBarTest extends SysuiTestCase {
                mWakefulnessLifecycle,
                mTaskStackChangeListeners,
                new FakeDisplayTracker(mContext),
                mNavBarButtonClickLogger));
                mNavBarButtonClickLogger,
                mNavbarOrientationTrackingLogger));
    }

    private void processAllMessages() {