Merge pull request #1549 from MGaetan89:min_sdk_21

PiperOrigin-RevId: 656358426
This commit is contained in:
Copybara-Service 2024-07-26 05:11:46 -07:00
commit ccf704b30b
49 changed files with 32 additions and 157 deletions

View File

@ -100,12 +100,6 @@ compileOptions {
}
```
#### 3. Enable multidex
If your Gradle `minSdkVersion` is 20 or lower, you should
[enable multidex](https://developer.android.com/studio/build/multidex) in order
to prevent build errors.
### Locally
Cloning the repository and depending on the modules locally is required when

View File

@ -27,7 +27,6 @@ android {
aarMetadata {
minCompileSdk = project.ext.compileSdkVersion
}
multiDexEnabled true
}
compileOptions {
@ -42,7 +41,3 @@ android {
unitTests.includeAndroidResources true
}
}
dependencies {
androidTestImplementation 'androidx.multidex:multidex:' + androidxMultidexVersion
}

View File

@ -47,7 +47,6 @@ project.ext {
androidxExifInterfaceVersion = '1.3.6'
androidxLifecycleVersion = '2.6.0'
androidxMediaVersion = '1.7.0'
androidxMultidexVersion = '2.0.1'
androidxRecyclerViewVersion = '1.3.0'
androidxMaterialVersion = '1.8.0'
androidxTestCoreVersion = '1.5.0'

View File

@ -29,7 +29,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -62,7 +61,6 @@ dependencies {
implementation project(modulePrefix + 'lib-ui')
implementation project(modulePrefix + 'lib-cast')
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
}

View File

@ -23,7 +23,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:label="@string/application_name"
android:icon="@mipmap/ic_launcher"
android:largeHeap="true"

View File

@ -1,23 +0,0 @@
/*
* Copyright 2020 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 androidx.media3.demo.cast;
import androidx.multidex.MultiDexApplication;
// Note: Multidex is enabled in code not AndroidManifest.xml because the internal build system
// doesn't dejetify MultiDexApplication in AndroidManifest.xml.
/** Application for multidex support. */
public final class DemoApplication extends MultiDexApplication {}

View File

@ -32,7 +32,7 @@ android {
defaultConfig {
versionName project.ext.releaseVersion
versionCode project.ext.releaseVersionCode
minSdkVersion 21
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
}

View File

@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Media3ComposeDemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
@ -25,9 +25,7 @@
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">
?attr/colorPrimaryVariant
</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Media3ComposeDemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
@ -25,9 +25,7 @@
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">
?attr/colorPrimaryVariant
</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -29,9 +29,8 @@ android {
defaultConfig {
versionName project.ext.releaseVersion
versionCode project.ext.releaseVersionCode
minSdkVersion 21
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -58,6 +57,5 @@ dependencies {
implementation project(modulePrefix + 'lib-transformer')
implementation project(modulePrefix + 'lib-ui')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
}

View File

@ -29,7 +29,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -55,6 +54,5 @@ dependencies {
implementation project(modulePrefix + 'lib-exoplayer-smoothstreaming')
implementation project(modulePrefix + 'lib-ui')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
}

View File

@ -22,7 +22,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/application_name">

View File

@ -31,7 +31,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -75,7 +74,6 @@ dependencies {
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation project(modulePrefix + 'lib-exoplayer')
implementation project(modulePrefix + 'lib-exoplayer-dash')

View File

@ -40,7 +40,6 @@
android:largeHeap="true"
android:allowBackup="false"
android:supportsRtl="true"
android:name="androidx.multidex.MultiDexApplication"
tools:targetApi="29">
<activity android:name=".SampleChooserActivity"

View File

@ -34,7 +34,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -65,7 +64,6 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-common:' + androidxLifecycleVersion
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:' + androidxLifecycleVersion
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-guava:' + kotlinxCoroutinesVersion
implementation project(modulePrefix + 'lib-ui')

View File

@ -14,7 +14,6 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidx.media3.demo.session">
<uses-sdk/>
@ -23,12 +22,10 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Media3Demo"
tools:replace="android:name">
android:theme="@style/Theme.Media3Demo">
<!-- Declare that this session demo supports Android Auto. -->
<meta-data

View File

@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Media3Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
@ -25,9 +25,7 @@
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">
?attr/colorPrimaryVariant
</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Media3Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
@ -25,9 +25,7 @@
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">
?attr/colorPrimaryVariant
</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -34,7 +34,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.automotiveMinSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -60,7 +59,6 @@ android {
dependencies {
implementation 'androidx.core:core-ktx:' + androidxCoreVersion
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation project(modulePrefix + 'lib-session')
implementation project(modulePrefix + 'demo-session-service')

View File

@ -14,7 +14,6 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidx.media3.demo.session.automotive">
<uses-sdk/>
@ -39,13 +38,11 @@
android:resource="@xml/automotive_app_desc"/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
android:taskAffinity=""
android:appCategory="audio"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
tools:replace="android:name">
android:label="@string/app_name">
<meta-data
android:name="androidx.car.app.TintableAttributionIcon"

View File

@ -33,7 +33,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -54,7 +53,6 @@ android {
dependencies {
implementation 'androidx.core:core-ktx:' + androidxCoreVersion
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation project(modulePrefix + 'lib-exoplayer')
implementation project(modulePrefix + 'lib-exoplayer-dash')
implementation project(modulePrefix + 'lib-exoplayer-hls')

View File

@ -34,7 +34,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -80,7 +79,6 @@ dependencies {
implementation 'androidx.core:core-ktx:' + androidxCoreVersion
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation project(modulePrefix + 'lib-exoplayer')
implementation project(modulePrefix + 'lib-exoplayer-dash')

View File

@ -14,17 +14,14 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidx.media3.demo.shortform">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="androidx.multidex.MultiDexApplication"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"
android:taskAffinity=""
tools:replace="android:name">
android:taskAffinity="">
<activity
android:exported="true"
android:name=".MainActivity">

View File

@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Media3Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
@ -25,9 +25,7 @@
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">
?attr/colorPrimaryVariant
</item>
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -29,9 +29,8 @@ android {
defaultConfig {
versionName project.ext.releaseVersion
versionCode project.ext.releaseVersionCode
minSdkVersion 21
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
}
buildTypes {
@ -77,7 +76,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.constraintlayout:constraintlayout:' + androidxConstraintLayoutVersion
implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation project(modulePrefix + 'lib-effect')
implementation project(modulePrefix + 'lib-exoplayer')

View File

@ -23,7 +23,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
android:usesCleartextTraffic="true"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">

View File

@ -23,7 +23,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
android:usesCleartextTraffic="true"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"/>

View File

@ -16,7 +16,7 @@ apply from: "$gradle.ext.androidxMediaSettingsDir/common_library_config.gradle"
android {
namespace 'androidx.media3.datasource.okhttp'
defaultConfig.minSdkVersion 21
defaultConfig.minSdkVersion project.ext.minSdkVersion
publishing {
singleVariant('release') {

View File

@ -22,7 +22,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"/>

View File

@ -22,7 +22,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"/>

View File

@ -22,7 +22,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"/>

View File

@ -23,7 +23,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"
android:usesCleartextTraffic="true"/>

View File

@ -2613,11 +2613,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* buffer with {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM} set. False otherwise.
*/
private static boolean codecNeedsEosFlushWorkaround(String name) {
return (Util.SDK_INT <= 23 && "OMX.google.vorbis.decoder".equals(name))
|| (Util.SDK_INT == 19
&& ("hb2000".equals(Util.DEVICE) || "stvm8".equals(Util.DEVICE))
&& ("OMX.amlogic.avc.decoder.awesome".equals(name)
|| "OMX.amlogic.avc.decoder.awesome.secure".equals(name)));
return Util.SDK_INT <= 23 && "OMX.google.vorbis.decoder".equals(name);
}
/**

View File

@ -1766,8 +1766,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
}
/**
* Renders the output buffer with the specified index. This method is only called if the platform
* API version of the device is 21 or later.
* Renders the output buffer with the specified index.
*
* @param codec The codec that owns the output buffer.
* @param index The index of the output buffer to drop.

View File

@ -24,7 +24,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
<activity android:name="androidx.media3.test.utils.HostActivity"

View File

@ -21,7 +21,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"
android:usesCleartextTraffic="true"/>

View File

@ -366,12 +366,6 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
}
}
if (player.isCommandAvailable(COMMAND_STOP)) {
// We must include a cancel intent for pre-L devices.
mediaStyle.setCancelButtonIntent(
actionFactory.createMediaActionPendingIntent(mediaSession, COMMAND_STOP));
}
long playbackStartTimeMs = getPlaybackStartTimeEpochMs(player);
boolean displayElapsedTimeWithChronometer = playbackStartTimeMs != C.TIME_UNSET;
builder

View File

@ -111,7 +111,6 @@ public class MediaStyleNotificationHelper {
/* package */ final MediaSession session;
/* package */ int @NullableType [] actionsToShowInCompact;
@Nullable /* package */ PendingIntent cancelButtonIntent;
/* package */ @MonotonicNonNull CharSequence remoteDeviceName;
/* package */ int remoteDeviceIconRes;
@Nullable /* package */ PendingIntent remoteDeviceIntent;
@ -138,23 +137,23 @@ public class MediaStyleNotificationHelper {
/**
* @deprecated This method is a no-op and usages can be safely removed. There is no recommended
* alternative (it was previously only operational on API &le; 21).
* alternative (it was previously only operational on API &lt; 21).
*/
@CanIgnoreReturnValue
@Deprecated
@SuppressWarnings("unused")
public MediaStyle setShowCancelButton(boolean show) {
return this;
}
/**
* Sets the pending intent to be sent when the cancel button is pressed. See {@link
* #setShowCancelButton}.
*
* @param pendingIntent the intent to be sent when the cancel button is pressed
* @deprecated This method is a no-op and usages can be safely removed. There is no recommended
* alternative (it was previously only operational on API &lt; 21).
*/
@CanIgnoreReturnValue
@Deprecated
@SuppressWarnings("unused")
public MediaStyle setCancelButtonIntent(PendingIntent pendingIntent) {
cancelButtonIntent = pendingIntent;
return this;
}

View File

@ -24,7 +24,6 @@
<uses-sdk/>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
<activity android:name="androidx.media3.test.utils.HostActivity"

View File

@ -40,7 +40,6 @@ dependencies {
implementation project(modulePrefix + 'test-session-common')
implementation project(modulePrefix + 'test-data')
implementation 'androidx.media:media:' + androidxMediaVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'androidx.test:core:' + androidxTestCoreVersion
implementation project(modulePrefix + 'test-data')
androidTestImplementation project(modulePrefix + 'lib-exoplayer')

View File

@ -19,7 +19,6 @@
<uses-sdk />
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"
android:usesCleartextTraffic="true" >

View File

@ -24,9 +24,7 @@
<package android:name="androidx.media3.test.session.test" />
</queries>
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false">
<application android:allowBackup="false">
<activity android:name="androidx.media3.test.session.common.SurfaceActivity"
android:exported="false" />

View File

@ -16,7 +16,7 @@ android {
namespace 'androidx.media3.transformer'
defaultConfig {
minSdkVersion 21
minSdkVersion project.ext.minSdkVersion
// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.

View File

@ -1156,7 +1156,6 @@ public class PlayerNotificationManager {
* duration} (like for example a live stream).
* <li>The media is not {@link Player#isPlayingAd() interrupted by an ad}.
* <li>The media is played at {@link Player#getPlaybackParameters() regular speed}.
* <li>The device is running at least API 21 (Lollipop).
* </ul>
*
* <p>See {@link NotificationCompat.Builder#setUsesChronometer(boolean)}.

View File

@ -41,7 +41,6 @@ def addMissingAarTypeToXml(xml) {
"androidx.leanback:leanback",
"androidx.media:media",
"androidx.media2:media2-session",
"androidx.multidex:multidex",
"androidx.recyclerview:recyclerview",
"androidx.test:core",
"androidx.test.ext:junit",

View File

@ -34,7 +34,6 @@ android {
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.appTargetSdkVersion
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
@ -62,7 +61,6 @@ android {
dependencies {
implementation 'androidx.core:core-ktx:' + androidxCoreVersion
implementation 'androidx.appcompat:appcompat:' + androidxAppCompatVersion
implementation 'androidx.multidex:multidex:' + androidxMultidexVersion
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation 'androidx.media:media:' + androidxMediaVersion
implementation project(modulePrefix + 'lib-session')

View File

@ -19,11 +19,8 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.media.session.MediaSessionManager as ActiveSessionManager
import android.os.Build
import android.os.Build.VERSION_CODES
import android.os.Bundle
import android.service.notification.NotificationListenerService
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.app.NotificationManagerCompat
@ -76,10 +73,7 @@ class LaunchActivity : AppCompatActivity() {
}
)
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
activeSessionListener = ActiveSessionListener()
}
mediaSessionApps = mediaAppListAdapter.addSection(R.string.media_app_header_media_service)
val mediaAppsList: RecyclerView? = findViewById(R.id.app_list)
@ -91,9 +85,7 @@ class LaunchActivity : AppCompatActivity() {
override fun onStart() {
super.onStart()
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
activeSessionListener!!.onStart()
}
// Finds apps that implement MediaSessionService, MediaLibraryService, or
// MediaBrowserServiceCompat.
@ -103,17 +95,12 @@ class LaunchActivity : AppCompatActivity() {
override fun onStop() {
super.onStop()
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
activeSessionListener!!.onStop()
}
}
/**
* Encapsulates the API 21+ functionality of looking for and observing updates to active media
* sessions. We only construct an instance of this class if the device is running L or later, to
* avoid any ClassNotFoundExceptions due to the use of MediaSession and related classes.
* Encapsulates the functionality of looking for and observing updates to active media sessions.
*/
@RequiresApi(VERSION_CODES.LOLLIPOP)
private inner class ActiveSessionListener {
private val activeSessionApps: MediaAppListAdapter.Section =
mediaAppListAdapter.addSection(R.string.media_app_header_active_session)
@ -170,10 +157,8 @@ class LaunchActivity : AppCompatActivity() {
/**
* A notification listener service that allows us to grab active media sessions from their
* notifications. This class is only used on API 21+ because the Android media framework added
* getActiveSessions in API 21.
* notifications.
*/
@RequiresApi(VERSION_CODES.LOLLIPOP)
class NotificationListener : NotificationListenerService() {
companion object {
// Helper method to check if our notification listener is enabled. In order to get active

View File

@ -20,9 +20,7 @@ import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Bitmap
import android.media.session.MediaController
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.media3.common.util.Util
import androidx.media3.session.SessionToken
@ -58,7 +56,6 @@ private constructor(
)
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun create(
packageManager: PackageManager,
resources: Resources,

View File

@ -21,15 +21,12 @@ import android.content.pm.PackageManager
import android.content.res.Resources
import android.media.session.MediaController
import android.media.session.MediaSessionManager
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.media3.testapp.controller.MediaAppDetails
/**
* Implementation of [FindMediaApps] that uses [MediaSessionManager] to populate the list of active
* media session apps.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
class FindActiveMediaSessionApps
constructor(
private val mediaSessionManager: MediaSessionManager,