Shorten log tags to 23 char limit

When calling Android's Log class directly, there's a LongLogTag
lint check that detects tags over the 23 char limit, however it
cannot detect long log tags in ExoPlayer due to the way that we
log via our own Log class. This commit adds @Size annotations to
enforce the same rule.

PiperOrigin-RevId: 413976364
This commit is contained in:
olly 2021-12-03 19:07:45 +00:00 committed by Ian Baker
parent aae9ebaa7e
commit f2ad8ccd3c
27 changed files with 83 additions and 57 deletions

View File

@ -18,6 +18,7 @@ package androidx.media3.common.util;
import android.text.TextUtils;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -79,7 +80,7 @@ public final class Log {
/** @see android.util.Log#d(String, String) */
@Pure
public static void d(String tag, String message) {
public static void d(@Size(max = 23) String tag, String message) {
if (logLevel == LOG_LEVEL_ALL) {
android.util.Log.d(tag, message);
}
@ -87,13 +88,13 @@ public final class Log {
/** @see android.util.Log#d(String, String, Throwable) */
@Pure
public static void d(String tag, String message, @Nullable Throwable throwable) {
public static void d(@Size(max = 23) String tag, String message, @Nullable Throwable throwable) {
d(tag, appendThrowableString(message, throwable));
}
/** @see android.util.Log#i(String, String) */
@Pure
public static void i(String tag, String message) {
public static void i(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_INFO) {
android.util.Log.i(tag, message);
}
@ -101,13 +102,13 @@ public final class Log {
/** @see android.util.Log#i(String, String, Throwable) */
@Pure
public static void i(String tag, String message, @Nullable Throwable throwable) {
public static void i(@Size(max = 23) String tag, String message, @Nullable Throwable throwable) {
i(tag, appendThrowableString(message, throwable));
}
/** @see android.util.Log#w(String, String) */
@Pure
public static void w(String tag, String message) {
public static void w(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_WARNING) {
android.util.Log.w(tag, message);
}
@ -115,13 +116,13 @@ public final class Log {
/** @see android.util.Log#w(String, String, Throwable) */
@Pure
public static void w(String tag, String message, @Nullable Throwable throwable) {
public static void w(@Size(max = 23) String tag, String message, @Nullable Throwable throwable) {
w(tag, appendThrowableString(message, throwable));
}
/** @see android.util.Log#e(String, String) */
@Pure
public static void e(String tag, String message) {
public static void e(@Size(max = 23) String tag, String message) {
if (logLevel <= LOG_LEVEL_ERROR) {
android.util.Log.e(tag, message);
}
@ -129,7 +130,7 @@ public final class Log {
/** @see android.util.Log#e(String, String, Throwable) */
@Pure
public static void e(String tag, String message, @Nullable Throwable throwable) {
public static void e(@Size(max = 23) String tag, String message, @Nullable Throwable throwable) {
e(tag, appendThrowableString(message, throwable));
}

View File

@ -45,7 +45,7 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
private static final int MODE_ENABLED = 1;
private static final int MODE_DISABLED = 2;
private static final String TAG = "DefaultMediaCodecAdapterFactory";
private static final String TAG = "DMCodecAdapterFactory";
@Mode private int asynchronousMode;
private boolean enableSynchronizeCodecInteractionsWithQueueing;

View File

@ -117,7 +117,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
AdsLoader getAdsLoader(MediaItem.AdsConfiguration adsConfiguration);
}
private static final String TAG = "DefaultMediaSourceFactory";
private static final String TAG = "DMediaSourceFactory";
private final DataSource.Factory dataSourceFactory;
private final DelegateFactoryLoader delegateFactoryLoader;

View File

@ -80,7 +80,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
@UnstableApi
public final class OutputConsumerAdapterV30 implements MediaParser.OutputConsumer {
private static final String TAG = "OutputConsumerAdapterV30";
private static final String TAG = "OConsumerAdapterV30";
private static final Pair<MediaParser.SeekPoint, MediaParser.SeekPoint> SEEK_POINT_PAIR_START =
Pair.create(MediaParser.SeekPoint.START, MediaParser.SeekPoint.START);

View File

@ -1761,8 +1761,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private static class EmsgUnwrappingTrackOutput implements TrackOutput {
private static final String TAG = "EmsgUnwrappingTrackOutput";
// TODO: Create a Formats util class with common constants like this.
private static final Format ID3_FORMAT =
new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_ID3).build();

View File

@ -22,6 +22,7 @@ import android.media.UnsupportedSchemeException;
import android.view.Surface;
import android.widget.FrameLayout;
import androidx.annotation.RequiresApi;
import androidx.annotation.Size;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
@ -85,7 +86,9 @@ import java.util.List;
private static final String WIDEVINE_SECURITY_LEVEL_3 = "L3";
private static final String SECURITY_LEVEL_PROPERTY = "securityLevel";
@Size(max = 23)
private final String tag;
private final HostActivity activity;
private String streamName;
@ -120,7 +123,7 @@ import java.util.List;
return false;
}
public DashTestRunner(String tag, HostActivity activity) {
public DashTestRunner(@Size(max = 23) String tag, HostActivity activity) {
this.tag = tag;
this.activity = activity;
}
@ -405,7 +408,9 @@ import java.util.List;
private static final class DashTestTrackSelector extends DefaultTrackSelector {
@Size(max = 23)
private final String tag;
private final String audioFormatId;
private final String[] videoFormatIds;
private final boolean canIncludeAdditionalVideoFormats;

View File

@ -79,7 +79,7 @@ import java.util.ArrayList;
*/
private static class DebugMediaCodecVideoRenderer extends MediaCodecVideoRenderer {
private static final String TAG = "DebugMediaCodecVideoRenderer";
private static final String TAG = "DMCodecVideoRenderer";
private static final int ARRAY_SIZE = 1000;
private final long[] timestampsList;

View File

@ -15,6 +15,7 @@
*/
package androidx.media3.test.exoplayer.playback.gts;
import androidx.annotation.Size;
import androidx.media3.common.util.Log;
/** Implementation of {@link MetricsLogger} that prints the metrics to logcat. */
@ -23,9 +24,10 @@ import androidx.media3.common.util.Log;
public static final Factory FACTORY =
(instrumentation, tag, streamName) -> new LogcatMetricsLogger(tag);
@Size(max = 23)
private final String tag;
public LogcatMetricsLogger(String tag) {
public LogcatMetricsLogger(@Size(max = 23) String tag) {
this.tag = tag;
}

View File

@ -16,12 +16,14 @@
package androidx.media3.test.exoplayer.playback.gts;
import android.app.Instrumentation;
import androidx.annotation.Size;
/** Metric logging interface for playback tests. */
/* package */ interface MetricsLogger {
interface Factory {
MetricsLogger create(Instrumentation instrumentation, String tag, String streamName);
MetricsLogger create(
Instrumentation instrumentation, @Size(max = 23) String tag, String streamName);
}
Factory DEFAULT_FACTORY = LogcatMetricsLogger.FACTORY;

View File

@ -58,7 +58,8 @@ import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
@LargeTest
public class MediaControllerSurfaceSizeChangeTest {
private static final String TAG = "MC_SurfaceSizeChangeTest";
private static final String TAG = "MCSurfaceSizeChangeTest";
private static final String SET_VIDEO_SURFACE = "setVideoSurface";
private static final String SET_VIDEO_SURFACE_HOLDER = "setVideoSurfaceHolder";

View File

@ -50,7 +50,8 @@ import org.junit.runner.RunWith;
@LargeTest
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP) // For framework MediaSession
public class MediaControllerWithFrameworkMediaSessionTest {
private static final String TAG = "MediaControllerWithFrameworkMediaSessionTest";
private static final String TAG = "MCFMediaSessionTest";
@ClassRule public static MainLooperTestRule mainLooperTestRule = new MainLooperTestRule();

View File

@ -44,7 +44,7 @@ import org.junit.runner.RunWith;
@LargeTest
public class MediaSessionAndControllerTest {
private static final String TAG = "SessionAndControllerTest";
private static final String TAG = "MSessionControllerTest";
@ClassRule public static MainLooperTestRule mainLooperTestRule = new MainLooperTestRule();

View File

@ -55,7 +55,8 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MediaSessionCallbackTest {
private static final String TAG = "MediaSessionCallbackTest";
private static final String TAG = "MSessionCallbackTest";
@ClassRule public static MainLooperTestRule mainLooperTestRule = new MainLooperTestRule();

View File

@ -30,7 +30,7 @@ import org.junit.rules.ExternalResource;
/** TestRule for managing {@link RemoteMediaController} instances. */
public final class RemoteControllerTestRule extends ExternalResource {
private static final String TAG = "RemoteControllerTestRule";
private static final String TAG = "RControllerTestRule";
private Context context;
private final List<RemoteMediaController> controllers;

View File

@ -46,7 +46,8 @@ import java.util.concurrent.Executor;
*/
@UnstableApi
public class MediaBrowserCompatProviderService extends Service {
private static final String TAG = "MediaBrowserCompatProviderService";
private static final String TAG = "MBCompatProviderService";
Map<String, MediaBrowserCompat> mediaBrowserCompatMap = new HashMap<>();
Map<String, TestBrowserConnectionCallback> connectionCallbackMap = new HashMap<>();

View File

@ -48,7 +48,7 @@ import java.util.concurrent.Executor;
*/
@UnstableApi
public class MediaControllerCompatProviderService extends Service {
private static final String TAG = "MediaControllerCompatProviderService";
private static final String TAG = "MCCProviderService";
Map<String, MediaControllerCompat> mediaControllerCompatMap = new HashMap<>();
RemoteMediaControllerCompatStub binder;

View File

@ -56,7 +56,7 @@ import java.util.concurrent.TimeoutException;
*/
@UnstableApi
public class MediaControllerProviderService extends Service {
private static final String TAG = "MediaControllerProviderService";
private static final String TAG = "MCProviderService";
Map<String, MediaController> mediaControllerMap = new HashMap<>();
RemoteMediaControllerStub binder;

View File

@ -48,7 +48,8 @@ import java.util.concurrent.Executor;
*/
@UnstableApi
public class MediaSessionCompatProviderService extends Service {
private static final String TAG = "MediaSessionCompatProviderService";
private static final String TAG = "MSCProviderService";
Map<String, MediaSessionCompat> sessionMap = new HashMap<>();
RemoteMediaSessionCompatStub sessionBinder;

View File

@ -101,7 +101,8 @@ import java.util.concurrent.Callable;
*/
@UnstableApi
public class MediaSessionProviderService extends Service {
private static final String TAG = "MediaSessionProviderService";
private static final String TAG = "MSProviderService";
private Map<String, MediaSession> sessionMap = new HashMap<>();
private RemoteMediaSessionStub sessionBinder;

View File

@ -37,7 +37,8 @@ import java.util.List;
/** Mock implementation of the media browser service. */
@UnstableApi
public class MockMediaBrowserServiceCompat extends MediaBrowserServiceCompat {
private static final String TAG = "MockMediaBrowserServiceCompat";
private static final String TAG = "MockMBSCompat";
private static final Object lock = new Object();
@GuardedBy("lock")

View File

@ -41,7 +41,8 @@ import java.util.concurrent.CountDownLatch;
*/
@UnstableApi
public class RemoteMediaBrowserCompat {
private static final String TAG = "RemoteMediaBrowserCompat";
private static final String TAG = "RMediaBrowserCompat";
private final String browserId;
private final Context context;

View File

@ -53,7 +53,8 @@ import java.util.concurrent.CountDownLatch;
*/
@UnstableApi
public class RemoteMediaSessionCompat {
private static final String TAG = "RemoteMediaSessionCompat";
private static final String TAG = "RMediaSessionCompat";
private final Context context;
private final String sessionTag;

View File

@ -18,6 +18,7 @@ package androidx.media3.test.utils;
import android.os.Looper;
import android.view.Surface;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.C;
import androidx.media3.common.IllegalSeekPositionException;
@ -48,7 +49,9 @@ import java.util.List;
@UnstableApi
public abstract class Action {
@Size(max = 23)
private final String tag;
@Nullable private final String description;
/**
@ -56,7 +59,7 @@ public abstract class Action {
* @param description A description to be logged when the action is executed, or null if no
* logging is required.
*/
public Action(String tag, @Nullable String description) {
public Action(@Size(max = 23) String tag, @Nullable String description) {
this.tag = tag;
this.description = description;
}
@ -133,7 +136,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param positionMs The seek position.
*/
public Seek(String tag, long positionMs) {
public Seek(@Size(max = 23) String tag, long positionMs) {
super(tag, "Seek:" + positionMs);
this.mediaItemIndex = null;
this.positionMs = positionMs;
@ -211,7 +214,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param mediaSources The media sources to be added to the playlist.
*/
public AddMediaItems(String tag, MediaSource... mediaSources) {
public AddMediaItems(@Size(max = 23) String tag, MediaSource... mediaSources) {
super(tag, /* description= */ "AddMediaItems");
this.mediaSources = mediaSources;
}
@ -259,7 +262,7 @@ public abstract class Action {
* @param currentIndex The current index of the media item.
* @param newIndex The new index of the media item.
*/
public MoveMediaItem(String tag, int currentIndex, int newIndex) {
public MoveMediaItem(@Size(max = 23) String tag, int currentIndex, int newIndex) {
super(tag, "MoveMediaItem");
this.currentIndex = currentIndex;
this.newIndex = newIndex;
@ -281,7 +284,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param index The index of the item to remove.
*/
public RemoveMediaItem(String tag, int index) {
public RemoveMediaItem(@Size(max = 23) String tag, int index) {
super(tag, "RemoveMediaItem");
this.index = index;
}
@ -304,7 +307,7 @@ public abstract class Action {
* @param fromIndex The start if the range of media items to remove.
* @param toIndex The end of the range of media items to remove (exclusive).
*/
public RemoveMediaItems(String tag, int fromIndex, int toIndex) {
public RemoveMediaItems(@Size(max = 23) String tag, int fromIndex, int toIndex) {
super(tag, "RemoveMediaItem");
this.fromIndex = fromIndex;
this.toIndex = toIndex;
@ -355,7 +358,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param reset The value to pass to {@link Player#stop(boolean)}.
*/
public Stop(String tag, boolean reset) {
public Stop(@Size(max = 23) String tag, boolean reset) {
super(tag, STOP_ACTION_TAG);
this.reset = reset;
}
@ -380,7 +383,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param playWhenReady The value to pass.
*/
public SetPlayWhenReady(String tag, boolean playWhenReady) {
public SetPlayWhenReady(@Size(max = 23) String tag, boolean playWhenReady) {
super(tag, playWhenReady ? "Play" : "Pause");
this.playWhenReady = playWhenReady;
}
@ -406,7 +409,7 @@ public abstract class Action {
* @param rendererIndex The index of the renderer.
* @param disabled Whether the renderer should be disabled.
*/
public SetRendererDisabled(String tag, int rendererIndex, boolean disabled) {
public SetRendererDisabled(@Size(max = 23) String tag, int rendererIndex, boolean disabled) {
super(tag, "SetRendererDisabled:" + rendererIndex + ":" + disabled);
this.rendererIndex = rendererIndex;
this.disabled = disabled;
@ -498,7 +501,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param repeatMode The repeat mode.
*/
public SetRepeatMode(String tag, @Player.RepeatMode int repeatMode) {
public SetRepeatMode(@Size(max = 23) String tag, @Player.RepeatMode int repeatMode) {
super(tag, "SetRepeatMode:" + repeatMode);
this.repeatMode = repeatMode;
}
@ -519,7 +522,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param shuffleOrder The shuffle order.
*/
public SetShuffleOrder(String tag, ShuffleOrder shuffleOrder) {
public SetShuffleOrder(@Size(max = 23) String tag, ShuffleOrder shuffleOrder) {
super(tag, "SetShufflerOrder");
this.shuffleOrder = shuffleOrder;
}
@ -540,7 +543,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param shuffleModeEnabled Whether shuffling is enabled.
*/
public SetShuffleModeEnabled(String tag, boolean shuffleModeEnabled) {
public SetShuffleModeEnabled(@Size(max = 23) String tag, boolean shuffleModeEnabled) {
super(tag, "SetShuffleModeEnabled:" + shuffleModeEnabled);
this.shuffleModeEnabled = shuffleModeEnabled;
}
@ -565,7 +568,7 @@ public abstract class Action {
* @param target A message target.
* @param positionMs The position at which the message should be sent, in milliseconds.
*/
public SendMessages(String tag, Target target, long positionMs) {
public SendMessages(@Size(max = 23) String tag, Target target, long positionMs) {
this(
tag,
target,
@ -624,7 +627,8 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param playbackParameters The playback parameters.
*/
public SetPlaybackParameters(String tag, PlaybackParameters playbackParameters) {
public SetPlaybackParameters(
@Size(max = 23) String tag, PlaybackParameters playbackParameters) {
super(tag, "SetPlaybackParameters:" + playbackParameters);
this.playbackParameters = playbackParameters;
}
@ -645,7 +649,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param exception The exception to throw.
*/
public ThrowPlaybackException(String tag, ExoPlaybackException exception) {
public ThrowPlaybackException(@Size(max = 23) String tag, ExoPlaybackException exception) {
super(tag, "ThrowPlaybackException:" + exception);
this.exception = exception;
}
@ -676,7 +680,7 @@ public abstract class Action {
* @param mediaItemIndex The media item index at which the player should be paused again.
* @param positionMs The position in that media item at which the player should be paused again.
*/
public PlayUntilPosition(String tag, int mediaItemIndex, long positionMs) {
public PlayUntilPosition(@Size(max = 23) String tag, int mediaItemIndex, long positionMs) {
super(tag, "PlayUntilPosition:" + mediaItemIndex + ":" + positionMs);
this.mediaItemIndex = mediaItemIndex;
this.positionMs = positionMs;
@ -860,7 +864,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param playWhenReady The playWhenReady value to wait for.
*/
public WaitForPlayWhenReady(String tag, boolean playWhenReady) {
public WaitForPlayWhenReady(@Size(max = 23) String tag, boolean playWhenReady) {
super(tag, "WaitForPlayWhenReady");
targetPlayWhenReady = playWhenReady;
}
@ -911,7 +915,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param targetPlaybackState The playback state to wait for.
*/
public WaitForPlaybackState(String tag, @Player.State int targetPlaybackState) {
public WaitForPlaybackState(@Size(max = 23) String tag, @Player.State int targetPlaybackState) {
super(tag, "WaitForPlaybackState");
this.targetPlaybackState = targetPlaybackState;
}
@ -961,7 +965,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param playerTarget The target to observe.
*/
public WaitForMessage(String tag, PlayerTarget playerTarget) {
public WaitForMessage(@Size(max = 23) String tag, PlayerTarget playerTarget) {
super(tag, "WaitForMessage");
this.playerTarget = playerTarget;
}
@ -1001,7 +1005,7 @@ public abstract class Action {
* @param tag A tag to use for logging.
* @param targetIsLoading The loading state to wait for.
*/
public WaitForIsLoading(String tag, boolean targetIsLoading) {
public WaitForIsLoading(@Size(max = 23) String tag, boolean targetIsLoading) {
super(tag, "WaitForIsLoading");
this.targetIsLoading = targetIsLoading;
}
@ -1080,7 +1084,7 @@ public abstract class Action {
private final Runnable runnable;
/** @param tag A tag to use for logging. */
public ExecuteRunnable(String tag, Runnable runnable) {
public ExecuteRunnable(@Size(max = 23) String tag, Runnable runnable) {
super(tag, "ExecuteRunnable");
this.runnable = runnable;
}

View File

@ -18,6 +18,7 @@ package androidx.media3.test.utils;
import android.os.Looper;
import android.view.Surface;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackParameters;
@ -105,7 +106,9 @@ public final class ActionSchedule {
/** A builder for {@link ActionSchedule} instances. */
public static final class Builder {
@Size(max = 23)
private final String tag;
private final ActionNode rootNode;
private long currentDelayMs;
@ -754,7 +757,7 @@ public final class ActionSchedule {
/** A no-op root action. */
private static final class RootAction extends Action {
public RootAction(String tag) {
public RootAction(@Size(max = 23) String tag) {
super(tag, "Root");
}
@ -770,7 +773,7 @@ public final class ActionSchedule {
@Nullable private Callback callback;
public CallbackAction(String tag) {
public CallbackAction(@Size(max = 23) String tag) {
super(tag, "FinishedCallback");
}

View File

@ -23,6 +23,7 @@ import android.os.SystemClock;
import android.view.Surface;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.media3.common.Player;
import androidx.media3.common.util.Clock;
import androidx.media3.common.util.HandlerWrapper;
@ -84,7 +85,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
* was within {@link #MAX_PLAYING_TIME_DISCREPANCY_MS} of the media duration. If set to false,
* the test will not assert an expected playing time.
*/
public ExoHostedTest(String tag, boolean fullPlaybackNoSeeking) {
public ExoHostedTest(@Size(max = 23) String tag, boolean fullPlaybackNoSeeking) {
this(
tag,
fullPlaybackNoSeeking
@ -104,7 +105,8 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
* an expected playing time.
* @param failOnPlayerError Whether a player error should be considered a test failure.
*/
public ExoHostedTest(String tag, long expectedPlayingTimeMs, boolean failOnPlayerError) {
public ExoHostedTest(
@Size(max = 23) String tag, long expectedPlayingTimeMs, boolean failOnPlayerError) {
this.tag = tag;
this.expectedPlayingTimeMs = expectedPlayingTimeMs;
this.failOnPlayerError = failOnPlayerError;

View File

@ -31,7 +31,7 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
/* package */ final class TransformerAudioRenderer extends TransformerBaseRenderer {
private static final String TAG = "TransformerAudioRenderer";
private static final String TAG = "TAudioRenderer";
private final DecoderInputBuffer decoderInputBuffer;

View File

@ -32,7 +32,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/* package */ final class TransformerVideoRenderer extends TransformerBaseRenderer {
private static final String TAG = "TransformerTranscodingVideoRenderer";
private static final String TAG = "TVideoRenderer";
private final Context context;
private final DecoderInputBuffer decoderInputBuffer;