diff --git a/zello-sdk-sample-contacts/build.gradle b/zello-sdk-sample-contacts/build.gradle index f3c04d6..8d1076f 100644 --- a/zello-sdk-sample-contacts/build.gradle +++ b/zello-sdk-sample-contacts/build.gradle @@ -4,9 +4,9 @@ buildscript { mavenCentral() } - dependencies { - classpath "com.android.tools.build:gradle:8.0.0" - } + dependencies { + classpath "com.android.tools.build:gradle:8.1.1" + } } repositories { @@ -23,8 +23,8 @@ java { } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" + compileSdk 34 + setBuildToolsVersion("33.0.1") namespace "com.zello.sdk.sample.contacts" buildFeatures { @@ -33,8 +33,8 @@ android { defaultConfig { applicationId "com.zello.sdk.sample.contacts" - minSdkVersion 23 - targetSdkVersion 33 + minSdk 23 + targetSdk 34 versionCode 1 versionName "1.0" } diff --git a/zello-sdk-sample-contacts/gradle/wrapper/gradle-wrapper.properties b/zello-sdk-sample-contacts/gradle/wrapper/gradle-wrapper.properties index 35ed23f..18695bc 100644 --- a/zello-sdk-sample-contacts/gradle/wrapper/gradle-wrapper.properties +++ b/zello-sdk-sample-contacts/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 15:52:58 CDT 2023 +#Fri Sep 08 15:53:50 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zello-sdk-sample-contacts/libs/zello-sdk.aar b/zello-sdk-sample-contacts/libs/zello-sdk.aar index 767e239..fc5e16a 100644 Binary files a/zello-sdk-sample-contacts/libs/zello-sdk.aar and b/zello-sdk-sample-contacts/libs/zello-sdk.aar differ diff --git a/zello-sdk-sample-misc/build.gradle b/zello-sdk-sample-misc/build.gradle index eeb1d98..1d4225f 100644 --- a/zello-sdk-sample-misc/build.gradle +++ b/zello-sdk-sample-misc/build.gradle @@ -1,58 +1,58 @@ buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath "com.android.tools.build:gradle:8.0.0" - } + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:8.1.1" + } } repositories { - google() - mavenCentral() + google() + mavenCentral() } apply plugin: "com.android.application" java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" - namespace "com.zello.sdk.sample.misc" - - buildFeatures { - buildConfig true - } - - defaultConfig { - applicationId "com.zello.sdk.sample.miscellaneous" - minSdkVersion 23 - targetSdkVersion 33 - versionCode 1 - versionName "1.0" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } + compileSdk 34 + setBuildToolsVersion("33.0.1") + namespace "com.zello.sdk.sample.misc" + + buildFeatures { + buildConfig true + } + + defaultConfig { + applicationId "com.zello.sdk.sample.miscellaneous" + minSdk 23 + targetSdk 34 + versionCode 1 + versionName "1.0" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } } dependencies { - implementation files("libs/zello-sdk.aar") - implementation "androidx.appcompat:appcompat:1.6.1" + implementation files("libs/zello-sdk.aar") + implementation "androidx.appcompat:appcompat:1.6.1" } diff --git a/zello-sdk-sample-misc/gradle/wrapper/gradle-wrapper.properties b/zello-sdk-sample-misc/gradle/wrapper/gradle-wrapper.properties index 35ed23f..18695bc 100644 --- a/zello-sdk-sample-misc/gradle/wrapper/gradle-wrapper.properties +++ b/zello-sdk-sample-misc/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 15:52:58 CDT 2023 +#Fri Sep 08 15:53:50 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zello-sdk-sample-misc/libs/zello-sdk.aar b/zello-sdk-sample-misc/libs/zello-sdk.aar index 767e239..fc5e16a 100644 Binary files a/zello-sdk-sample-misc/libs/zello-sdk.aar and b/zello-sdk-sample-misc/libs/zello-sdk.aar differ diff --git a/zello-sdk-sample-ptt/build.gradle b/zello-sdk-sample-ptt/build.gradle index ae6f3fc..974f18b 100644 --- a/zello-sdk-sample-ptt/build.gradle +++ b/zello-sdk-sample-ptt/build.gradle @@ -1,58 +1,58 @@ buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath "com.android.tools.build:gradle:8.0.0" - } + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:8.1.1" + } } repositories { - google() - mavenCentral() + google() + mavenCentral() } apply plugin: "com.android.application" java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" - namespace "com.zello.sdk.sample.ptt" - - buildFeatures { - buildConfig true - } - - defaultConfig { - applicationId "com.zello.sdk.sample.ptt" - minSdkVersion 23 - targetSdkVersion 33 - versionCode 1 - versionName "1.0" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } + compileSdk 34 + setBuildToolsVersion("33.0.1") + namespace "com.zello.sdk.sample.ptt" + + buildFeatures { + buildConfig true + } + + defaultConfig { + applicationId "com.zello.sdk.sample.ptt" + minSdk 23 + targetSdk 34 + versionCode 1 + versionName "1.0" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } } dependencies { - implementation files("libs/zello-sdk.aar") - implementation "androidx.appcompat:appcompat:1.6.1" + implementation files("libs/zello-sdk.aar") + implementation "androidx.appcompat:appcompat:1.6.1" } diff --git a/zello-sdk-sample-ptt/gradle/wrapper/gradle-wrapper.properties b/zello-sdk-sample-ptt/gradle/wrapper/gradle-wrapper.properties index 35ed23f..18695bc 100644 --- a/zello-sdk-sample-ptt/gradle/wrapper/gradle-wrapper.properties +++ b/zello-sdk-sample-ptt/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 15:52:58 CDT 2023 +#Fri Sep 08 15:53:50 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zello-sdk-sample-ptt/libs/zello-sdk.aar b/zello-sdk-sample-ptt/libs/zello-sdk.aar index 767e239..fc5e16a 100644 Binary files a/zello-sdk-sample-ptt/libs/zello-sdk.aar and b/zello-sdk-sample-ptt/libs/zello-sdk.aar differ diff --git a/zello-sdk-sample-signin/build.gradle b/zello-sdk-sample-signin/build.gradle index 1de1ba5..e68050f 100644 --- a/zello-sdk-sample-signin/build.gradle +++ b/zello-sdk-sample-signin/build.gradle @@ -1,54 +1,54 @@ buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath "com.android.tools.build:gradle:8.0.0" - } + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:8.1.1" + } } repositories { - google() - mavenCentral() + google() + mavenCentral() } apply plugin: "com.android.application" java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" - namespace "com.zello.sdk.sample.signin" - - defaultConfig { - applicationId "com.zello.sdk.sample" - minSdkVersion 23 - targetSdkVersion 33 - versionCode 1 - versionName "1.0" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } + compileSdk 34 + setBuildToolsVersion("33.0.1") + namespace "com.zello.sdk.sample.signin" + + defaultConfig { + applicationId "com.zello.sdk.sample" + minSdk 23 + targetSdk 34 + versionCode 1 + versionName "1.0" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } } dependencies { - implementation files("libs/zello-sdk.aar") - implementation "androidx.appcompat:appcompat:1.6.1" + implementation files("libs/zello-sdk.aar") + implementation "androidx.appcompat:appcompat:1.6.1" } diff --git a/zello-sdk-sample-signin/gradle/wrapper/gradle-wrapper.properties b/zello-sdk-sample-signin/gradle/wrapper/gradle-wrapper.properties index 35ed23f..18695bc 100644 --- a/zello-sdk-sample-signin/gradle/wrapper/gradle-wrapper.properties +++ b/zello-sdk-sample-signin/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 15:52:58 CDT 2023 +#Fri Sep 08 15:53:50 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zello-sdk-sample-signin/libs/zello-sdk.aar b/zello-sdk-sample-signin/libs/zello-sdk.aar index 767e239..fc5e16a 100644 Binary files a/zello-sdk-sample-signin/libs/zello-sdk.aar and b/zello-sdk-sample-signin/libs/zello-sdk.aar differ diff --git a/zello-sdk-sample/build.gradle b/zello-sdk-sample/build.gradle index 3540d52..353a41a 100644 --- a/zello-sdk-sample/build.gradle +++ b/zello-sdk-sample/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = "1.8.10" + ext.kotlin_version = "1.9.10" repositories { google() @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:8.0.0" + classpath "com.android.tools.build:gradle:8.1.1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -31,8 +31,8 @@ kotlin { } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" + compileSdk 34 + setBuildToolsVersion("33.0.1") namespace "com.zello.sdk.sample" buildFeatures { @@ -41,8 +41,8 @@ android { defaultConfig { applicationId "com.zello.sdk.sample" - minSdkVersion 23 - targetSdkVersion 33 + minSdk 23 + targetSdk 34 versionCode 1 versionName "1.0" } @@ -67,7 +67,7 @@ android { dependencies { implementation files("libs/zello-sdk.aar") implementation "androidx.appcompat:appcompat:1.6.1" - implementation "androidx.core:core-ktx:1.10.0" + implementation "androidx.core:core-ktx:1.10.1" implementation "androidx.media:media:1.6.0" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } diff --git a/zello-sdk-sample/gradle/wrapper/gradle-wrapper.properties b/zello-sdk-sample/gradle/wrapper/gradle-wrapper.properties index 35ed23f..18695bc 100644 --- a/zello-sdk-sample/gradle/wrapper/gradle-wrapper.properties +++ b/zello-sdk-sample/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 15:52:58 CDT 2023 +#Fri Sep 08 15:53:50 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zello-sdk-sample/libs/zello-sdk.aar b/zello-sdk-sample/libs/zello-sdk.aar index 767e239..fc5e16a 100644 Binary files a/zello-sdk-sample/libs/zello-sdk.aar and b/zello-sdk-sample/libs/zello-sdk.aar differ diff --git a/zello-sdk.aar b/zello-sdk.aar index 767e239..fc5e16a 100644 Binary files a/zello-sdk.aar and b/zello-sdk.aar differ diff --git a/zello-sdk/build.gradle b/zello-sdk/build.gradle index 50fdc92..6e3a126 100644 --- a/zello-sdk/build.gradle +++ b/zello-sdk/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = "1.8.10" + ext.kotlin_version = "1.9.10" repositories { google() @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:8.0.0" + classpath "com.android.tools.build:gradle:8.1.1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -31,7 +31,7 @@ kotlin { } dependencies { - implementation "androidx.core:core-ktx:1.10.0" + implementation "androidx.core:core-ktx:1.10.1" implementation "androidx.media:media:1.6.0" implementation "androidx.annotation:annotation:1.6.0" } @@ -40,7 +40,7 @@ def sourceAarName = "zello-sdk-release.aar" def targetAarName = "zello-sdk.aar" def sourceAarPath = "build/outputs/aar/${sourceAarName}" -task zelloSdkAarDeployReleaseToRoot() { +tasks.register("zelloSdkAarDeployReleaseToRoot") { description "Copies SDK AAR to the root folder of the project" delete { "../${targetAarName}" @@ -54,7 +54,7 @@ task zelloSdkAarDeployReleaseToRoot() { } // This add a task that deploys a release build of the library to the sample projects /lib folders. -task zelloSdkAarDeployReleaseToSamples { +tasks.register("zelloSdkAarDeployReleaseToSamples") { description "Copies SDK AAR to all sample projects" delete { "../zello-sdk-sample/libs/${targetAarName}" @@ -96,20 +96,17 @@ task zelloSdkAarDeployReleaseToSamples { into "../zello-sdk-sample-signin/libs/" rename("${sourceAarName}", "${targetAarName}") } - dependencies { - implementation "androidx.annotation:annotation:1.6.0" - } shouldRunAfter "assembleRelease" } -task zelloSdkDocDelete(type: Delete) { +tasks.register("zelloSdkDocDelete", Delete) { description "Deletes Zello SDK Javadoc from the project root folder" delete "../docs/zello-sdk-documentation" } -android.libraryVariants.all { variant -> +android.libraryVariants.configureEach { variant -> if (variant.name == "release") { - task zelloSdkDocCreate(type: Javadoc, dependsOn: "zelloSdkDocDelete") { + tasks.register("zelloSdkDocCreate", Javadoc) { title "" description "Creates Zello SDK Javadoc in the project root folder" destinationDir = new File("${projectDir}/../docs", "zello-sdk-documentation") @@ -131,11 +128,12 @@ android.libraryVariants.all { variant -> options.noDeprecatedList = true options.stylesheetFile = new File(projectDir, "../docs/stylesheet.css") shouldRunAfter "assembleRelease" + dependsOn "zelloSdkDocDelete" } } } -tasks.whenTaskAdded { task -> +tasks.configureEach { task -> if (task.name == "assembleRelease") { task.finalizedBy "zelloSdkAarDeployReleaseToRoot" task.finalizedBy "zelloSdkAarDeployReleaseToSamples" @@ -143,20 +141,20 @@ tasks.whenTaskAdded { task -> } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" + compileSdk 34 + setBuildToolsVersion("33.0.1") namespace "com.zello.sdk" buildFeatures { buildConfig true } - ext.sdkVersion = "5.22.0" + ext.sdkVersion = "5.28.0" defaultConfig { - targetSdkVersion 33 - minSdkVersion 23 - manifestPlaceholders = [sdkVersion: "$sdkVersion"] + minSdk 23 + targetSdk 34 + manifestPlaceholders.sdkVersion = "$sdkVersion" buildConfigField "String", "SDK_VERSION", "\"$sdkVersion\"" consumerProguardFiles "consumer-rules.pro" } diff --git a/zello-sdk/gradle/wrapper/gradle-wrapper.properties b/zello-sdk/gradle/wrapper/gradle-wrapper.properties index 35ed23f..4a8c0e8 100644 --- a/zello-sdk/gradle/wrapper/gradle-wrapper.properties +++ b/zello-sdk/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 01 15:52:58 CDT 2023 +#Fri Sep 08 15:31:37 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/zello-sdk/src/main/java/com/zello/sdk/Audio.java b/zello-sdk/src/main/java/com/zello/sdk/Audio.java index 8bf349a..1774122 100644 --- a/zello-sdk/src/main/java/com/zello/sdk/Audio.java +++ b/zello-sdk/src/main/java/com/zello/sdk/Audio.java @@ -7,6 +7,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; /** *

@@ -22,19 +23,18 @@ public class Audio { //region Private Properties private boolean _sp, _ep, _bt; // Speaker, earpiece, bluetooth - private int _wearable = -1; // Wearable index private int _wearables; // Wearable device count private boolean _changing; private @NonNull AudioMode _mode = AudioMode.SPEAKER; // Current mode private @Nullable BroadcastReceiver _receiver; private @Nullable Context _context; - private @Nullable String _package; + private final @Nullable String _package; //endregion //region Package Private Methods - Audio(String packageName, Context context) { + Audio(@Nullable String packageName, @Nullable Context context) { _package = packageName; _context = context; if (context != null && packageName != null) { @@ -48,8 +48,9 @@ public void onReceive(Context context, Intent intent) { } } }; - Intent intentStickyAudioState = context.registerReceiver(_receiver, new IntentFilter(packageName + "." + Constants.ACTION_AUDIO_STATE)); - updateAudioState(intentStickyAudioState); + IntentFilter filter = new IntentFilter(packageName + "." + Constants.ACTION_AUDIO_STATE); + Intent intent = ContextCompat.registerReceiver(context, _receiver, filter, ContextCompat.RECEIVER_EXPORTED); + updateAudioState(intent); } } @@ -72,18 +73,12 @@ void close() { * @return boolean indicating if the mode is available for the device. */ public boolean isModeAvailable(@NonNull AudioMode mode) { - switch (mode) { - case SPEAKER: - return _sp; - case EARPIECE: - return _ep; - case BLUETOOTH: - return _bt; - case WEARABLE: - return _wearables > 0; - default: - return false; - } + return switch (mode) { + case SPEAKER -> _sp; + case EARPIECE -> _ep; + case BLUETOOTH -> _bt; + case WEARABLE -> _wearables > 0; + }; } /** @@ -154,20 +149,12 @@ private void doSetMode(@NonNull AudioMode mode, int wearable) { } Intent intent = new Intent(_package + "." + Constants.ACTION_COMMAND); intent.putExtra(Constants.EXTRA_COMMAND, Constants.VALUE_SET_AUDIO); - final String command; - switch (mode) { - case BLUETOOTH: - command = Constants.EXTRA_BT; - break; - case EARPIECE: - command = Constants.EXTRA_EP; - break; - case WEARABLE: - command = Constants.EXTRA_WA + wearable; - break; - default: - command = Constants.EXTRA_SP; - } + String command = switch (mode) { + case BLUETOOTH -> Constants.EXTRA_BT; + case EARPIECE -> Constants.EXTRA_EP; + case WEARABLE -> Constants.EXTRA_WA + wearable; + default -> Constants.EXTRA_SP; + }; intent.putExtra(Constants.EXTRA_MODE, command); context.sendBroadcast(intent); } @@ -179,11 +166,6 @@ private void updateAudioState(@Nullable Intent intent) { String mode = Util.emptyIfNull(intent.getStringExtra(Constants.EXTRA_MODE)); if (mode.startsWith(Constants.EXTRA_WA)) { _mode = AudioMode.WEARABLE; - try { - _wearable = Integer.parseInt(mode.substring(Constants.EXTRA_WA.length())); - } catch (NumberFormatException ignore) { - _wearable = -1; - } } else if (mode.equals(Constants.EXTRA_EP)) { _mode = AudioMode.EARPIECE; } else if (mode.equals(Constants.EXTRA_BT)) { diff --git a/zello-sdk/src/main/java/com/zello/sdk/Sdk.java b/zello-sdk/src/main/java/com/zello/sdk/Sdk.java index 42729d6..fdbe022 100644 --- a/zello-sdk/src/main/java/com/zello/sdk/Sdk.java +++ b/zello-sdk/src/main/java/com/zello/sdk/Sdk.java @@ -97,9 +97,9 @@ void onDestroy() { if (_context == null) { return; } + unregisterPackageReceivers(); disconnect(); _resumed = false; - unregisterPackageEventReceivers(); Contacts contacts = _contacts; if (contacts != null) { contacts.close(); @@ -761,19 +761,19 @@ public void onReceive(Context context, Intent intent) { } } }; - IntentFilter filterPackage = new IntentFilter(); - filterPackage.addAction(Intent.ACTION_PACKAGE_ADDED); - filterPackage.addAction(Intent.ACTION_PACKAGE_REMOVED); - filterPackage.addAction(Intent.ACTION_PACKAGE_REPLACED); - filterPackage.addAction(Intent.ACTION_PACKAGE_CHANGED); - filterPackage.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED); - filterPackage.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); - filterPackage.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); - filterPackage.addDataScheme("package"); - _context.registerReceiver(_receiverPackage, filterPackage); - } - - private void unregisterPackageEventReceivers() { + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_PACKAGE_ADDED); + filter.addAction(Intent.ACTION_PACKAGE_REMOVED); + filter.addAction(Intent.ACTION_PACKAGE_REPLACED); + filter.addAction(Intent.ACTION_PACKAGE_CHANGED); + filter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED); + filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); + filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); + filter.addDataScheme("package"); + ContextCompat.registerReceiver(_context, _receiverPackage, filter, ContextCompat.RECEIVER_EXPORTED); + } + + private void unregisterPackageReceivers() { if (_context == null) { return; } @@ -795,8 +795,9 @@ public void onReceive(Context context, Intent intent) { updateAppState(intent); } }; - Intent intentStickyAppState = _context.registerReceiver(_receiverAppState, new IntentFilter(_connectedPackage + "." + Constants.ACTION_APP_STATE)); - updateAppState(intentStickyAppState); + IntentFilter filter = new IntentFilter(_connectedPackage + "." + Constants.ACTION_APP_STATE); + Intent intent = ContextCompat.registerReceiver(_context, _receiverAppState, filter, ContextCompat.RECEIVER_EXPORTED); + updateAppState(intent); updateContacts(); } if (_receiverPermissionErrors == null) { @@ -807,7 +808,8 @@ public void onReceive(Context context, Intent intent) { handlePermissionError(intent); } }; - _context.registerReceiver(_receiverPermissionErrors, new IntentFilter(_connectedPackage + "." + Constants.ACTION_PERMISSION_ERRORS)); + IntentFilter filter = new IntentFilter(_connectedPackage + "." + Constants.ACTION_PERMISSION_ERRORS); + ContextCompat.registerReceiver(_context, _receiverPermissionErrors, filter, ContextCompat.RECEIVER_EXPORTED); } if (_receiverMessageState == null) { // Register to receive message state broadcasts @@ -817,8 +819,9 @@ public void onReceive(Context context, Intent intent) { updateMessageState(intent); } }; - Intent intentStickyMessageState = _context.registerReceiver(_receiverMessageState, new IntentFilter(_connectedPackage + "." + Constants.ACTION_MESSAGE_STATE)); - updateMessageState(intentStickyMessageState); + IntentFilter filter = new IntentFilter(_connectedPackage + "." + Constants.ACTION_MESSAGE_STATE); + Intent intent = ContextCompat.registerReceiver(_context, _receiverMessageState, filter, ContextCompat.RECEIVER_EXPORTED); + updateMessageState(intent); } if (_receiverContactSelected == null) { // Register to receive selected contact broadcasts @@ -828,8 +831,9 @@ public void onReceive(Context context, Intent intent) { updateSelectedContact(intent); } }; - Intent intentStickySelectedContact = _context.registerReceiver(_receiverContactSelected, new IntentFilter(_connectedPackage + "." + Constants.ACTION_CONTACT_SELECTED)); - updateSelectedContact(intentStickySelectedContact); + IntentFilter filter = new IntentFilter(_connectedPackage + "." + Constants.ACTION_CONTACT_SELECTED); + Intent intent = ContextCompat.registerReceiver(_context, _receiverContactSelected, filter, ContextCompat.RECEIVER_EXPORTED); + updateSelectedContact(intent); } if (_receiverActiveTab == null) { // Register to receive last selected contact list tab @@ -839,7 +843,8 @@ public void onReceive(Context context, Intent intent) { updateSelectedTab(intent); } }; - _context.registerReceiver(_receiverActiveTab, new IntentFilter(_activeTabAction)); + IntentFilter filter = new IntentFilter(_activeTabAction); + ContextCompat.registerReceiver(_context, _receiverActiveTab, filter, ContextCompat.RECEIVER_EXPORTED); } if (_receiverBtAccessoryState == null) { // Register to receive bluetooth accessory state broadcasts @@ -849,7 +854,8 @@ public void onReceive(Context context, Intent intent) { handleBtAccessoryState(intent); } }; - _context.registerReceiver(_receiverBtAccessoryState, new IntentFilter(_connectedPackage + "." + Constants.ACTION_BT_ACCESSORY_STATE)); + IntentFilter filter = new IntentFilter(_connectedPackage + "." + Constants.ACTION_BT_ACCESSORY_STATE); + ContextCompat.registerReceiver(_context, _receiverBtAccessoryState, filter, ContextCompat.RECEIVER_EXPORTED); } } @@ -857,10 +863,6 @@ private void unregisterAppStateReceivers() { if (_context == null) { return; } - if (_receiverPackage != null) { - _context.unregisterReceiver(_receiverPackage); - _receiverPackage = null; - } if (_receiverAppState != null) { _context.unregisterReceiver(_receiverAppState); _receiverAppState = null; @@ -1287,47 +1289,32 @@ private void fireAppStateChanged() { } static @NonNull ContactType intToContactType(int type) { - switch (type) { - case 1: - return ContactType.CHANNEL; - case 3: - return ContactType.GROUP; - case 2: - return ContactType.GATEWAY; - case 4: - return ContactType.CONVERSATION; - default: - return ContactType.USER; - } + return switch (type) { + case 1 -> ContactType.CHANNEL; + case 3 -> ContactType.GROUP; + case 2 -> ContactType.GATEWAY; + case 4 -> ContactType.CONVERSATION; + default -> ContactType.USER; + }; } static @NonNull ContactStatus intToContactStatus(int status) { - switch (status) { - case 1: - return ContactStatus.STANDBY; - case 2: - case 4: - case 5: - return ContactStatus.AVAILABLE; - case 3: - return ContactStatus.BUSY; - case 6: - return ContactStatus.CONNECTING; - default: - return ContactStatus.OFFLINE; - } + return switch (status) { + case 1 -> ContactStatus.STANDBY; + case 2, 4, 5 -> ContactStatus.AVAILABLE; + case 3 -> ContactStatus.BUSY; + case 6 -> ContactStatus.CONNECTING; + default -> ContactStatus.OFFLINE; + }; } private static @Nullable String tabToString(@Nullable Tab tab) { if (tab != null) { - switch (tab) { - case RECENTS: - return Constants.VALUE_RECENTS; - case USERS: - return Constants.VALUE_USERS; - case CHANNELS: - return Constants.VALUE_CHANNELS; - } + return switch (tab) { + case RECENTS -> Constants.VALUE_RECENTS; + case USERS -> Constants.VALUE_USERS; + case CHANNELS -> Constants.VALUE_CHANNELS; + }; } return null; }