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

Commit ebf2ce16 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "MediaMetrics: Retain previous audio state a limited time." into rvc-dev am: f3f98cc2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/11931279

Change-Id: I2e4c16b8c7c6a5637e7195b221611393dc924a70
parents 7224614a f3f98cc2
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ auto ENUM_EXTRACT(const T& x) {

static constexpr const auto LOG_LEVEL = android::base::VERBOSE;

static constexpr int PREVIOUS_STATE_EXPIRE_SEC = 60 * 60; // 1 hour.

/*
 * For logging purposes, we list all of the MediaMetrics atom fields,
 * which can then be associated with consecutive arguments to the statsd write.
@@ -173,6 +175,19 @@ AudioAnalytics::AudioAnalytics()
                // to end of full expression.
                mAnalyticsState->clear();  // TODO: filter the analytics state.
                // Perhaps report this.

                // Set up a timer to expire the previous audio state to save space.
                // Use the transaction log size as a cookie to see if it is the
                // same as before.  A benign race is possible where a state is cleared early.
                const size_t size = mPreviousAnalyticsState->transactionLog().size();
                mTimedAction.postIn(
                        std::chrono::seconds(PREVIOUS_STATE_EXPIRE_SEC), [this, size](){
                    if (mPreviousAnalyticsState->transactionLog().size() == size) {
                        ALOGD("expiring previous audio state after %d seconds.",
                                PREVIOUS_STATE_EXPIRE_SEC);
                        mPreviousAnalyticsState->clear();  // removes data from the state.
                    }
                });
            }));

    // Handle device use record statistics
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ private:

    // AnalyticsState is individually locked, and we use SharedPtrWrap
    // to allow safe access even if the shared pointer changes underneath.

    // These wrap pointers always point to a valid state object.
    SharedPtrWrap<AnalyticsState> mAnalyticsState;
    SharedPtrWrap<AnalyticsState> mPreviousAnalyticsState;