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