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

Commit 14692053 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[Media] Add logging to ResumeMediaBrowser for connections and...

Merge "[Media] Add logging to ResumeMediaBrowser for connections and disconnections." into tm-dev am: 38b22faf am: 6d070b84 am: 7fb73d9a

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



Change-Id: I29f2792bdf7dc0529894f9f4a006677fff79cd3c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d6de64d7 7fb73d9a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -218,6 +218,18 @@ public class LogModule {
        return factory.create("MediaTimeout", 100);
    }

    /**
     * Provides a buffer for our connections and disconnections to MediaBrowserService.
     *
     * See {@link com.android.systemui.media.ResumeMediaBrowser}.
     */
    @Provides
    @SysUISingleton
    @MediaBrowserLog
    public static LogBuffer provideMediaBrowserBuffer(LogBufferFactory factory) {
        return factory.create("MediaBrowser", 100);
    }

    /** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */
    @Provides
    @SysUISingleton
+35 −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.systemui.log.dagger;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.android.systemui.log.LogBuffer;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

/**
 * A {@link LogBuffer} for {@link com.android.systemui.media.ResumeMediaBrowser}
 */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface MediaBrowserLog {
}
+15 −5
Original line number Diff line number Diff line
@@ -49,9 +49,11 @@ public class ResumeMediaBrowser {
    private static final String TAG = "ResumeMediaBrowser";
    private final Context mContext;
    @Nullable private final Callback mCallback;
    private MediaBrowserFactory mBrowserFactory;
    private final MediaBrowserFactory mBrowserFactory;
    private final ResumeMediaBrowserLogger mLogger;
    private final ComponentName mComponentName;

    private MediaBrowser mMediaBrowser;
    private ComponentName mComponentName;

    /**
     * Initialize a new media browser
@@ -59,12 +61,17 @@ public class ResumeMediaBrowser {
     * @param callback used to report media items found
     * @param componentName Component name of the MediaBrowserService this browser will connect to
     */
    public ResumeMediaBrowser(Context context, @Nullable Callback callback,
            ComponentName componentName, MediaBrowserFactory browserFactory) {
    public ResumeMediaBrowser(
            Context context,
            @Nullable Callback callback,
            ComponentName componentName,
            MediaBrowserFactory browserFactory,
            ResumeMediaBrowserLogger logger) {
        mContext = context;
        mCallback = callback;
        mComponentName = componentName;
        mBrowserFactory = browserFactory;
        mLogger = logger;
    }

    /**
@@ -76,7 +83,6 @@ public class ResumeMediaBrowser {
     * ResumeMediaBrowser#disconnect will be called automatically with this function.
     */
    public void findRecentMedia() {
        Log.d(TAG, "Connecting to " + mComponentName);
        disconnect();
        Bundle rootHints = new Bundle();
        rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_RECENT, true);
@@ -84,6 +90,7 @@ public class ResumeMediaBrowser {
                mComponentName,
                mConnectionCallback,
                rootHints);
        mLogger.logConnection(mComponentName, "findRecentMedia");
        mMediaBrowser.connect();
    }

@@ -196,6 +203,7 @@ public class ResumeMediaBrowser {
     */
    protected void disconnect() {
        if (mMediaBrowser != null) {
            mLogger.logDisconnect(mComponentName);
            mMediaBrowser.disconnect();
        }
        mMediaBrowser = null;
@@ -251,6 +259,7 @@ public class ResumeMediaBrowser {
                        disconnect();
                    }
                }, rootHints);
        mLogger.logConnection(mComponentName, "restart");
        mMediaBrowser.connect();
    }

@@ -296,6 +305,7 @@ public class ResumeMediaBrowser {
                mComponentName,
                mConnectionCallback,
                rootHints);
        mLogger.logConnection(mComponentName, "testConnection");
        mMediaBrowser.connect();
    }

+5 −2
Original line number Diff line number Diff line
@@ -27,11 +27,14 @@ import javax.inject.Inject;
public class ResumeMediaBrowserFactory {
    private final Context mContext;
    private final MediaBrowserFactory mBrowserFactory;
    private final ResumeMediaBrowserLogger mLogger;

    @Inject
    public ResumeMediaBrowserFactory(Context context, MediaBrowserFactory browserFactory) {
    public ResumeMediaBrowserFactory(
            Context context, MediaBrowserFactory browserFactory, ResumeMediaBrowserLogger logger) {
        mContext = context;
        mBrowserFactory = browserFactory;
        mLogger = logger;
    }

    /**
@@ -43,6 +46,6 @@ public class ResumeMediaBrowserFactory {
     */
    public ResumeMediaBrowser create(ResumeMediaBrowser.Callback callback,
            ComponentName componentName) {
        return new ResumeMediaBrowser(mContext, callback, componentName, mBrowserFactory);
        return new ResumeMediaBrowser(mContext, callback, componentName, mBrowserFactory, mLogger);
    }
}
+53 −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.systemui.media

import android.content.ComponentName
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel
import com.android.systemui.log.dagger.MediaBrowserLog
import javax.inject.Inject

/** A logger for events in [ResumeMediaBrowser]. */
@SysUISingleton
class ResumeMediaBrowserLogger @Inject constructor(
    @MediaBrowserLog private val buffer: LogBuffer
) {
    /** Logs that we've initiated a connection to a [android.media.browse.MediaBrowser]. */
    fun logConnection(componentName: ComponentName, reason: String) = buffer.log(
        TAG,
        LogLevel.DEBUG,
        {
            str1 = componentName.toShortString()
            str2 = reason
        },
        { "Connecting browser for component $str1 due to $str2" }
    )

    /** Logs that we've disconnected from a [android.media.browse.MediaBrowser]. */
    fun logDisconnect(componentName: ComponentName) = buffer.log(
        TAG,
        LogLevel.DEBUG,
        {
            str1 = componentName.toShortString()
        },
        { "Disconnecting browser for component $str1" }
    )
}

private const val TAG = "MediaBrowser"
Loading