summaryrefslogtreecommitdiff
path: root/hostsidetests/media/app/MediaMetricsTest/src/android/media/metrics/cts/MediaMetricsAtomHostSideTests.java
blob: 3d0edfc3747e83cf3fd8f2b96030c64a473f7ebc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/*
 * Copyright (C) 2021 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 android.media.metrics.cts;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.device.collectors.util.SendToInstrumentation;
import android.media.metrics.BundleSession;
import android.media.metrics.EditingSession;
import android.media.metrics.LogSessionId;
import android.media.metrics.MediaMetricsManager;
import android.media.metrics.NetworkEvent;
import android.media.metrics.PlaybackErrorEvent;
import android.media.metrics.PlaybackMetrics;
import android.media.metrics.PlaybackSession;
import android.media.metrics.PlaybackStateEvent;
import android.media.metrics.RecordingSession;
import android.media.metrics.TrackChangeEvent;
import android.media.metrics.TranscodingSession;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.provider.DeviceConfig;
import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.compatibility.common.util.SystemUtil;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MediaMetricsAtomHostSideTests {
    private static final String TAG = "MediaMetricsAtomHostSideTests";
    private static final String MEDIA_METRICS_MODE = "media_metrics_mode";
    private static final String PLAYER_METRICS_APP_ALLOWLIST = "player_metrics_app_allowlist";
    private static final String PLAYER_METRICS_APP_BLOCKLIST = "player_metrics_app_blocklist";
    private static final String PLAYER_METRICS_PER_APP_ATTRIBUTION_ALLOWLIST =
            "player_metrics_per_app_attribution_allowlist";
    private static final String PLAYER_METRICS_PER_APP_ATTRIBUTION_BLOCKLIST =
            "player_metrics_per_app_attribution_blocklist";
    private static final String MEDIA_METRICS_MODE_ON = "1";
    private static final String MEDIA_METRICS_MODE_BLOCKLIST = "2";
    private static final String MEDIA_METRICS_MODE_ALLOWLIST = "3";
    private static final String TEST_PKG = "android.media.metrics.cts";
    private static final int DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS = 1000;

    static {
        System.loadLibrary("CtsMediaMetricsHostTestAppJni");
    }

    private static void resetProperties() throws InterruptedException {
        // ensure the event/metric is sent.
        Thread.sleep(1000);
        // see DeviceConfig#resetToDefaults(int, String).
        SystemUtil.runWithShellPermissionIdentity(() -> {
            DeviceConfig.setProperties(
                    new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_MEDIA).build());
        });
        // ensure the property is set.
        Thread.sleep(DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS);
    }

    private static void turnOnForTesting() throws InterruptedException {
        SystemUtil.runWithShellPermissionIdentity(() -> {
            DeviceConfig.setProperty(
                    DeviceConfig.NAMESPACE_MEDIA,
                    MEDIA_METRICS_MODE,
                    MEDIA_METRICS_MODE_ON,
                    /*makeDefault=*/ false);
        });
        // ensure the property is set.
        Thread.sleep(DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS);
    }


    @Test
    public void testPlaybackStateEvent_default() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackStateEvent e =
                new PlaybackStateEvent.Builder().build();
        s.reportPlaybackStateEvent(e);
        resetProperties();
    }


    @Test
    public void testPlaybackStateEvent() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackStateEvent e =
                new PlaybackStateEvent.Builder()
                        .setTimeSinceCreatedMillis(1763L)
                        .setState(PlaybackStateEvent.STATE_JOINING_FOREGROUND)
                        .setMetricsBundle(new Bundle())
                        .build();
        s.reportPlaybackStateEvent(e);
        resetProperties();
    }

    @Test
    public void testPlaybackErrorEvent_default() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackErrorEvent e =
                new PlaybackErrorEvent.Builder()
                        .setException(new Exception(""))
                        .build();
        s.reportPlaybackErrorEvent(e);
        resetProperties();
    }

    @Test
    public void testPlaybackErrorEvent() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackErrorEvent e =
                new PlaybackErrorEvent.Builder()
                        .setTimeSinceCreatedMillis(17630000L)
                        .setErrorCode(PlaybackErrorEvent.ERROR_RUNTIME)
                        .setSubErrorCode(378)
                        .setException(new Exception("test exception"))
                        .setMetricsBundle(new Bundle())
                        .build();
        s.reportPlaybackErrorEvent(e);
        resetProperties();
    }

    @Test
    public void testTrackChangeEvent_default() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        TrackChangeEvent e =
                new TrackChangeEvent.Builder(TrackChangeEvent.TRACK_TYPE_AUDIO).build();
        s.reportTrackChangeEvent(e);
        resetProperties();
    }

    @Test
    public void testTrackChangeEvent_text() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        TrackChangeEvent e =
                new TrackChangeEvent.Builder(TrackChangeEvent.TRACK_TYPE_TEXT)
                        .setTimeSinceCreatedMillis(37278L)
                        .setTrackState(TrackChangeEvent.TRACK_STATE_ON)
                        .setTrackChangeReason(TrackChangeEvent.TRACK_CHANGE_REASON_MANUAL)
                        .setContainerMimeType("text/foo")
                        .setSampleMimeType("text/plain")
                        .setCodecName("codec_1")
                        .setBitrate(1024)
                        .setLanguage("EN")
                        .setLanguageRegion("US")
                        .build();
        s.reportTrackChangeEvent(e);
        resetProperties();
    }

    @Test
    public void testTrackChangeEvent_audio() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        TrackChangeEvent e =
                new TrackChangeEvent.Builder(TrackChangeEvent.TRACK_TYPE_AUDIO)
                        .setTimeSinceCreatedMillis(37278L)
                        .setTrackState(TrackChangeEvent.TRACK_STATE_OFF)
                        .setTrackChangeReason(TrackChangeEvent.TRACK_CHANGE_REASON_INITIAL)
                        .setContainerMimeType("audio/foo")
                        .setSampleMimeType("audio/avc")
                        .setCodecName("codec_2")
                        .setBitrate(1025)
                        .setLanguage("EN")
                        .setLanguageRegion("US")
                        .setAudioSampleRate(89)
                        .setChannelCount(3)
                        .build();
        s.reportTrackChangeEvent(e);
        resetProperties();
    }

    @Test
    public void testTrackChangeEvent_video() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        TrackChangeEvent e =
                new TrackChangeEvent.Builder(TrackChangeEvent.TRACK_TYPE_VIDEO)
                        .setTimeSinceCreatedMillis(37278L)
                        .setTrackState(TrackChangeEvent.TRACK_STATE_OFF)
                        .setTrackChangeReason(TrackChangeEvent.TRACK_CHANGE_REASON_INITIAL)
                        .setContainerMimeType("video/foo")
                        .setSampleMimeType("video/mpeg")
                        .setCodecName("codec_3")
                        .setBitrate(1025)
                        .setLanguage("EN")
                        .setLanguageRegion("US")
                        .setHeight(1080)
                        .setWidth(1440)
                        .setVideoFrameRate(60)
                        .setMetricsBundle(new Bundle())
                        .build();
        s.reportTrackChangeEvent(e);
        resetProperties();
    }

    @Test
    public void testNetworkEvent_default() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        NetworkEvent e =
                new NetworkEvent.Builder().build();
        s.reportNetworkEvent(e);
        resetProperties();
    }

    @Test
    public void testNetworkEvent() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        NetworkEvent e =
                new NetworkEvent.Builder()
                        .setTimeSinceCreatedMillis(3032L)
                        .setNetworkType(NetworkEvent.NETWORK_TYPE_WIFI)
                        .setMetricsBundle(new Bundle())
                        .build();
        s.reportNetworkEvent(e);
        resetProperties();
    }

    @Test
    public void testPlaybackMetrics_default() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackMetrics e =
                new PlaybackMetrics.Builder().build();
        s.reportPlaybackMetrics(e);
        resetProperties();
    }

    @Test
    public void testPlaybackMetrics() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackMetrics e =
                new PlaybackMetrics.Builder()
                        .setMediaDurationMillis(233L)
                        .setStreamSource(PlaybackMetrics.STREAM_SOURCE_NETWORK)
                        .setStreamType(PlaybackMetrics.STREAM_TYPE_OTHER)
                        .setPlaybackType(PlaybackMetrics.PLAYBACK_TYPE_LIVE)
                        .setDrmType(PlaybackMetrics.DRM_TYPE_WIDEVINE_L1)
                        .setContentType(PlaybackMetrics.CONTENT_TYPE_MAIN)
                        .setPlayerName("ExoPlayer")
                        .setPlayerVersion("1.01x")
                        .setVideoFramesPlayed(1024)
                        .setVideoFramesDropped(32)
                        .setAudioUnderrunCount(22)
                        .setNetworkBytesRead(102400)
                        .setLocalBytesRead(2000)
                        .setNetworkTransferDurationMillis(6000)
                        .setDrmSessionId(new byte[]{2, 3, 3, 10})
                        .setMetricsBundle(new Bundle())
                        .addExperimentId(123)
                        .build();
        s.reportPlaybackMetrics(e);
        resetProperties();
    }

    @Test
    public void testSessionId() throws Exception {
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);

        try (PlaybackSession s = manager.createPlaybackSession()) {
            LogSessionId idObj = s.getSessionId();
            assertThat(idObj).isNotEqualTo(null);
            assertThat(idObj.getStringId().length()).isGreaterThan(0);
        }
    }

    @Test
    public void testRecordingSession() throws Exception {
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);

        try (RecordingSession s = manager.createRecordingSession()) {
            assertThat(s).isNotEqualTo(null);
            LogSessionId idObj = s.getSessionId();
            assertThat(idObj).isNotEqualTo(null);
            assertThat(idObj.getStringId().length()).isGreaterThan(0);
        }
    }

    @Test
    public void testEditingSession() throws Exception {
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);

        try (EditingSession s = manager.createEditingSession()) {
            assertThat(s).isNotEqualTo(null);
            LogSessionId idObj = s.getSessionId();
            assertThat(idObj).isNotEqualTo(null);
            assertThat(idObj.getStringId().length()).isGreaterThan(0);
        }
    }

    @Test
    public void testTranscodingSession() throws Exception {
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);

        try (TranscodingSession s = manager.createTranscodingSession()) {
            assertThat(s).isNotEqualTo(null);
            LogSessionId idObj = s.getSessionId();
            assertThat(idObj).isNotEqualTo(null);
            assertThat(idObj.getStringId().length()).isGreaterThan(0);
        }
    }

    @Test
    public void testBundleSession() throws Exception {
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);

        try (BundleSession s = manager.createBundleSession()) {
            assertThat(s).isNotEqualTo(null);
            LogSessionId idObj = s.getSessionId();
            assertThat(idObj).isNotEqualTo(null);
            assertThat(idObj.getStringId().length()).isGreaterThan(0);
        }
    }

    @Test
    public void testBundleSessionPlaybackStateEvent() throws Exception {
        turnOnForTesting();
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        BundleSession s = manager.createBundleSession();
        PersistableBundle b = new PersistableBundle();
        b.putInt(BundleSession.KEY_STATSD_ATOM, 322);
        // eventually want these keys from within the service side.
        b.putString("playbackstateevent-sessionid", s.getSessionId().getStringId());
        b.putInt("playbackstateevent-state", PlaybackStateEvent.STATE_JOINING_FOREGROUND);
        b.putLong("playbackstateevent-lifetime", 1763L);
        s.reportBundleMetrics(b);
        resetProperties();
    }

    @Test
    public void testAppBlocklist() throws Exception {
        SystemUtil.runWithShellPermissionIdentity(() -> {
            DeviceConfig.setProperties(
                    new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_MEDIA)
                            .setString(MEDIA_METRICS_MODE, MEDIA_METRICS_MODE_BLOCKLIST)
                            .setString(PLAYER_METRICS_PER_APP_ATTRIBUTION_BLOCKLIST, "")
                            .setString(PLAYER_METRICS_APP_BLOCKLIST, TEST_PKG)
                            .build());
        });
        Thread.sleep(DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS);
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackStateEvent e =
                new PlaybackStateEvent.Builder()
                        .setTimeSinceCreatedMillis(1763L)
                        .setState(PlaybackStateEvent.STATE_JOINING_FOREGROUND)
                        .setMetricsBundle(new Bundle())
                        .build();
        s.reportPlaybackStateEvent(e);
        writeSessionIdToFile(s.getSessionId().getStringId());
        resetProperties();
    }

    @Test
    public void testAttributionBlocklist() throws Exception {
        SystemUtil.runWithShellPermissionIdentity(() -> {
            DeviceConfig.setProperties(
                    new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_MEDIA)
                            .setString(MEDIA_METRICS_MODE, MEDIA_METRICS_MODE_BLOCKLIST)
                            .setString(PLAYER_METRICS_PER_APP_ATTRIBUTION_BLOCKLIST, TEST_PKG)
                            .setString(PLAYER_METRICS_APP_BLOCKLIST, "")
                            .build());
        });
        Thread.sleep(DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS);
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackMetrics e =
                new PlaybackMetrics.Builder()
                        .setMediaDurationMillis(233L)
                        .setStreamSource(PlaybackMetrics.STREAM_SOURCE_NETWORK)
                        .setStreamType(PlaybackMetrics.STREAM_TYPE_OTHER)
                        .setPlaybackType(PlaybackMetrics.PLAYBACK_TYPE_LIVE)
                        .setDrmType(PlaybackMetrics.DRM_TYPE_WIDEVINE_L1)
                        .setContentType(PlaybackMetrics.CONTENT_TYPE_MAIN)
                        .setPlayerName("ExoPlayer")
                        .setPlayerVersion("1.01x")
                        .setVideoFramesPlayed(1024)
                        .setVideoFramesDropped(32)
                        .setAudioUnderrunCount(22)
                        .setNetworkBytesRead(102400)
                        .setLocalBytesRead(2000)
                        .setNetworkTransferDurationMillis(6000)
                        .setDrmSessionId(new byte[]{2, 3, 3, 10})
                        .setMetricsBundle(new Bundle())
                        .addExperimentId(123)
                        .build();
        s.reportPlaybackMetrics(e);
        writeSessionIdToFile(s.getSessionId().getStringId());
        resetProperties();
    }

    @Test
    public void testAppAllowlist() throws Exception {
        SystemUtil.runWithShellPermissionIdentity(() -> {
            DeviceConfig.setProperties(
                    new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_MEDIA)
                            .setString(MEDIA_METRICS_MODE, MEDIA_METRICS_MODE_ALLOWLIST)
                            .setString(PLAYER_METRICS_PER_APP_ATTRIBUTION_ALLOWLIST, "")
                            .setString(PLAYER_METRICS_APP_ALLOWLIST, TEST_PKG)
                            .build());
        });
        Thread.sleep(DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS);
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackStateEvent e =
                new PlaybackStateEvent.Builder()
                        .setTimeSinceCreatedMillis(1763L)
                        .setState(PlaybackStateEvent.STATE_JOINING_FOREGROUND)
                        .setMetricsBundle(new Bundle())
                        .build();
        s.reportPlaybackStateEvent(e);
        writeSessionIdToFile(s.getSessionId().getStringId());
        resetProperties();
    }

    @Test
    public void testAttributionAllowlist() throws Exception {
        SystemUtil.runWithShellPermissionIdentity(() -> {
            DeviceConfig.setProperties(
                    new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_MEDIA)
                            .setString(MEDIA_METRICS_MODE, MEDIA_METRICS_MODE_ALLOWLIST)
                            .setString(PLAYER_METRICS_PER_APP_ATTRIBUTION_ALLOWLIST, TEST_PKG)
                            .setString(PLAYER_METRICS_APP_ALLOWLIST, "")
                            .build());
        });
        Thread.sleep(DEVICE_PROPERTY_PROPAGATION_DELAY_MICROSECONDS);
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        MediaMetricsManager manager = context.getSystemService(MediaMetricsManager.class);
        PlaybackSession s = manager.createPlaybackSession();
        PlaybackMetrics e =
                new PlaybackMetrics.Builder()
                        .setMediaDurationMillis(233L)
                        .setStreamSource(PlaybackMetrics.STREAM_SOURCE_NETWORK)
                        .setStreamType(PlaybackMetrics.STREAM_TYPE_OTHER)
                        .setPlaybackType(PlaybackMetrics.PLAYBACK_TYPE_LIVE)
                        .setDrmType(PlaybackMetrics.DRM_TYPE_WIDEVINE_L1)
                        .setContentType(PlaybackMetrics.CONTENT_TYPE_MAIN)
                        .setPlayerName("ExoPlayer")
                        .setPlayerVersion("1.01x")
                        .setVideoFramesPlayed(1024)
                        .setVideoFramesDropped(32)
                        .setAudioUnderrunCount(22)
                        .setNetworkBytesRead(102400)
                        .setLocalBytesRead(2000)
                        .setNetworkTransferDurationMillis(6000)
                        .setDrmSessionId(new byte[]{2, 3, 3, 10})
                        .setMetricsBundle(new Bundle())
                        .addExperimentId(123)
                        .build();
        s.reportPlaybackMetrics(e);
        writeSessionIdToFile(s.getSessionId().getStringId());
        resetProperties();
    }

    /**
     * Open aaudio low latency output stream and then close
     */
    @Test
    public native void testAAudioLowLatencyOutputStream();

    /**
     * Open aaudio low latency input stream and then close
     */
    @Test
    public native void testAAudioLowLatencyInputStream();

    /**
     * Open aaudio legacy output stream and then close
     */
    @Test
    public native void testAAudioLegacyOutputStream();

    /**
     * Open aaudio legacy input stream and then close
     */
    @Test
    public native void testAAudioLegacyInputStream();

    private void writeSessionIdToFile(String stringId) {
        Log.i(TAG, "log_session_id=" + stringId);
        Bundle b = new Bundle();
        // TODO(b/265311058): use a common constant for metrics keys.
        b.putString("log_session_id", stringId);
        SendToInstrumentation.sendBundle(InstrumentationRegistry.getInstrumentation(), b);
    }
}