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

Commit ea7040e3 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix potential overflow of launch event uptime

It was stored as integer for legacy MetricsLogger to log in seconds.
But since atom log uses it in milliseconds, it may be overflow if the
time is greater than 24 days. So now just store it in milliseconds
with long type and only covert to seconds for legacy logger.

Bug: 191610816
Test: atest ActivityMetricsLoggerTests

Change-Id: I3e40097fe7ce8e01d8495c1de2f1eafa855934a8
parent bdd8ff3f
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -206,8 +206,8 @@ class ActivityMetricsLogger {
         * observer to identify which callbacks belong to a launch event.
         */
        final long mTransitionStartTimeNs;
        /** The device uptime in seconds when this transition info is created. */
        final int mCurrentTransitionDeviceUptime;
        /** The device uptime in millis when this transition info is created. */
        final long mTransitionDeviceUptimeMs;
        /** The type can be cold (new process), warm (new activity), or hot (bring to front). */
        final int mTransitionType;
        /** Whether the process was already running when the transition started. */
@@ -277,8 +277,7 @@ class ActivityMetricsLogger {
            mTransitionType = transitionType;
            mProcessRunning = processRunning;
            mProcessSwitch = processSwitch;
            mCurrentTransitionDeviceUptime =
                    (int) TimeUnit.MILLISECONDS.toSeconds(launchingState.mCurrentUpTimeMs);
            mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs;
            setLatestLaunchedActivity(r);
            launchingState.mAssociatedTransitionInfo = this;
            if (options != null) {
@@ -908,7 +907,7 @@ class ActivityMetricsLogger {
        final TransitionInfoSnapshot infoSnapshot = new TransitionInfoSnapshot(info);
        if (info.isInterestingToLoggerAndObserver()) {
            mLoggerHandler.post(() -> logAppTransition(
                    info.mCurrentTransitionDeviceUptime, info.mCurrentTransitionDelayMs,
                    info.mTransitionDeviceUptimeMs, info.mCurrentTransitionDelayMs,
                    infoSnapshot, isHibernating));
        }
        mLoggerHandler.post(() -> logAppDisplayed(infoSnapshot));
@@ -920,7 +919,7 @@ class ActivityMetricsLogger {
    }

    // This gets called on another thread without holding the activity manager lock.
    private void logAppTransition(int currentTransitionDeviceUptime, int currentTransitionDelayMs,
    private void logAppTransition(long transitionDeviceUptimeMs, int currentTransitionDelayMs,
            TransitionInfoSnapshot info, boolean isHibernating) {
        final LogMaker builder = new LogMaker(APP_TRANSITION);
        builder.setPackageName(info.packageName);
@@ -937,7 +936,7 @@ class ActivityMetricsLogger {
        }
        builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, isInstantApp ? 1 : 0);
        builder.addTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS,
                currentTransitionDeviceUptime);
                TimeUnit.MILLISECONDS.toSeconds(transitionDeviceUptimeMs));
        builder.addTaggedData(APP_TRANSITION_DELAY_MS, currentTransitionDelayMs);
        builder.setSubtype(info.reason);
        if (info.startingWindowDelayMs != INVALID_DELAY) {
@@ -972,7 +971,7 @@ class ActivityMetricsLogger {
                info.launchedActivityName,
                info.launchedActivityLaunchedFromPackage,
                isInstantApp,
                currentTransitionDeviceUptime * 1000,
                transitionDeviceUptimeMs,
                info.reason,
                currentTransitionDelayMs,
                info.startingWindowDelayMs,