Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class MainApplicationKT : MultiDexApplication() {
setupOneSignalListeners()

// Request permission - this will internally switch to Main thread for UI operations
// Even though the MainActivity comes on top of this, we can still request permission by tapping the prompt push button.
OneSignal.Notifications.requestPermission(true)

Log.d(Tag.LOG_TAG, Text.ONESIGNAL_SDK_INIT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onesignal.sdktest.model;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import com.google.android.material.appbar.AppBarLayout;
Expand Down Expand Up @@ -54,6 +55,9 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RequiresApi(api = Build.VERSION_CODES.N)
public class MainActivityViewModel implements ActivityViewModel, IPushSubscriptionObserver {
Expand Down Expand Up @@ -791,12 +795,6 @@ private void setupPushNotificationLayout() {

private void setupSubscriptionSwitch() {
refreshSubscriptionState();

pushSubscriptionEnabledRelativeLayout.setOnClickListener(v -> {
boolean isSubscriptionEnabled = !pushSubscriptionEnabledSwitch.isChecked();
pushSubscriptionEnabledSwitch.setChecked(isSubscriptionEnabled);
});

// Add a listener to toggle the push notification enablement for the push subscription.
pushSubscriptionEnabledSwitch.setOnClickListener(v -> {
IPushSubscription subscription = OneSignal.getUser().getPushSubscription();
Expand All @@ -811,7 +809,12 @@ private void setupSubscriptionSwitch() {

private void setupPromptPushButton() {
promptPushButton.setOnClickListener(v -> {
OneSignal.getUser().getPushSubscription().optIn();
ExecutorService executor = Executors.newSingleThreadExecutor();
@SuppressLint({"NewApi", "LocalSuppress"}) CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
OneSignal.getNotifications().requestPermission(true, Continue.none());
}, executor);
future.join(); // Waits for the task to complete
executor.shutdown();
});
}

Expand Down
22 changes: 22 additions & 0 deletions OneSignalSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ buildscript {
huaweiHMSPushVersion = '6.3.0.304'
huaweiHMSLocationVersion = '4.0.0.300'
kotlinVersion = '1.7.10'
coroutinesVersion = '1.7.3'
kotestVersion = '5.8.0'
ktlintPluginVersion = '11.6.1'
ktlintVersion = '1.0.1'
// DO NOT upgrade for tests, using an old version so it matches AOSP
tdunningJsonForTest = '1.0'
// AndroidX Lifecycle and Activity versions
lifecycleVersion = '2.6.2'
activityVersion = '1.7.2'

sharedRepos = {
google()
Expand Down Expand Up @@ -55,4 +59,22 @@ allprojects {
// Huawei maven
maven { url 'https://developer.huawei.com/repo/' }
}

// Force all modules to use the same Kotlin version
configurations.all {
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
force "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion"

// Exclude deprecated jdk7/jdk8 variants
eachDependency { details ->
if (details.requested.group == 'org.jetbrains.kotlin') {
if (details.requested.name == 'kotlin-stdlib-jdk7' ||
details.requested.name == 'kotlin-stdlib-jdk8') {
details.useTarget "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
}
}
}
}
Comment on lines +63 to +79
Copy link
Copy Markdown
Member

@jkasten2 jkasten2 Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend we make sure this substitution works before publishing the 5.4.0 release. I have concerns if this really works correctly when it comes to the dependencies in the .aar files.

}
8 changes: 7 additions & 1 deletion OneSignalSDK/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
# Remove when creating an .aar build.
#android.enableAapt2=false

org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to increase the memory for running tests


# Gradle daemon optimization
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true

# Enables D8 for all modules.
android.enableD8 = true
Expand Down
17 changes: 12 additions & 5 deletions OneSignalSDK/onesignal/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ android {
testOptions {
unitTests.all {
maxParallelForks 1
maxHeapSize '2048m'
maxHeapSize '3072m'
jvmArgs '-XX:MaxMetaspaceSize=256m', '-XX:+UseG1GC', '-XX:+UseStringDeduplication'
}
unitTests {
includeAndroidResources = true
Expand Down Expand Up @@ -68,9 +69,14 @@ ext {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed stdlib-jdk7 to stdlib.

context: I had to add these libraries to get the standard setup going to use Android View Models and lifescope methods.
androidx.lifecycle:lifecycle-viewmodel-ktx
androidx.lifecycle:lifecycle-runtime-ktx
androidx.activity:activity-ktx

And now to test this code, I had to upgrade Roboelectric test library which then began complaining about duplicate class.

Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.10.jar -> kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and kotlin-stdlib-jdk8-1.7.20.jar -> kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)

So I moved from stdlib-jdk7 to stdlib. The stdlib is a unified class that includes all functionality, avoids multiple stdlib variants with different versions.
https://mbonnin.medium.com/the-different-kotlin-stdlibs-explained-83d7c6bf293 this guy explains in detail.

But if you folks know something where we have to be dependent for jdk 7 explicitly, please call it out

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want to support Android 5 (API level 21). This seems to still work correctly from what I have read and also tested to confirm.

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"

// AndroidX Lifecycle and Activity
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.activity:activity-ktx:$activityVersion"

compileOnly('com.amazon.device:amazon-appstore-sdk:[3.0.1, 3.0.99]')

Expand All @@ -87,13 +93,14 @@ dependencies {
testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-property:$kotestVersion")
testImplementation("org.robolectric:robolectric:4.8.1")
testImplementation("org.robolectric:robolectric:4.10.3")
// kotest-extensions-android allows Robolectric to work with Kotest via @RobolectricTest
testImplementation("br.com.colman:kotest-extensions-android:0.1.1")
testImplementation("androidx.test:core-ktx:1.4.0")
testImplementation("androidx.test:core:1.4.0")
testImplementation("io.mockk:mockk:1.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")

// com.tdunning:json is needed for non-Robolectric tests.
testImplementation("com.tdunning:json:$tdunningJsonForTest")
Expand Down
Loading
Loading