@Test public void testDeviceTokenWithNullDeviceToken() { ParseInstallation installation = new ParseInstallation(); installation.setDeviceToken("deviceToken"); assertEquals("deviceToken", installation.getDeviceToken()); installation.setDeviceToken(null); assertEquals("deviceToken", installation.getDeviceToken()); }
@Override public boolean onStartJob(final JobParameters job) { PLog.d(ParseFCM.TAG, "Updating FCM token"); ParseInstallation installation = ParseInstallation.getCurrentInstallation(); String token = FirebaseInstanceId.getInstance().getToken(); if (installation != null && token != null) { installation.setDeviceToken(token); //even though this is FCM, calling it gcm will work on the backend installation.setPushType(PUSH_TYPE); installation.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { PLog.d(ParseFCM.TAG, "FCM token saved to installation"); jobFinished(job, false); } else { PLog.e(ParseFCM.TAG, "FCM token upload failed", e); jobFinished(job, true); } } }); return true; } return false; // Answers the question: "Is there still work going on?" }
@Override public Void call() { try { InstanceID instanceID = InstanceID.getInstance(getApplicationContext()); String senderId = job.getExtras().getString(KEY_GCM_SENDER_ID); String token = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); ParseInstallation installation = ParseInstallation.getCurrentInstallation(); installation.setDeviceToken(token); //even though this is FCM, calling it gcm will work on the backend installation.setPushType(PUSH_TYPE); installation.save(); PLog.d(ParseGCM.TAG, "GCM registration success"); } catch (Exception e) { PLog.e(ParseGCM.TAG, "GCM registration failed", e); jobFinished(job, true); } return null; } });
@Test public void testDeviceToken() { ParseInstallation installation = new ParseInstallation(); installation.setDeviceToken("deviceToken"); assertEquals("deviceToken", installation.getDeviceToken()); installation.removeDeviceToken(); assertNull(installation.getDeviceToken()); // Make sure we add the pushType to operationSetQueue instead of serverData assertEquals(1, installation.operationSetQueue.getLast().size()); }