use of com.onesignal.OSPermissionObserver in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldFirePermissionObserverWhenUserDisablesNotifications.
@Test
public void shouldFirePermissionObserverWhenUserDisablesNotifications() throws Exception {
ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse(new JSONObject().put("unsubscribe_on_notifications_disabled", false));
OneSignalInit();
threadAndTaskWait();
OSPermissionObserver permissionObserver = stateChanges -> {
lastPermissionStateChanges = stateChanges;
currentPermission = stateChanges.getTo().areNotificationsEnabled();
};
OneSignal.addPermissionObserver(permissionObserver);
lastPermissionStateChanges = null;
// Make sure garbage collection doesn't nuke any observers.
Runtime.getRuntime().gc();
stopActivity(blankActivityController);
ShadowNotificationManagerCompat.enabled = false;
blankActivityController.resume();
assertTrue(lastPermissionStateChanges.getFrom().areNotificationsEnabled());
assertFalse(lastPermissionStateChanges.getTo().areNotificationsEnabled());
// Test to make sure object was correct at the time of firing.
assertFalse(currentPermission);
// unsubscribeWhenNotificationsAreDisabled is not set so don't send notification_types.
assertFalse(ShadowOneSignalRestClient.lastPost.has("notification_types"));
}
use of com.onesignal.OSPermissionObserver 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());
}
use of com.onesignal.OSPermissionObserver 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);
}
Aggregations