Search in sources :

Example 1 with OSPermissionStateChanges

use of com.onesignal.OSPermissionStateChanges in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldAddPermissionObserverIfConsentNotGranted.

@Test
public void shouldAddPermissionObserverIfConsentNotGranted() throws Exception {
    ShadowOneSignalRestClient.setRemoteParamsRequirePrivacyConsent(true);
    OneSignalInit();
    threadAndTaskWait();
    OSPermissionObserver permissionObserver = new OSPermissionObserver() {

        @Override
        public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) {
            lastPermissionStateChanges = stateChanges;
            currentPermission = stateChanges.getTo().areNotificationsEnabled();
        }
    };
    OneSignal.addPermissionObserver(permissionObserver);
    OneSignal.provideUserConsent(true);
    threadAndTaskWait();
    // make sure the permission observer was fired
    assertFalse(lastPermissionStateChanges.getFrom().areNotificationsEnabled());
    assertTrue(lastPermissionStateChanges.getTo().areNotificationsEnabled());
}
Also used : OSPermissionObserver(com.onesignal.OSPermissionObserver) OSPermissionStateChanges(com.onesignal.OSPermissionStateChanges) Test(org.junit.Test)

Example 2 with OSPermissionStateChanges

use of com.onesignal.OSPermissionStateChanges in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldFirePermissionObserverOnFirstAdd.

// Firing right away to match iOS behavior for wrapper SDKs.
@Test
public void shouldFirePermissionObserverOnFirstAdd() throws Exception {
    OneSignalInit();
    threadAndTaskWait();
    OSPermissionObserver permissionObserver = new OSPermissionObserver() {

        @Override
        public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) {
            lastPermissionStateChanges = stateChanges;
            currentPermission = stateChanges.getTo().areNotificationsEnabled();
        }
    };
    OneSignal.addPermissionObserver(permissionObserver);
    assertFalse(lastPermissionStateChanges.getFrom().areNotificationsEnabled());
    assertTrue(lastPermissionStateChanges.getTo().areNotificationsEnabled());
    // Test to make sure object was correct at the time of firing.
    assertTrue(currentPermission);
}
Also used : OSPermissionObserver(com.onesignal.OSPermissionObserver) OSPermissionStateChanges(com.onesignal.OSPermissionStateChanges) Test(org.junit.Test)

Aggregations

OSPermissionObserver (com.onesignal.OSPermissionObserver)2 OSPermissionStateChanges (com.onesignal.OSPermissionStateChanges)2 Test (org.junit.Test)2