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

Commit 8f19fb3f authored by Darrell Shi's avatar Darrell Shi
Browse files

Improve dream logs.

This change adds/refactors the following logs around dreams:
- add/remove a dream complication
- show/hide a dream status bar item
- dream overlay active state changed
- low light mode active state changed
- assistant attention state changed
- status bar visible state changed
- available complication types changed
- should show complications state changed

Bug: 284167849
Fix: 284167849
Test: adb bugreport and verify logs are present
Change-Id: I3771c527e3cfd571bdae641a2fb6f49100191199
parent df271348
Loading
Loading
Loading
Loading
+19 −20
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.dreams;
import static com.android.systemui.dreams.dagger.DreamModule.DREAM_OVERLAY_ENABLED;

import android.service.dreams.DreamService;
import android.util.Log;

import androidx.annotation.NonNull;

@@ -52,7 +51,6 @@ import javax.inject.Named;
public class DreamOverlayStateController implements
        CallbackController<DreamOverlayStateController.Callback> {
    private static final String TAG = "DreamOverlayStateCtlr";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    public static final int STATE_DREAM_OVERLAY_ACTIVE = 1 << 0;
    public static final int STATE_LOW_LIGHT_ACTIVE = 1 << 1;
@@ -110,13 +108,17 @@ public class DreamOverlayStateController implements

    private final int mSupportedTypes;

    private final DreamLogger mLogger;

    @VisibleForTesting
    @Inject
    public DreamOverlayStateController(@Main Executor executor,
            @Named(DREAM_OVERLAY_ENABLED) boolean overlayEnabled,
            FeatureFlags featureFlags) {
            FeatureFlags featureFlags,
            DreamLogger dreamLogger) {
        mExecutor = executor;
        mOverlayEnabled = overlayEnabled;
        mLogger = dreamLogger;
        mFeatureFlags = featureFlags;
        if (mFeatureFlags.isEnabled(Flags.ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS)) {
            mSupportedTypes = Complication.COMPLICATION_TYPE_NONE
@@ -124,9 +126,7 @@ public class DreamOverlayStateController implements
        } else {
            mSupportedTypes = Complication.COMPLICATION_TYPE_NONE;
        }
        if (DEBUG) {
            Log.d(TAG, "Dream overlay enabled:" + mOverlayEnabled);
        }
        mLogger.d(TAG, "Dream overlay enabled: " + mOverlayEnabled);
    }

    /**
@@ -134,18 +134,14 @@ public class DreamOverlayStateController implements
     */
    public void addComplication(Complication complication) {
        if (!mOverlayEnabled) {
            if (DEBUG) {
                Log.d(TAG,
            mLogger.d(TAG,
                    "Ignoring adding complication due to overlay disabled: " + complication);
            }
            return;
        }

        mExecutor.execute(() -> {
            if (mComplications.add(complication)) {
                if (DEBUG) {
                    Log.d(TAG, "addComplication: added " + complication);
                }
                mLogger.d(TAG, "Added dream complication: " + complication);
                mCallbacks.stream().forEach(callback -> callback.onComplicationsChanged());
            }
        });
@@ -156,18 +152,14 @@ public class DreamOverlayStateController implements
     */
    public void removeComplication(Complication complication) {
        if (!mOverlayEnabled) {
            if (DEBUG) {
                Log.d(TAG,
            mLogger.d(TAG,
                    "Ignoring removing complication due to overlay disabled: " + complication);
            }
            return;
        }

        mExecutor.execute(() -> {
            if (mComplications.remove(complication)) {
                if (DEBUG) {
                    Log.d(TAG, "removeComplication: removed " + complication);
                }
                mLogger.d(TAG, "Removed dream complication: " + complication);
                mCallbacks.stream().forEach(callback -> callback.onComplicationsChanged());
            }
        });
@@ -313,6 +305,7 @@ public class DreamOverlayStateController implements
     * @param active {@code true} if overlay is active, {@code false} otherwise.
     */
    public void setOverlayActive(boolean active) {
        mLogger.d(TAG, "Dream overlay active: " + active);
        modifyState(active ? OP_SET_STATE : OP_CLEAR_STATE, STATE_DREAM_OVERLAY_ACTIVE);
    }

@@ -321,6 +314,8 @@ public class DreamOverlayStateController implements
     * @param active {@code true} if low light mode is active, {@code false} otherwise.
     */
    public void setLowLightActive(boolean active) {
        mLogger.d(TAG, "Low light mode active: " + active);

        if (isLowLightActive() && !active) {
            // Notify that we're exiting low light only on the transition from active to not active.
            mCallbacks.forEach(Callback::onExitLowLight);
@@ -351,6 +346,7 @@ public class DreamOverlayStateController implements
     * @param hasAttention {@code true} if has the user's attention, {@code false} otherwise.
     */
    public void setHasAssistantAttention(boolean hasAttention) {
        mLogger.d(TAG, "Dream overlay has Assistant attention: " + hasAttention);
        modifyState(hasAttention ? OP_SET_STATE : OP_CLEAR_STATE, STATE_HAS_ASSISTANT_ATTENTION);
    }

@@ -359,6 +355,7 @@ public class DreamOverlayStateController implements
     * @param visible {@code true} if the status bar is visible, {@code false} otherwise.
     */
    public void setDreamOverlayStatusBarVisible(boolean visible) {
        mLogger.d(TAG, "Dream overlay status bar visible: " + visible);
        modifyState(
                visible ? OP_SET_STATE : OP_CLEAR_STATE, STATE_DREAM_OVERLAY_STATUS_BAR_VISIBLE);
    }
@@ -376,6 +373,7 @@ public class DreamOverlayStateController implements
     */
    public void setAvailableComplicationTypes(@Complication.ComplicationType int types) {
        mExecutor.execute(() -> {
            mLogger.d(TAG, "Available complication types: " + types);
            mAvailableComplicationTypes = types;
            mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
        });
@@ -393,6 +391,7 @@ public class DreamOverlayStateController implements
     */
    public void setShouldShowComplications(boolean shouldShowComplications) {
        mExecutor.execute(() -> {
            mLogger.d(TAG, "Should show complications: " + shouldShowComplications);
            mShouldShowComplications = shouldShowComplications;
            mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
        });
+14 −0
Original line number Diff line number Diff line
@@ -141,6 +141,20 @@ public class DreamOverlayStatusBarView extends ConstraintLayout {
        mExtraSystemStatusViewGroup = findViewById(R.id.dream_overlay_extra_items);
    }

    protected static String getLoggableStatusIconType(@StatusIconType int type) {
        return switch (type) {
            case STATUS_ICON_NOTIFICATIONS -> "notifications";
            case STATUS_ICON_WIFI_UNAVAILABLE -> "wifi_unavailable";
            case STATUS_ICON_ALARM_SET -> "alarm_set";
            case STATUS_ICON_CAMERA_DISABLED -> "camera_disabled";
            case STATUS_ICON_MIC_DISABLED -> "mic_disabled";
            case STATUS_ICON_MIC_CAMERA_DISABLED -> "mic_camera_disabled";
            case STATUS_ICON_PRIORITY_MODE_ON -> "priority_mode_on";
            case STATUS_ICON_ASSISTANT_ATTENTION_ACTIVE -> "assistant_attention_active";
            default -> type + "(unknown)";
        };
    }

    void showIcon(@StatusIconType int iconType, boolean show, @Nullable String contentDescription) {
        View icon = mStatusIcons.get(iconType);
        if (icon == null) {
+8 −1
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ import javax.inject.Inject;
 */
@DreamOverlayComponent.DreamOverlayScope
public class DreamOverlayStatusBarViewController extends ViewController<DreamOverlayStatusBarView> {
    private static final String TAG = "DreamStatusBarCtrl";

    private final ConnectivityManager mConnectivityManager;
    private final TouchInsetManager.TouchInsetSession mTouchInsetSession;
    private final NextAlarmController mNextAlarmController;
@@ -78,6 +80,7 @@ public class DreamOverlayStatusBarViewController extends ViewController<DreamOve
    private final Executor mMainExecutor;
    private final List<DreamOverlayStatusBarItemsProvider.StatusBarItem> mExtraStatusBarItems =
            new ArrayList<>();
    private final DreamLogger mLogger;

    private boolean mIsAttached;

@@ -157,7 +160,8 @@ public class DreamOverlayStatusBarViewController extends ViewController<DreamOve
            StatusBarWindowStateController statusBarWindowStateController,
            DreamOverlayStatusBarItemsProvider statusBarItemsProvider,
            DreamOverlayStateController dreamOverlayStateController,
            UserTracker userTracker) {
            UserTracker userTracker,
            DreamLogger dreamLogger) {
        super(view);
        mResources = resources;
        mMainExecutor = mainExecutor;
@@ -173,6 +177,7 @@ public class DreamOverlayStatusBarViewController extends ViewController<DreamOve
        mZenModeController = zenModeController;
        mDreamOverlayStateController = dreamOverlayStateController;
        mUserTracker = userTracker;
        mLogger = dreamLogger;

        // Register to receive show/hide updates for the system status bar. Our custom status bar
        // needs to hide when the system status bar is showing to ovoid overlapping status bars.
@@ -341,6 +346,8 @@ public class DreamOverlayStatusBarViewController extends ViewController<DreamOve
            @Nullable String contentDescription) {
        mMainExecutor.execute(() -> {
            if (mIsAttached) {
                mLogger.d(TAG, (show ? "Showing" : "Hiding") + " dream status bar item: "
                        + DreamOverlayStatusBarView.getLoggableStatusIconType(iconType));
                mView.showIcon(iconType, show, contentDescription);
            }
        });
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.lifecycle.Observer;
import androidx.test.filters.SmallTest;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.dreams.DreamLogger;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.flags.FakeFeatureFlags;
import com.android.systemui.flags.Flags;
@@ -56,6 +57,8 @@ public class ComplicationCollectionLiveDataTest extends SysuiTestCase {
    private FakeFeatureFlags mFeatureFlags;
    @Mock
    private Observer mObserver;
    @Mock
    private DreamLogger mLogger;

    @Before
    public void setUp() {
@@ -66,7 +69,8 @@ public class ComplicationCollectionLiveDataTest extends SysuiTestCase {
        mStateController = new DreamOverlayStateController(
                mExecutor,
                /* overlayEnabled= */ true,
                mFeatureFlags);
                mFeatureFlags,
                mLogger);
        mLiveData = new ComplicationCollectionLiveData(mStateController);
    }

+4 −1
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
    @Mock
    private FeatureFlags mFeatureFlags;

    @Mock
    private DreamLogger mLogger;

    final FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());

    @Before
@@ -405,6 +408,6 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
    }

    private DreamOverlayStateController getDreamOverlayStateController(boolean overlayEnabled) {
        return new DreamOverlayStateController(mExecutor, overlayEnabled, mFeatureFlags);
        return new DreamOverlayStateController(mExecutor, overlayEnabled, mFeatureFlags, mLogger);
    }
}
Loading