Search in sources :

Example 1 with OSDeviceState

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

the class MainActivityViewModel method onOSPermissionChanged.

@Override
public void onOSPermissionChanged(OSPermissionStateChanges stateChanges) {
    OSDeviceState deviceState = OneSignal.getDeviceState();
    final boolean isSubscribed = deviceState != null && deviceState.isSubscribed();
    boolean isPermissionEnabled = stateChanges.getTo().areNotificationsEnabled();
    subscriptionSwitch.setEnabled(isPermissionEnabled);
    subscriptionSwitch.setChecked(isSubscribed);
}
Also used : OSDeviceState(com.onesignal.OSDeviceState)

Example 2 with OSDeviceState

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

the class MainOneSignalClassRunner method shouldGetSMSUserIdAfterAppRestart.

@Test
public void shouldGetSMSUserIdAfterAppRestart() throws Exception {
    OneSignalInit();
    OneSignal.setSMSNumber(ONESIGNAL_SMS_NUMBER);
    threadAndTaskWait();
    restartAppAndElapseTimeToNextSession(time);
    OneSignalInit();
    OSDeviceState deviceState = OneSignal.getDeviceState();
    assertEquals(ONESIGNAL_SMS_NUMBER, deviceState.getSMSNumber());
    assertNotNull(deviceState.getSMSUserId());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Example 3 with OSDeviceState

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

the class MainOneSignalClassRunner method shouldGetCorrectCurrentSMSSubscriptionState.

@Test
public void shouldGetCorrectCurrentSMSSubscriptionState() throws Exception {
    OneSignalInit();
    OSDeviceState deviceState = OneSignal.getDeviceState();
    assertNotNull(deviceState);
    assertNull(deviceState.getSMSUserId());
    assertNull(deviceState.getSMSNumber());
    assertFalse(deviceState.isSMSSubscribed());
    OneSignal.setSMSNumber(ONESIGNAL_SMS_NUMBER);
    threadAndTaskWait();
    deviceState = OneSignal.getDeviceState();
    assertEquals(SMS_USER_ID, deviceState.getSMSUserId());
    assertEquals(ONESIGNAL_SMS_NUMBER, deviceState.getSMSNumber());
    assertTrue(deviceState.isSMSSubscribed());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Example 4 with OSDeviceState

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

the class MainOneSignalClassRunner method shouldGetCorrectCurrentEmailSubscriptionState.

@Test
public void shouldGetCorrectCurrentEmailSubscriptionState() throws Exception {
    OneSignalInit();
    OSDeviceState deviceState = OneSignal.getDeviceState();
    assertNotNull(deviceState);
    assertNull(deviceState.getEmailUserId());
    assertNull(deviceState.getEmailAddress());
    assertFalse(deviceState.isEmailSubscribed());
    OneSignal.setEmail("josh@onesignal.com");
    threadAndTaskWait();
    deviceState = OneSignal.getDeviceState();
    assertEquals("b007f967-98cc-11e4-bed1-118f05be4522", deviceState.getEmailUserId());
    assertEquals("josh@onesignal.com", deviceState.getEmailAddress());
    assertTrue(deviceState.isEmailSubscribed());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Example 5 with OSDeviceState

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

the class MainOneSignalClassRunner method testDeviceStateAreNotificationsEnabled.

@Test
public void testDeviceStateAreNotificationsEnabled() throws Exception {
    assertNull(OneSignal.getDeviceState());
    OneSignalInit();
    threadAndTaskWait();
    OSDeviceState device = OneSignal.getDeviceState();
    assertTrue(device.areNotificationsEnabled());
    fastColdRestartApp();
    ShadowNotificationManagerCompat.enabled = false;
    OneSignalInit();
    threadAndTaskWait();
    // Device is a snapshot, last value should not change
    assertTrue(device.areNotificationsEnabled());
    // Retrieve new user device
    assertFalse(OneSignal.getDeviceState().areNotificationsEnabled());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Aggregations

OSDeviceState (com.onesignal.OSDeviceState)14 Test (org.junit.Test)12