Merge "[Media] Add some tracing to media classes." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ee1b4d021f
@@ -32,6 +32,7 @@ import com.android.systemui.util.animation.UniqueObjectHostView
|
||||
import com.android.systemui.util.animation.requiresRemeasuring
|
||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||
import com.android.systemui.util.time.SystemClock
|
||||
import com.android.systemui.util.traceSection
|
||||
import java.io.PrintWriter
|
||||
import java.util.TreeMap
|
||||
import javax.inject.Inject
|
||||
@@ -425,7 +426,7 @@ class MediaCarouselController @Inject constructor(
|
||||
oldKey: String?,
|
||||
data: MediaData,
|
||||
isSsReactivated: Boolean
|
||||
): Boolean {
|
||||
): Boolean = traceSection("MediaCarouselController#addOrUpdatePlayer") {
|
||||
MediaPlayerData.moveIfExists(oldKey, key)
|
||||
val existingPlayer = MediaPlayerData.getMediaPlayer(key)
|
||||
val curVisibleMediaKey = MediaPlayerData.playerKeys()
|
||||
@@ -471,7 +472,7 @@ class MediaCarouselController @Inject constructor(
|
||||
key: String,
|
||||
data: SmartspaceMediaData,
|
||||
shouldPrioritize: Boolean
|
||||
) {
|
||||
) = traceSection("MediaCarouselController#addSmartspaceMediaRecommendations") {
|
||||
if (DEBUG) Log.d(TAG, "Updating smartspace target in carousel")
|
||||
if (MediaPlayerData.getMediaPlayer(key) != null) {
|
||||
Log.w(TAG, "Skip adding smartspace target in carousel")
|
||||
@@ -698,7 +699,7 @@ class MediaCarouselController @Inject constructor(
|
||||
animate: Boolean,
|
||||
duration: Long = 200,
|
||||
startDelay: Long = 0
|
||||
) {
|
||||
) = traceSection("MediaCarouselController#onDesiredLocationChanged") {
|
||||
desiredHostState?.let {
|
||||
if (this.desiredLocation != desiredLocation) {
|
||||
// Only log an event when location changes
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.app.WallpaperColors;
|
||||
import android.app.smartspace.SmartspaceAction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
@@ -45,6 +44,7 @@ import android.media.session.MediaController;
|
||||
import android.media.session.MediaSession;
|
||||
import android.media.session.PlaybackState;
|
||||
import android.os.Process;
|
||||
import android.os.Trace;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
@@ -397,6 +397,7 @@ public class MediaControlPanel {
|
||||
if (mMediaViewHolder == null) {
|
||||
return;
|
||||
}
|
||||
Trace.beginSection("MediaControlPanel#bindPlayer<" + key + ">");
|
||||
mKey = key;
|
||||
mMediaData = data;
|
||||
MediaSession.Token token = data.getToken();
|
||||
@@ -455,7 +456,7 @@ public class MediaControlPanel {
|
||||
bindActionButtons(data);
|
||||
|
||||
boolean isSongUpdated = bindSongMetadata(data);
|
||||
bindArtworkAndColors(data, isSongUpdated);
|
||||
bindArtworkAndColors(data, key, isSongUpdated);
|
||||
|
||||
// TODO: We don't need to refresh this state constantly, only if the state actually changed
|
||||
// to something which might impact the measurement
|
||||
@@ -463,6 +464,7 @@ public class MediaControlPanel {
|
||||
if (!mMetadataAnimationHandler.isRunning()) {
|
||||
mMediaViewController.refreshState();
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void bindOutputSwitcherChip(MediaData data) {
|
||||
@@ -607,7 +609,11 @@ public class MediaControlPanel {
|
||||
mRecommendationViewHolder.getRecommendations().setContentDescription(contentDescription);
|
||||
}
|
||||
|
||||
private void bindArtworkAndColors(MediaData data, boolean updateBackground) {
|
||||
private void bindArtworkAndColors(MediaData data, String key, boolean updateBackground) {
|
||||
final int traceCookie = data.hashCode();
|
||||
final String traceName = "MediaControlPanel#bindArtworkAndColors<" + key + ">";
|
||||
Trace.beginAsyncSection(traceName, traceCookie);
|
||||
|
||||
final int reqId = mArtworkNextBindRequestId++;
|
||||
if (updateBackground) {
|
||||
mIsArtworkBound = false;
|
||||
@@ -648,7 +654,10 @@ public class MediaControlPanel {
|
||||
final ColorScheme colorScheme = mutableColorScheme;
|
||||
mMainExecutor.execute(() -> {
|
||||
// Cancel the request if a later one arrived first
|
||||
if (reqId < mArtworkBoundId) return;
|
||||
if (reqId < mArtworkBoundId) {
|
||||
Trace.endAsyncSection(traceName, traceCookie);
|
||||
return;
|
||||
}
|
||||
mArtworkBoundId = reqId;
|
||||
|
||||
// Bind the album view to the artwork or a transition drawable
|
||||
@@ -698,6 +707,7 @@ public class MediaControlPanel {
|
||||
appIconView.setImageResource(R.drawable.ic_music_note);
|
||||
}
|
||||
}
|
||||
Trace.endAsyncSection(traceName, traceCookie);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -990,6 +1000,9 @@ public class MediaControlPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
Trace.beginSection(
|
||||
"MediaControlPanel#bindRecommendation<" + data.getPackageName() + ">");
|
||||
|
||||
mRecommendationData = data;
|
||||
mSmartspaceId = SmallHash.hash(data.getTargetId());
|
||||
mPackageName = data.getPackageName();
|
||||
@@ -1003,12 +1016,14 @@ public class MediaControlPanel {
|
||||
mUid = applicationInfo.uid;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.w(TAG, "Fail to get media recommendation's app info", e);
|
||||
Trace.endSection();
|
||||
return;
|
||||
}
|
||||
|
||||
CharSequence appName = data.getAppName(mContext);
|
||||
if (appName == null) {
|
||||
Log.w(TAG, "Fail to get media recommendation's app name");
|
||||
Trace.endSection();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1123,6 +1138,7 @@ public class MediaControlPanel {
|
||||
if (mMetadataAnimationHandler == null || !mMetadataAnimationHandler.isRunning()) {
|
||||
mMediaViewController.refreshState();
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void fetchAndUpdateRecommendationColors(Drawable appIcon) {
|
||||
|
||||
@@ -65,6 +65,7 @@ import com.android.systemui.util.Assert
|
||||
import com.android.systemui.util.Utils
|
||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||
import com.android.systemui.util.time.SystemClock
|
||||
import com.android.systemui.util.traceSection
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import java.util.concurrent.Executor
|
||||
@@ -1031,7 +1032,11 @@ class MediaDataManager(
|
||||
)
|
||||
}
|
||||
|
||||
fun onMediaDataLoaded(key: String, oldKey: String?, data: MediaData) {
|
||||
fun onMediaDataLoaded(
|
||||
key: String,
|
||||
oldKey: String?,
|
||||
data: MediaData
|
||||
) = traceSection("MediaDataManager#onMediaDataLoaded") {
|
||||
Assert.isMainThread()
|
||||
if (mediaEntries.containsKey(key)) {
|
||||
// Otherwise this was removed already
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController
|
||||
import com.android.systemui.util.LargeScreenUtils
|
||||
import com.android.systemui.util.animation.UniqueObjectHostView
|
||||
import com.android.systemui.util.traceSection
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -582,7 +583,7 @@ class MediaHierarchyManager @Inject constructor(
|
||||
private fun updateDesiredLocation(
|
||||
forceNoAnimation: Boolean = false,
|
||||
forceStateUpdate: Boolean = false
|
||||
) {
|
||||
) = traceSection("MediaHierarchyManager#updateDesiredLocation") {
|
||||
val desiredLocation = calculateLocation()
|
||||
if (desiredLocation != this.desiredLocation || forceStateUpdate) {
|
||||
if (this.desiredLocation >= 0 && desiredLocation != this.desiredLocation) {
|
||||
@@ -616,7 +617,10 @@ class MediaHierarchyManager @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun performTransitionToNewLocation(isNewView: Boolean, animate: Boolean) {
|
||||
private fun performTransitionToNewLocation(
|
||||
isNewView: Boolean,
|
||||
animate: Boolean
|
||||
) = traceSection("MediaHierarchyManager#performTransitionToNewLocation") {
|
||||
if (previousLocation < 0 || isNewView) {
|
||||
cancelAnimationAndApplyDesiredState()
|
||||
return
|
||||
@@ -899,7 +903,7 @@ class MediaHierarchyManager @Inject constructor(
|
||||
alpha: Float,
|
||||
immediately: Boolean = false,
|
||||
clipBounds: Rect = EMPTY_RECT
|
||||
) {
|
||||
) = traceSection("MediaHierarchyManager#applyState") {
|
||||
currentBounds.set(bounds)
|
||||
currentClipping = clipBounds
|
||||
carouselAlpha = if (isCurrentlyFading()) alpha else 1.0f
|
||||
@@ -922,7 +926,9 @@ class MediaHierarchyManager @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateHostAttachment() {
|
||||
private fun updateHostAttachment() = traceSection(
|
||||
"MediaHierarchyManager#updateHostAttachment"
|
||||
) {
|
||||
var newLocation = resolveLocationForFading()
|
||||
var canUseOverlay = !isCurrentlyFading()
|
||||
if (isCrossFadeAnimatorRunning) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.systemui.media
|
||||
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.util.animation.MeasurementOutput
|
||||
import com.android.systemui.util.traceSection
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,10 @@ class MediaHostStatesManager @Inject constructor() {
|
||||
* Notify that a media state for a given location has changed. Should only be called from
|
||||
* Media hosts themselves.
|
||||
*/
|
||||
fun updateHostState(@MediaLocation location: Int, hostState: MediaHostState) {
|
||||
fun updateHostState(
|
||||
@MediaLocation location: Int,
|
||||
hostState: MediaHostState
|
||||
) = traceSection("MediaHostStatesManager#updateHostState") {
|
||||
val currentState = mediaHostStates.get(location)
|
||||
if (!hostState.equals(currentState)) {
|
||||
val newState = hostState.copy()
|
||||
@@ -71,7 +75,7 @@ class MediaHostStatesManager @Inject constructor() {
|
||||
fun updateCarouselDimensions(
|
||||
@MediaLocation location: Int,
|
||||
hostState: MediaHostState
|
||||
): MeasurementOutput {
|
||||
): MeasurementOutput = traceSection("MediaHostStatesManager#updateCarouselDimensions") {
|
||||
val result = MeasurementOutput(0, 0)
|
||||
for (controller in controllers) {
|
||||
val measurement = controller.getMeasurementsForState(hostState)
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.android.systemui.util.animation.MeasurementOutput
|
||||
import com.android.systemui.util.animation.TransitionLayout
|
||||
import com.android.systemui.util.animation.TransitionLayoutController
|
||||
import com.android.systemui.util.animation.TransitionViewState
|
||||
import com.android.systemui.util.traceSection
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -371,7 +372,10 @@ class MediaViewController @Inject constructor(
|
||||
* Attach a view to this controller. This may perform measurements if it's not available yet
|
||||
* and should therefore be done carefully.
|
||||
*/
|
||||
fun attach(transitionLayout: TransitionLayout, type: TYPE) {
|
||||
fun attach(
|
||||
transitionLayout: TransitionLayout,
|
||||
type: TYPE
|
||||
) = traceSection("MediaViewController#attach") {
|
||||
updateMediaViewControllerType(type)
|
||||
logger.logMediaLocation("attach", currentStartLocation, currentEndLocation)
|
||||
this.transitionLayout = transitionLayout
|
||||
@@ -392,7 +396,9 @@ class MediaViewController @Inject constructor(
|
||||
* and all widgets know their location. Calling this method may create a measurement if we
|
||||
* don't have a cached value available already.
|
||||
*/
|
||||
fun getMeasurementsForState(hostState: MediaHostState): MeasurementOutput? {
|
||||
fun getMeasurementsForState(
|
||||
hostState: MediaHostState
|
||||
): MeasurementOutput? = traceSection("MediaViewController#getMeasurementsForState") {
|
||||
val viewState = obtainViewState(hostState) ?: return null
|
||||
measurement.measuredWidth = viewState.width
|
||||
measurement.measuredHeight = viewState.height
|
||||
@@ -408,7 +414,7 @@ class MediaViewController @Inject constructor(
|
||||
@MediaLocation endLocation: Int,
|
||||
transitionProgress: Float,
|
||||
applyImmediately: Boolean
|
||||
) {
|
||||
) = traceSection("MediaViewController#setCurrentState") {
|
||||
currentEndLocation = endLocation
|
||||
currentStartLocation = startLocation
|
||||
currentTransitionProgress = transitionProgress
|
||||
@@ -540,7 +546,7 @@ class MediaViewController @Inject constructor(
|
||||
/**
|
||||
* Clear all existing measurements and refresh the state to match the view.
|
||||
*/
|
||||
fun refreshState() {
|
||||
fun refreshState() = traceSection("MediaViewController#refreshState") {
|
||||
// Let's clear all of our measurements and recreate them!
|
||||
viewStates.clear()
|
||||
if (firstRefresh) {
|
||||
|
||||
Reference in New Issue
Block a user