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

Commit 7a5be553 authored by Jin Seok Park's avatar Jin Seok Park Committed by Android (Google) Code Review
Browse files

Merge "[Media ML] Copy over Debug#getCallers(int)"

parents 8d0e4c55 d9c93db0
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.server.media.SessionPolicyProvider.SESSION_POLICY_IGNO

import android.media.Session2Token;
import android.media.session.MediaSession;
import android.os.Debug;
import android.os.UserHandle;
import android.util.Log;
import android.util.SparseArray;
@@ -187,7 +186,7 @@ class MediaSessionStack {
     */
    public void updateMediaButtonSessionIfNeeded() {
        if (DEBUG) {
            Log.d(TAG, "updateMediaButtonSessionIfNeeded, callers=" + Debug.getCallers(2));
            Log.d(TAG, "updateMediaButtonSessionIfNeeded, callers=" + getCallers(2));
        }
        List<Integer> audioPlaybackUids =
                mAudioPlayerStateMonitor.getSortedAudioPlaybackClientUids();
@@ -413,4 +412,24 @@ class MediaSessionStack {
        // so they also need to be cleared.
        mCachedActiveLists.remove(UserHandle.USER_ALL);
    }

    // Code copied from android.os.Debug#getCallers(int)
    private static String getCallers(final int depth) {
        final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < depth; i++) {
            sb.append(getCaller(callStack, i)).append(" ");
        }
        return sb.toString();
    }

    // Code copied from android.os.Debug#getCaller(StackTraceElement[], int)
    private static String getCaller(StackTraceElement[] callStack, int depth) {
        // callStack[4] is the caller of the method that called getCallers()
        if (4 + depth >= callStack.length) {
            return "<bottom of call stack>";
        }
        StackTraceElement caller = callStack[4 + depth];
        return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber();
    }
}