Skip to content

Commit af55a25

Browse files
authored
Merge pull request #598 from OneSignal/public_requires_consent
Add requiresUserPrivacyConsent() getter
2 parents 3cc4c31 + 88d8056 commit af55a25

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,14 @@ public static void setRequiresUserPrivacyConsent(boolean required) {
894894
requiresUserPrivacyConsent = required;
895895
}
896896

897+
898+
/**
899+
* Indicates if the SDK is still waiting for the user to provide consent
900+
*/
901+
public static boolean requiresUserPrivacyConsent() {
902+
return requiresUserPrivacyConsent && !userProvidedPrivacyConsent();
903+
}
904+
897905
static boolean shouldLogUserPrivacyConsentErrorMessageForMethodName(String methodName) {
898906
if (requiresUserPrivacyConsent && !userProvidedPrivacyConsent()) {
899907
if (methodName != null)

OneSignalSDK/unittest/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,19 @@ public void onFailure(JSONObject response) {
22372237
postNotificationSuccess = postNotificationFailure = null;
22382238
}
22392239

2240+
@Test
2241+
public void shouldReturnCorrectConsentRequiredStatus() throws Exception {
2242+
OneSignal.setRequiresUserPrivacyConsent(true);
2243+
2244+
OneSignalInit();
2245+
2246+
assertTrue(OneSignal.requiresUserPrivacyConsent());
2247+
2248+
OneSignal.provideUserConsent(true);
2249+
2250+
assertFalse(OneSignal.requiresUserPrivacyConsent());
2251+
}
2252+
22402253
/*
22412254
// Can't get test to work from a app flow due to the main thread being locked one way or another in a robolectric env.
22422255
// Running ActivityLifecycleListener.focusHandlerThread...advanceToNextPostedRunnable waits on the main thread.

0 commit comments

Comments
 (0)