Constraints workerConstraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();
// worker differs between hms and regular builds, see fcm and hms directory for for overwriting push worker versions
WorkRequest pushTokenRegistrationRequest = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class)
.setInputData(workerFlags)
.setConstraints(workerConstraints)
.build();
if (serviceManager != null) {
serviceManager.getTaskCreator().scheduleSendPushTokenTask(token, type);
logger.info("Sending push token of type 0x{} successfully scheduled", Integer.toHexString(type)); // Note that the last sent date of the push token is set in the task
} else { thrownew ThreemaException("Unable to send / clear push token. ServiceManager not available");
}
}
/** *Signalapushtokenupdatethroughalocalbroadcast * *@paramerrorStringpotentialerrormessage *@paramclearTokenbooleanwhetherthetokenwasreset
*/ publicstaticvoid signalRegistrationFinished(@Nullable String error, boolean clearToken) { final Intent intent = new Intent(AppConstants.INTENT_PUSH_REGISTRATION_COMPLETE); if (error != null) {
logger.error("Failed to get push token {}", error);
intent.putExtra(PushUtil.EXTRA_REGISTRATION_ERROR_BROADCAST, true);
} else {
intent.putExtra(PushUtil.EXTRA_CLEAR_TOKEN, clearToken);
}
LocalBroadcastManager.getInstance(ThreemaApplication.getAppContext()).sendBroadcast(intent);
}
if (ConfigUtils.isBackgroundDataRestricted(appContext)) {
logger.warn("Network blocked (background data disabled?)"); // The same message may arrive twice (due to a network change). so we simply ignore messages that we were unable to fetch due to a blocked network // Simply schedule a poll when the device is back online
JobScheduler js = (JobScheduler) appContext.getSystemService(Context.JOB_SCHEDULER_SERVICE);
js.cancel(RECONNECT_JOB);
JobInfo job = new JobInfo.Builder(RECONNECT_JOB, new ComponentName(appContext, ReConnectJobService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setRequiresCharging(false)
.build();
@Override publicvoid resetLockTimer(boolean restartAfterReset) { // not needed in this context
}
@Override publicvoid addOnLockAppStateListener(OnLockAppStateListener c) { //not needed in this context
}
}, new ConversationCategoryService() {
@Override publicvoid markContactChatAsPrivate(@NonNull ContactModel contactModel) { // Nothing to do
}
@Override publicvoid removePrivateMarkFromContactChat(@NonNull ContactModel contactModel) { // Nothing to do
}
@Override publicvoid removePrivateMarkFromContactChat(@NonNull ch.threema.storage.models.ContactModel contactModel) { // Nothing to do
}
@Override publicvoid markGroupChatAsPrivate(long groupDatabaseId) { // Nothing to do
}
@Override publicvoid removePrivateMarkFromGroupChat(long groupDatabaseId) { // Nothing to do
}
privatestaticvoid sendWebclientNotification(Map<String, String> data) { final String session = data.get(WEBCLIENT_SESSION); final String timestamp = data.get(WEBCLIENT_TIMESTAMP); final String version = data.get(WEBCLIENT_VERSION); final String affiliationId = data.get(WEBCLIENT_AFFILIATION_ID); if (session != null && !session.isEmpty() && timestamp != null && !timestamp.isEmpty()) {
logger.debug("Received webclient wakeup for session {}", session);
finalThread t = newThread(() -> {
logger.info("Trying to wake up webclient session {}", session);
// Parse version number
Integer versionNumber = null; if (version != null) { // Can be null during beta, if an old client doesn't yet send the version field try {
versionNumber = Integer.parseInt(version, 10);
} catch (NumberFormatException e) {
logger.error("Could not parse webclient protocol version number: ", e); return;
}
}
// Try to wake up session
SessionWakeUpServiceImpl.getInstance()
.resume(session, versionNumber == null ? 0 : versionNumber, affiliationId);
});
t.setName("webclient-wakeup");
t.start();
}
}
if (sharedPreferences != null) { long lastDate = sharedPreferences.getLong(context.getString(R.string.preferences__token_sent_date), 0L); // refresh push token at least once a day return (System.currentTimeMillis() - lastDate) > DateUtils.DAY_IN_MILLIS;
} returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.