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());
}
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);
}
Aggregations