From 75803e6655f6096cf8c88b3bdba569e9e8f1f1d9 Mon Sep 17 00:00:00 2001 From: Gautier de Lataillade Date: Mon, 15 Jul 2024 16:10:14 +0200 Subject: [PATCH] Increment plugin version to 3.1.5 --- CHANGELOG.md | 4 +++ .../gdelataillade/alarm/alarm/AlarmService.kt | 1 + .../alarm/services/VolumeService.kt | 30 ++++++++++++++--- example/lib/screens/home.dart | 2 +- example/pubspec.lock | 32 +++++++------------ pubspec.yaml | 2 +- 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c714fe53..8928acb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.5 +* [Android] Fix volume/focus post-alarm. +* Export `AlarmSettings` class in `Alarm` class. + ## 3.1.4 * [Android] Add more type safety. diff --git a/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmService.kt b/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmService.kt index dc715b23..580b5385 100644 --- a/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmService.kt +++ b/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmService.kt @@ -142,6 +142,7 @@ class AlarmService : Service() { audioService?.cleanUp() vibrationService?.stopVibrating() volumeService?.restorePreviousVolume(showSystemUI) + volumeService?.abandonAudioFocus() stopForeground(true) diff --git a/android/src/main/kotlin/com/gdelataillade/alarm/services/VolumeService.kt b/android/src/main/kotlin/com/gdelataillade/alarm/services/VolumeService.kt index 4f93f376..9efa156e 100644 --- a/android/src/main/kotlin/com/gdelataillade/alarm/services/VolumeService.kt +++ b/android/src/main/kotlin/com/gdelataillade/alarm/services/VolumeService.kt @@ -6,10 +6,12 @@ import android.media.AudioAttributes import android.media.AudioFocusRequest import android.os.Build import kotlin.math.round +import io.flutter.Log class VolumeService(private val context: Context) { private var previousVolume: Int? = null private val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager + private var focusRequest: AudioFocusRequest? = null fun setVolume(volume: Double, showSystemUI: Boolean) { val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) @@ -32,22 +34,40 @@ class VolumeService(private val context: Context) { .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build() - val focusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) + focusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) .setAudioAttributes(audioAttributes) .build() - audioManager.requestAudioFocus(focusRequest) + val result = audioManager.requestAudioFocus(focusRequest!!) + if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { + Log.d("VolumeService", "Audio focus request granted") + } else { + Log.e("VolumeService", "Audio focus request failed") + } } else { @Suppress("DEPRECATION") - audioManager.requestAudioFocus( + val result = audioManager.requestAudioFocus( null, AudioManager.STREAM_ALARM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK ) + if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { + Log.d("VolumeService", "Audio focus request granted") + } else { + Log.e("VolumeService", "Audio focus request failed") + } } } fun abandonAudioFocus() { - audioManager.abandonAudioFocus(null) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + focusRequest?.let { + audioManager.abandonAudioFocusRequest(it) + } + } else { + @Suppress("DEPRECATION") + audioManager.abandonAudioFocus(null) + } + Log.d("VolumeService", "Audio focus abandoned") } -} +} \ No newline at end of file diff --git a/example/lib/screens/home.dart b/example/lib/screens/home.dart index 12e74b19..9bfb4992 100644 --- a/example/lib/screens/home.dart +++ b/example/lib/screens/home.dart @@ -110,7 +110,7 @@ class _ExampleAlarmHomeScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text('alarm 3.1.4')), + appBar: AppBar(title: const Text('alarm 3.1.5')), body: SafeArea( child: alarms.isNotEmpty ? ListView.separated( diff --git a/example/pubspec.lock b/example/pubspec.lock index 24720000..589e3178 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -179,10 +179,10 @@ packages: dependency: transitive description: name: path_provider_windows - sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" + sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.3.0" permission_handler: dependency: "direct main" description: @@ -195,18 +195,18 @@ packages: dependency: transitive description: name: permission_handler_android - sha256: "8bb852cd759488893805c3161d0b2b5db55db52f773dbb014420b304055ba2c5" + sha256: b29a799ca03be9f999aa6c39f7de5209482d638e6f857f6b93b0875c618b7e54 url: "https://pub.dev" source: hosted - version: "12.0.6" + version: "12.0.7" permission_handler_apple: dependency: transitive description: name: permission_handler_apple - sha256: e9ad66020b89ff1b63908f247c2c6f931c6e62699b756ef8b3c4569350cd8662 + sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0 url: "https://pub.dev" source: hosted - version: "9.4.4" + version: "9.4.5" permission_handler_html: dependency: transitive description: @@ -235,10 +235,10 @@ packages: dependency: transitive description: name: platform - sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65" url: "https://pub.dev" source: hosted - version: "3.1.4" + version: "3.1.5" plugin_platform_interface: dependency: transitive description: @@ -259,10 +259,10 @@ packages: dependency: transitive description: name: shared_preferences_android - sha256: "1ee8bf911094a1b592de7ab29add6f826a7331fb854273d55918693d5364a1f2" + sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577" url: "https://pub.dev" source: hosted - version: "2.2.2" + version: "2.2.3" shared_preferences_foundation: dependency: transitive description: @@ -388,14 +388,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.1" - win32: - dependency: transitive - description: - name: win32 - sha256: "0eaf06e3446824099858367950a813472af675116bf63f008a4c2a75ae13e9cb" - url: "https://pub.dev" - source: hosted - version: "5.5.0" xdg_directories: dependency: transitive description: @@ -405,5 +397,5 @@ packages: source: hosted version: "1.0.4" sdks: - dart: ">=3.3.0 <4.0.0" - flutter: ">=3.19.0" + dart: ">=3.4.0 <4.0.0" + flutter: ">=3.22.0" diff --git a/pubspec.yaml b/pubspec.yaml index 799a4f7e..5bce0159 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: alarm description: A simple Flutter alarm manager plugin for both iOS and Android. -version: 3.1.4 +version: 3.1.5 homepage: https://github.com/gdelataillade/alarm environment: