Loading packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +12 −0 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/log/dagger/MediaBrowserLog.java 0 → 100644 +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 { } packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowser.java +15 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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; } /** Loading @@ -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); Loading @@ -84,6 +90,7 @@ public class ResumeMediaBrowser { mComponentName, mConnectionCallback, rootHints); mLogger.logConnection(mComponentName, "findRecentMedia"); mMediaBrowser.connect(); } Loading Loading @@ -196,6 +203,7 @@ public class ResumeMediaBrowser { */ protected void disconnect() { if (mMediaBrowser != null) { mLogger.logDisconnect(mComponentName); mMediaBrowser.disconnect(); } mMediaBrowser = null; Loading Loading @@ -251,6 +259,7 @@ public class ResumeMediaBrowser { disconnect(); } }, rootHints); mLogger.logConnection(mComponentName, "restart"); mMediaBrowser.connect(); } Loading Loading @@ -296,6 +305,7 @@ public class ResumeMediaBrowser { mComponentName, mConnectionCallback, rootHints); mLogger.logConnection(mComponentName, "testConnection"); mMediaBrowser.connect(); } Loading packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserFactory.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; } /** Loading @@ -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); } } packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserLogger.kt 0 → 100644 +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
packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +12 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/log/dagger/MediaBrowserLog.java 0 → 100644 +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 { }
packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowser.java +15 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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; } /** Loading @@ -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); Loading @@ -84,6 +90,7 @@ public class ResumeMediaBrowser { mComponentName, mConnectionCallback, rootHints); mLogger.logConnection(mComponentName, "findRecentMedia"); mMediaBrowser.connect(); } Loading Loading @@ -196,6 +203,7 @@ public class ResumeMediaBrowser { */ protected void disconnect() { if (mMediaBrowser != null) { mLogger.logDisconnect(mComponentName); mMediaBrowser.disconnect(); } mMediaBrowser = null; Loading Loading @@ -251,6 +259,7 @@ public class ResumeMediaBrowser { disconnect(); } }, rootHints); mLogger.logConnection(mComponentName, "restart"); mMediaBrowser.connect(); } Loading Loading @@ -296,6 +305,7 @@ public class ResumeMediaBrowser { mComponentName, mConnectionCallback, rootHints); mLogger.logConnection(mComponentName, "testConnection"); mMediaBrowser.connect(); } Loading
packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserFactory.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; } /** Loading @@ -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); } }
packages/SystemUI/src/com/android/systemui/media/ResumeMediaBrowserLogger.kt 0 → 100644 +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"