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

Commit 0c436f5e authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

Add dream component name to dream start/stop events logging.

In order to add the additional information, created dedicated
DreamUIEventLogger and moved the DREAM_START/STOP events in there.

Android Metrics Design Review: eldar/189451700.

Bug: 213906448
Test: Manually on device via `statsd_testdrive `
Change-Id: I37f4d70e5dd0bd2c516ef49b8f11c61530db6101
parent fd351e74
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2403,6 +2403,9 @@
    <!-- Limit of how long the device can remain unlocked due to attention checking.  -->
    <integer name="config_attentionMaximumExtension">900000</integer> <!-- 15 minutes.  -->

    <!-- The prefix of dream component names that are loggable. If empty, logs "other" for all. -->
    <string name ="config_loggable_dream_prefix" translatable="false"></string>

    <!-- ComponentName of a dream to show whenever the system would otherwise have
         gone to sleep.  When the PowerManager is asked to go to sleep, it will instead
         try to start this dream if possible.  The dream should typically call startDozing()
+1 −0
Original line number Diff line number Diff line
@@ -2237,6 +2237,7 @@
  <java-symbol type="array" name="config_supportedDreamComplications" />
  <java-symbol type="array" name="config_dreamComplicationsEnabledByDefault" />
  <java-symbol type="array" name="config_disabledDreamComponents" />
  <java-symbol type="string" name="config_loggable_dream_prefix" />
  <java-symbol type="string" name="config_dozeComponent" />
  <java-symbol type="string" name="enable_explore_by_touch_warning_title" />
  <java-symbol type="string" name="enable_explore_by_touch_warning_message" />
+12 −24
Original line number Diff line number Diff line
@@ -47,8 +47,7 @@ import android.service.dreams.IDreamManager;
import android.util.Slog;
import android.view.Display;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEvent;
import com.android.internal.R;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.util.DumpUtils;
@@ -82,6 +81,7 @@ public final class DreamManagerService extends SystemService {
    private final PowerManager.WakeLock mDozeWakeLock;
    private final ActivityTaskManagerInternal mAtmInternal;
    private final UiEventLogger mUiEventLogger;
    private final DreamUiEventLogger mDreamUiEventLogger;
    private final ComponentName mAmbientDisplayComponent;

    private Binder mCurrentDreamToken;
@@ -99,26 +99,6 @@ public final class DreamManagerService extends SystemService {

    private AmbientDisplayConfiguration mDozeConfig;

    @VisibleForTesting
    public enum DreamManagerEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "The screensaver has started.")
        DREAM_START(577),

        @UiEvent(doc = "The screensaver has stopped.")
        DREAM_STOP(578);

        private final int mId;

        DreamManagerEvent(int id) {
            mId = id;
        }

        @Override
        public int getId() {
            return mId;
        }
    }

    public DreamManagerService(Context context) {
        super(context);
        mContext = context;
@@ -131,6 +111,8 @@ public final class DreamManagerService extends SystemService {
        mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, TAG);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        mUiEventLogger = new UiEventLoggerImpl();
        mDreamUiEventLogger = new DreamUiEventLoggerImpl(
                mContext.getResources().getString(R.string.config_loggable_dream_prefix));
        AmbientDisplayConfiguration adc = new AmbientDisplayConfiguration(mContext);
        mAmbientDisplayComponent = ComponentName.unflattenFromString(adc.ambientDisplayComponent());
    }
@@ -417,7 +399,10 @@ public final class DreamManagerService extends SystemService {
        mCurrentDreamUserId = userId;

        if (!mCurrentDreamName.equals(mAmbientDisplayComponent)) {
            mUiEventLogger.log(DreamManagerEvent.DREAM_START);
            // TODO(b/213906448): Remove when metrics based on new atom are fully rolled out.
            mUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_START);
            mDreamUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_START,
                    mCurrentDreamName.flattenToString());
        }

        PowerManager.WakeLock wakeLock = mPowerManager
@@ -453,7 +438,10 @@ public final class DreamManagerService extends SystemService {

    private void cleanupDreamLocked() {
        if (!mCurrentDreamName.equals(mAmbientDisplayComponent)) {
            mUiEventLogger.log(DreamManagerEvent.DREAM_STOP);
            // TODO(b/213906448): Remove when metrics based on new atom are fully rolled out.
            mUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_STOP);
            mDreamUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_STOP,
                    mCurrentDreamName.flattenToString());
        }
        mCurrentDreamToken = null;
        mCurrentDreamName = null;
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.server.dreams;

import android.annotation.NonNull;

import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;

/**
 * Logging interface for Dream UI events. Normal implementation is DreamUiEventLoggerImpl.
 *
 * See DreamUiEventReported atom in atoms.proto for more context.
 * @hide
 */
public interface DreamUiEventLogger {
    /** Put your Event IDs in enums that implement this interface, and document them using the
     * UiEventEnum annotation.
     * Event IDs must be globally unique. This will be enforced by tooling (forthcoming).
     * OEMs should use event IDs above 100000 and below 1000000 (1 million).
     */
    enum DreamUiEventEnum implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "The screensaver has started.")
        DREAM_START(577),

        @UiEvent(doc = "The screensaver has stopped.")
        DREAM_STOP(578);

        private final int mId;

        DreamUiEventEnum(int id) {
            mId = id;
        }

        @Override
        public int getId() {
            return mId;
        }
    }

    /**
     * Log a simple event with dream component name, with no package information. Does nothing if
     * event.getId() <= 0.
     * @param event an enum implementing UiEventEnum interface.
     * @param dreamComponentName the component name of the dream in use.
     */
    void log(@NonNull UiEventLogger.UiEventEnum event, @NonNull String dreamComponentName);
}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.server.dreams;

import com.android.internal.logging.UiEventLogger;
import com.android.internal.util.FrameworkStatsLog;

/**
 * Standard implementation of DreamUiEventLogger, writing to FrameworkStatsLog.
 *
 * See DreamUiEventReported atom in atoms.proto for more context.
 * @hide
 */
public class DreamUiEventLoggerImpl implements DreamUiEventLogger {
    final String mLoggableDreamPrefix;

    DreamUiEventLoggerImpl(String loggableDreamPrefix) {
        mLoggableDreamPrefix = loggableDreamPrefix;
    }

    @Override
    public void log(UiEventLogger.UiEventEnum event, String dreamComponentName) {
        final int eventID = event.getId();
        if (eventID <= 0) {
            return;
        }
        final boolean isFirstPartyDream =
                mLoggableDreamPrefix.isEmpty() ? false : dreamComponentName.startsWith(
                        mLoggableDreamPrefix);
        FrameworkStatsLog.write(FrameworkStatsLog.DREAM_UI_EVENT_REPORTED,
                /* uid = 1 */ 0,
                /* event_id = 2 */ eventID,
                /* instance_id = 3 */ 0,
                /* dream_component_name = 4 */ isFirstPartyDream ? dreamComponentName : "other");
    }
}