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

Commit 1d716b29 authored by Will Brockman's avatar Will Brockman
Browse files

De-contextify volume/Events MetricsLogger calls.

A small cleanup - replace calls to MetricsLogger's deprecated static
methods with calls to the member functions of the logger instance that
the code was already constructing.  This makes the Context argument of
Events.writeEvent() unnecessary, so removed that as well.

Test: atest SystemUITests
Test: mp droid + manually verify MetricsLogger logging.

Change-Id: I8ca380ca56f51c414c17858dfd5b932ba02d4df0
parent 3ef13e04
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        mShowing = true;
        clearAllAndSetupDefaultCarVolumeLineItem(mCurrentlyDisplayingGroupId);
        mDialog.show();
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
        Events.writeEvent(Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
    }

    private void clearAllAndSetupDefaultCarVolumeLineItem(int groupId) {
@@ -349,7 +349,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                }, DISMISS_DELAY_IN_MILLIS))
                .start();

        Events.writeEvent(mContext, Events.EVENT_DISMISS_DIALOG, reason);
        Events.writeEvent(Events.EVENT_DISMISS_DIALOG, reason);
    }

    private void loadAudioUsageItems() {
+2 −2
Original line number Diff line number Diff line
@@ -476,7 +476,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
                });
        d.setOnDismissListener(dialogInterface -> {
            mUsbHighTempDialog = null;
            Events.writeEvent(mContext, Events.EVENT_DISMISS_USB_OVERHEAT_ALARM,
            Events.writeEvent(Events.EVENT_DISMISS_USB_OVERHEAT_ALARM,
                    Events.DISMISS_REASON_USB_OVERHEAD_ALARM_CHANGED,
                    mKeyguard.isKeyguardLocked());
        });
@@ -485,7 +485,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
        d.show();
        mUsbHighTempDialog = d;

        Events.writeEvent(mContext, Events.EVENT_SHOW_USB_OVERHEAT_ALARM,
        Events.writeEvent(Events.EVENT_SHOW_USB_OVERHEAT_ALARM,
                Events.SHOW_REASON_USB_OVERHEAD_ALARM_CHANGED,
                mKeyguard.isKeyguardLocked());
    }
+20 −15
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.volume;

import android.content.Context;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.provider.Settings.Global;
@@ -125,7 +124,12 @@ public class Events {

    public static Callback sCallback;

    public static void writeEvent(Context context, int tag, Object... list) {
    /**
     * Logs an event to the system log and the event log.
     * @param tag One of the EVENT_* codes above.
     * @param list Any additional event-specific arguments, documented above.
     */
    public static void writeEvent(int tag, Object... list) {
        MetricsLogger logger = new MetricsLogger();
        final long time = System.currentTimeMillis();
        final StringBuilder sb = new StringBuilder("writeEvent ").append(EVENT_TAGS[tag]);
@@ -133,33 +137,33 @@ public class Events {
            sb.append(" ");
            switch (tag) {
                case EVENT_SHOW_DIALOG:
                    MetricsLogger.visible(context, MetricsEvent.VOLUME_DIALOG);
                    MetricsLogger.histogram(context, "volume_from_keyguard",
                    logger.visible(MetricsEvent.VOLUME_DIALOG);
                    logger.histogram("volume_from_keyguard",
                            (Boolean) list[1] ? 1 : 0);
                    sb.append(SHOW_REASONS[(Integer) list[0]]).append(" keyguard=").append(list[1]);
                    break;
                case EVENT_EXPAND:
                    MetricsLogger.visibility(context, MetricsEvent.VOLUME_DIALOG_DETAILS,
                    logger.visibility(MetricsEvent.VOLUME_DIALOG_DETAILS,
                            (Boolean) list[0]);
                    sb.append(list[0]);
                    break;
                case EVENT_DISMISS_DIALOG:
                    MetricsLogger.hidden(context, MetricsEvent.VOLUME_DIALOG);
                    logger.hidden(MetricsEvent.VOLUME_DIALOG);
                    sb.append(DISMISS_REASONS[(Integer) list[0]]);
                    break;
                case EVENT_ACTIVE_STREAM_CHANGED:
                    MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_STREAM,
                    logger.action(MetricsEvent.ACTION_VOLUME_STREAM,
                            (Integer) list[0]);
                    sb.append(AudioSystem.streamToString((Integer) list[0]));
                    break;
                case EVENT_ICON_CLICK:
                    MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_ICON,
                    logger.action(MetricsEvent.ACTION_VOLUME_ICON,
                            (Integer) list[0]);
                    sb.append(AudioSystem.streamToString((Integer) list[0])).append(' ')
                            .append(iconStateToString((Integer) list[1]));
                    break;
                case EVENT_TOUCH_LEVEL_DONE:
                    MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_SLIDER,
                    logger.action(MetricsEvent.ACTION_VOLUME_SLIDER,
                            (Integer) list[1]);
                    // fall through
                case EVENT_TOUCH_LEVEL_CHANGED:
@@ -169,7 +173,7 @@ public class Events {
                            .append(list[1]);
                    break;
                case EVENT_KEY:
                    MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_KEY,
                    logger.action(MetricsEvent.ACTION_VOLUME_KEY,
                            (Integer) list[0]);
                    sb.append(AudioSystem.streamToString((Integer) list[0])).append(' ')
                            .append(list[1]);
@@ -181,7 +185,7 @@ public class Events {
                    logger.action(MetricsEvent.ACTION_VOLUME_SETTINGS);
                    break;
                case EVENT_EXTERNAL_RINGER_MODE_CHANGED:
                    MetricsLogger.action(context, MetricsEvent.ACTION_RINGER_MODE,
                    logger.action(MetricsEvent.ACTION_RINGER_MODE,
                            (Integer) list[0]);
                    // fall through
                case EVENT_INTERNAL_RINGER_MODE_CHANGED:
@@ -194,14 +198,14 @@ public class Events {
                    sb.append(list[0]).append(' ').append(list[1]);
                    break;
                case EVENT_SHOW_USB_OVERHEAT_ALARM:
                    MetricsLogger.visible(context, MetricsEvent.POWER_OVERHEAT_ALARM);
                    MetricsLogger.histogram(context, "show_usb_overheat_alarm",
                    logger.visible(MetricsEvent.POWER_OVERHEAT_ALARM);
                    logger.histogram("show_usb_overheat_alarm",
                            (Boolean) list[1] ? 1 : 0);
                    sb.append(SHOW_REASONS[(Integer) list[0]]).append(" keyguard=").append(list[1]);
                    break;
                case EVENT_DISMISS_USB_OVERHEAT_ALARM:
                    MetricsLogger.hidden(context, MetricsEvent.POWER_OVERHEAT_ALARM);
                    MetricsLogger.histogram(context, "dismiss_usb_overheat_alarm",
                    logger.hidden(MetricsEvent.POWER_OVERHEAT_ALARM);
                    logger.histogram("dismiss_usb_overheat_alarm",
                            (Boolean) list[1] ? 1 : 0);
                    sb.append(DISMISS_REASONS[(Integer) list[0]])
                        .append(" keyguard=").append(list[1]);
@@ -255,4 +259,5 @@ public class Events {
        void writeEvent(long time, int tag, Object[] list);
        void writeState(long time, State state);
    }

}
+13 −13
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        mStatusBarOptionalLazy = statusBarOptionalLazy;
        mNotificationManager = (NotificationManager) mContext.getSystemService(
                Context.NOTIFICATION_SERVICE);
        Events.writeEvent(mContext, Events.EVENT_COLLECTION_STARTED);
        Events.writeEvent(Events.EVENT_COLLECTION_STARTED);
        mWorkerThread = new HandlerThread(VolumeDialogControllerImpl.class.getSimpleName());
        mWorkerThread.start();
        mWorker = new W(mWorkerThread.getLooper());
@@ -237,7 +237,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        if (D.BUG) Log.d(TAG, "destroy");
        if (mDestroyed) return;
        mDestroyed = true;
        Events.writeEvent(mContext, Events.EVENT_COLLECTION_STOPPED);
        Events.writeEvent(Events.EVENT_COLLECTION_STOPPED);
        mMediaSessions.destroy();
        mObserver.destroy();
        mReceiver.destroy();
@@ -487,7 +487,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
            mCallbacks.onShowSilentHint();
        }
        if (changed && fromKey) {
            Events.writeEvent(mContext, Events.EVENT_KEY, stream, lastAudibleStreamVolume);
            Events.writeEvent(Events.EVENT_KEY, stream, lastAudibleStreamVolume);
        }
        return changed;
    }
@@ -495,7 +495,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
    private boolean updateActiveStreamW(int activeStream) {
        if (activeStream == mState.activeStream) return false;
        mState.activeStream = activeStream;
        Events.writeEvent(mContext, Events.EVENT_ACTIVE_STREAM_CHANGED, activeStream);
        Events.writeEvent(Events.EVENT_ACTIVE_STREAM_CHANGED, activeStream);
        if (D.BUG) Log.d(TAG, "updateActiveStreamW " + activeStream);
        final int s = activeStream < DYNAMIC_STREAM_START_INDEX ? activeStream : -1;
        if (D.BUG) Log.d(TAG, "forceVolumeControlStream " + s);
@@ -544,7 +544,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        if (ss.level == level) return false;
        ss.level = level;
        if (isLogWorthy(stream)) {
            Events.writeEvent(mContext, Events.EVENT_LEVEL_CHANGED, stream, level);
            Events.writeEvent(Events.EVENT_LEVEL_CHANGED, stream, level);
        }
        return true;
    }
@@ -567,7 +567,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        if (ss.muted == muted) return false;
        ss.muted = muted;
        if (isLogWorthy(stream)) {
            Events.writeEvent(mContext, Events.EVENT_MUTE_CHANGED, stream, muted);
            Events.writeEvent(Events.EVENT_MUTE_CHANGED, stream, muted);
        }
        if (muted && isRinger(stream)) {
            updateRingerModeInternalW(mAudio.getRingerModeInternal());
@@ -583,7 +583,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        if (Objects.equals(mState.effectsSuppressor, effectsSuppressor)) return false;
        mState.effectsSuppressor = effectsSuppressor;
        mState.effectsSuppressorName = getApplicationName(mContext, mState.effectsSuppressor);
        Events.writeEvent(mContext, Events.EVENT_SUPPRESSOR_CHANGED, mState.effectsSuppressor,
        Events.writeEvent(Events.EVENT_SUPPRESSOR_CHANGED, mState.effectsSuppressor,
                mState.effectsSuppressorName);
        return true;
    }
@@ -607,7 +607,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
                Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_OFF);
        if (mState.zenMode == zen) return false;
        mState.zenMode = zen;
        Events.writeEvent(mContext, Events.EVENT_ZEN_MODE_CHANGED, zen);
        Events.writeEvent(Events.EVENT_ZEN_MODE_CHANGED, zen);
        return true;
    }

@@ -633,23 +633,23 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        mState.disallowMedia = disallowMedia;
        mState.disallowSystem = disallowSystem;
        mState.disallowRinger = disallowRinger;
        Events.writeEvent(mContext, Events.EVENT_ZEN_CONFIG_CHANGED, "disallowAlarms=" +
                disallowAlarms + " disallowMedia=" + disallowMedia + " disallowSystem=" +
                disallowSystem + " disallowRinger=" + disallowRinger);
        Events.writeEvent(Events.EVENT_ZEN_CONFIG_CHANGED, "disallowAlarms="
                + disallowAlarms + " disallowMedia=" + disallowMedia + " disallowSystem="
                + disallowSystem + " disallowRinger=" + disallowRinger);
        return true;
    }

    private boolean updateRingerModeExternalW(int rm) {
        if (rm == mState.ringerModeExternal) return false;
        mState.ringerModeExternal = rm;
        Events.writeEvent(mContext, Events.EVENT_EXTERNAL_RINGER_MODE_CHANGED, rm);
        Events.writeEvent(Events.EVENT_EXTERNAL_RINGER_MODE_CHANGED, rm);
        return true;
    }

    private boolean updateRingerModeInternalW(int rm) {
        if (rm == mState.ringerModeInternal) return false;
        mState.ringerModeInternal = rm;
        Events.writeEvent(mContext, Events.EVENT_INTERNAL_RINGER_MODE_CHANGED, rm);
        Events.writeEvent(Events.EVENT_INTERNAL_RINGER_MODE_CHANGED, rm);

        if (mState.ringerModeInternal == RINGER_MODE_NORMAL) {
            playTouchFeedback();
+9 −9
Original line number Diff line number Diff line
@@ -429,7 +429,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        row.icon.setImageResource(iconRes);
        if (row.stream != AudioSystem.STREAM_ACCESSIBILITY) {
            row.icon.setOnClickListener(v -> {
                Events.writeEvent(mContext, Events.EVENT_ICON_CLICK, row.stream, row.iconState);
                Events.writeEvent(Events.EVENT_ICON_CLICK, row.stream, row.iconState);
                mController.setActiveStream(row.stream);
                if (row.stream == AudioManager.STREAM_RING) {
                    final boolean hasVibrator = mController.hasVibrator();
@@ -468,7 +468,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        }
        if (mSettingsIcon != null) {
            mSettingsIcon.setOnClickListener(v -> {
                Events.writeEvent(mContext, Events.EVENT_SETTINGS_CLICK);
                Events.writeEvent(Events.EVENT_SETTINGS_CLICK);
                Intent intent = new Intent(Settings.Panel.ACTION_VOLUME);
                dismissH(DISMISS_REASON_SETTINGS_CLICKED);
                Dependency.get(ActivityStarter.class).startActivity(intent,
@@ -504,7 +504,7 @@ public class VolumeDialogImpl implements VolumeDialog,
                        mController.setStreamVolume(AudioManager.STREAM_RING, 1);
                    }
                }
                Events.writeEvent(mContext, Events.EVENT_RINGER_TOGGLE, newRingerMode);
                Events.writeEvent(Events.EVENT_RINGER_TOGGLE, newRingerMode);
                incrementManualToggleCount();
                updateRingerH();
                provideTouchFeedbackH(newRingerMode);
@@ -519,7 +519,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        if (mODICaptionsIcon != null) {
            mODICaptionsIcon.setOnConfirmedTapListener(() -> {
                onCaptionIconClicked();
                Events.writeEvent(mContext, Events.EVENT_ODI_CAPTIONS_CLICK);
                Events.writeEvent(Events.EVENT_ODI_CAPTIONS_CLICK);
            }, mHandler);
        }

@@ -541,7 +541,7 @@ public class VolumeDialogImpl implements VolumeDialog,
            mODICaptionsTooltipView = mODICaptionsTooltipViewStub.inflate();
            mODICaptionsTooltipView.findViewById(R.id.dismiss).setOnClickListener(v -> {
                hideCaptionsTooltip();
                Events.writeEvent(mContext, Events.EVENT_ODI_CAPTIONS_TOOLTIP_CLICK);
                Events.writeEvent(Events.EVENT_ODI_CAPTIONS_TOOLTIP_CLICK);
            });
            mODICaptionsTooltipViewStub = null;
            rescheduleTimeoutH();
@@ -694,7 +694,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        initSettingsH();
        mShowing = true;
        mDialog.show();
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
        Events.writeEvent(Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
        mController.notifyVisible(true);
        mController.getCaptionsComponentState(false);
        checkODICaptionsTooltip(false);
@@ -741,7 +741,7 @@ public class VolumeDialogImpl implements VolumeDialog,
        if (mShowing) {
            mShowing = false;
            // Only logs when the volume dialog visibility is changed.
            Events.writeEvent(mContext, Events.EVENT_DISMISS_DIALOG, reason);
            Events.writeEvent(Events.EVENT_DISMISS_DIALOG, reason);
        }
        mDialogView.setTranslationX(0);
        mDialogView.setAlpha(1);
@@ -1400,7 +1400,7 @@ public class VolumeDialogImpl implements VolumeDialog,
                    mController.setActiveStream(mRow.stream);
                    mController.setStreamVolume(mRow.stream, userLevel);
                    mRow.requestedLevel = userLevel;
                    Events.writeEvent(mContext, Events.EVENT_TOUCH_LEVEL_CHANGED, mRow.stream,
                    Events.writeEvent(Events.EVENT_TOUCH_LEVEL_CHANGED, mRow.stream,
                            userLevel);
                }
            }
@@ -1419,7 +1419,7 @@ public class VolumeDialogImpl implements VolumeDialog,
            mRow.tracking = false;
            mRow.userAttempt = SystemClock.uptimeMillis();
            final int userLevel = getImpliedLevel(seekBar, seekBar.getProgress());
            Events.writeEvent(mContext, Events.EVENT_TOUCH_LEVEL_DONE, mRow.stream, userLevel);
            Events.writeEvent(Events.EVENT_TOUCH_LEVEL_DONE, mRow.stream, userLevel);
            if (mRow.ss.level != userLevel) {
                mHandler.sendMessageDelayed(mHandler.obtainMessage(H.RECHECK, mRow),
                        USER_ATTEMPT_GRACE_PERIOD);