From bd4208f709b93a7582b65f8884a8eb5d1e3ce69d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 12 Jan 2022 20:26:29 +0100 Subject: [PATCH 01/18] minor refactoring - extract method to register device at proxy - rename method Signed-off-by: Marcel Hibbe Signed-off-by: Marcel Hibbe --- .../java/com/nextcloud/talk/api/NcApi.java | 4 +- .../com/nextcloud/talk/utils/PushUtils.java | 150 +++++++++--------- 2 files changed, 81 insertions(+), 73 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index b568dd210..c75b9c083 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -283,8 +283,8 @@ public interface NcApi { @FormUrlEncoded @POST - Observable registerDeviceForNotificationsWithProxy(@Url String url, - @FieldMap Map fields); + Observable registerDeviceForNotificationsWithPushProxy(@Url String url, + @FieldMap Map fields); /* diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 0708d25de..0120e914f 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -284,77 +284,7 @@ public class PushUtils { proxyMap.put("userPublicKey", pushRegistrationOverall.getOcs() .getData().getPublicKey()); - ncApi.registerDeviceForNotificationsWithProxy( - ApiUtils.getUrlPushProxy(), proxyMap) - .subscribeOn(Schedulers.io()) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - // unused atm - } - - @Override - public void onNext(@NonNull Void aVoid) { - PushConfigurationState pushConfigurationState = - new PushConfigurationState(); - pushConfigurationState.setPushToken(token); - pushConfigurationState.setDeviceIdentifier( - pushRegistrationOverall.getOcs() - .getData().getDeviceIdentifier()); - pushConfigurationState.setDeviceIdentifierSignature( - pushRegistrationOverall - .getOcs().getData().getSignature()); - pushConfigurationState.setUserPublicKey( - pushRegistrationOverall.getOcs() - .getData().getPublicKey()); - pushConfigurationState.setUsesRegularPass(false); - - try { - userUtils.createOrUpdateUser(null, - null, null, - userEntity.getDisplayName(), - LoganSquare.serialize(pushConfigurationState), null, - null, userEntity.getId(), null, null, null) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - // unused atm - } - - @Override - public void onNext(@NonNull UserEntity userEntity) { - eventBus.post(new EventStatus(userEntity.getId(), EventStatus.EventType.PUSH_REGISTRATION, true)); - } - - @Override - public void onError(@NonNull Throwable e) { - eventBus.post(new EventStatus - (userEntity.getId(), - EventStatus.EventType - .PUSH_REGISTRATION, false)); - } - - @Override - public void onComplete() { - // unused atm - } - }); - } catch (IOException e) { - Log.e(TAG, "IOException while updating user", e); - } - } - - @Override - public void onError(@NonNull Throwable e) { - eventBus.post(new EventStatus(userEntity.getId(), - EventStatus.EventType.PUSH_REGISTRATION, false)); - } - - @Override - public void onComplete() { - // unused atm - } - }); + registerDeviceWithPushProxy(pushRegistrationOverall, proxyMap, token, userEntity); } @Override @@ -375,6 +305,84 @@ public class PushUtils { } } + private void registerDeviceWithPushProxy( + @androidx.annotation.NonNull PushRegistrationOverall pushRegistrationOverall, + Map proxyMap, + String token, + UserEntity userEntity) { + ncApi.registerDeviceForNotificationsWithPushProxy( + ApiUtils.getUrlPushProxy(), proxyMap) + .subscribeOn(Schedulers.io()) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + // unused atm + } + + @Override + public void onNext(@NonNull Void aVoid) { + PushConfigurationState pushConfigurationState = + new PushConfigurationState(); + pushConfigurationState.setPushToken(token); + pushConfigurationState.setDeviceIdentifier( + pushRegistrationOverall.getOcs() + .getData().getDeviceIdentifier()); + pushConfigurationState.setDeviceIdentifierSignature( + pushRegistrationOverall + .getOcs().getData().getSignature()); + pushConfigurationState.setUserPublicKey( + pushRegistrationOverall.getOcs() + .getData().getPublicKey()); + pushConfigurationState.setUsesRegularPass(false); + + try { + userUtils.createOrUpdateUser(null, + null, null, + userEntity.getDisplayName(), + LoganSquare.serialize(pushConfigurationState), null, + null, userEntity.getId(), null, null, null) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + // unused atm + } + + @Override + public void onNext(@NonNull UserEntity userEntity) { + eventBus.post(new EventStatus(userEntity.getId(), EventStatus.EventType.PUSH_REGISTRATION, true)); + } + + @Override + public void onError(@NonNull Throwable e) { + eventBus.post(new EventStatus + (userEntity.getId(), + EventStatus.EventType + .PUSH_REGISTRATION, false)); + } + + @Override + public void onComplete() { + // unused atm + } + }); + } catch (IOException e) { + Log.e(TAG, "IOException while updating user", e); + } + } + + @Override + public void onError(@NonNull Throwable e) { + eventBus.post(new EventStatus(userEntity.getId(), + EventStatus.EventType.PUSH_REGISTRATION, false)); + } + + @Override + public void onComplete() { + // unused atm + } + }); + } + private Key readKeyFromString(boolean readPublicKey, String keyString) { if (readPublicKey) { keyString = keyString.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", From a7c298b224d9f2b5a147686e861b34bf6ccbc7bb Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 12 Jan 2022 21:01:44 +0100 Subject: [PATCH 02/18] add log if push token is empty when registering at nc server Signed-off-by: Marcel Hibbe --- app/src/main/java/com/nextcloud/talk/utils/PushUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 0120e914f..4c5216627 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -302,6 +302,8 @@ public class PushUtils { } } } + } else { + Log.e(TAG, "push token was empty when trying to register at nextcloud server"); } } From 412af46ed5ec4a9046ed18be908645c8f28db0ab Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 13 Jan 2022 12:15:15 +0100 Subject: [PATCH 03/18] refactoring PushUtils Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/utils/PushUtils.java | 246 +++++++++--------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 4c5216627..372155ded 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -97,11 +97,11 @@ public class PushUtils { keysFile = NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeyStore", Context.MODE_PRIVATE); publicKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", - Context.MODE_PRIVATE), "push_key.pub"); + Context.MODE_PRIVATE), "push_key.pub"); privateKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", - Context.MODE_PRIVATE), "push_key.priv"); + Context.MODE_PRIVATE), "push_key.priv"); proxyServer = NextcloudTalkApplication.Companion.getSharedApplication().getResources(). - getString(R.string.nc_push_server_url); + getString(R.string.nc_push_server_url); } public SignatureVerification verifySignature(byte[] signatureBytes, byte[] subjectBytes) { @@ -118,9 +118,9 @@ public class PushUtils { for (UserEntity userEntity : userEntities) { if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) { pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), - PushConfigurationState.class); + PushConfigurationState.class); publicKey = (PublicKey) readKeyFromString(true, - pushConfigurationState.getUserPublicKey()); + pushConfigurationState.getUserPublicKey()); signature.initVerify(publicKey); signature.update(subjectBytes); if (signature.verify(signatureBytes)) { @@ -183,7 +183,7 @@ public class PushUtils { StringBuilder result = new StringBuilder(); for (byte individualByte : bytes) { result.append(Integer.toString((individualByte & 0xff) + 0x100, 16) - .substring(1)); + .substring(1)); } return result.toString(); } @@ -230,11 +230,11 @@ public class PushUtils { String pushTokenHash = generateSHA512Hash(token).toLowerCase(); PublicKey devicePublicKey = (PublicKey) readKeyFromFile(true); if (devicePublicKey != null) { - byte[] publicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP); - String publicKey = new String(publicKeyBytes); - publicKey = publicKey.replaceAll("(.{64})", "$1\n"); + byte[] devicePublicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP); + String devicePublicKeyBase64 = new String(devicePublicKeyBytes); + devicePublicKeyBase64 = devicePublicKeyBase64.replaceAll("(.{64})", "$1\n"); - publicKey = "-----BEGIN PUBLIC KEY-----\n" + publicKey + "\n-----END PUBLIC KEY-----\n"; + devicePublicKeyBase64 = "-----BEGIN PUBLIC KEY-----\n" + devicePublicKeyBase64 + "\n-----END PUBLIC KEY-----\n"; if (userUtils.anyUserExists()) { String providerValue; @@ -253,51 +253,17 @@ public class PushUtils { accountPushData = null; } - if (((TextUtils.isEmpty(providerValue) || accountPushData == null) && !userEntity.getScheduledForDeletion()) || - (accountPushData != null && !accountPushData.getPushToken().equals(token) && !userEntity.getScheduledForDeletion())) { + if (((TextUtils.isEmpty(providerValue) || accountPushData == null) + && !userEntity.getScheduledForDeletion()) || + (accountPushData != null && !accountPushData.getPushToken().equals(token) && !userEntity.getScheduledForDeletion())) { - Map queryMap = new HashMap<>(); - queryMap.put("format", "json"); - queryMap.put("pushTokenHash", pushTokenHash); - queryMap.put("devicePublicKey", publicKey); - queryMap.put("proxyServer", proxyServer); + Map nextcloudRegisterPushMap = new HashMap<>(); + nextcloudRegisterPushMap.put("format", "json"); + nextcloudRegisterPushMap.put("pushTokenHash", pushTokenHash); + nextcloudRegisterPushMap.put("devicePublicKey", devicePublicKeyBase64); + nextcloudRegisterPushMap.put("proxyServer", proxyServer); - credentials = ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()); - - ncApi.registerDeviceForNotificationsWithNextcloud( - credentials, - ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl()), queryMap) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - // unused atm - } - - @Override - public void onNext(@NonNull PushRegistrationOverall pushRegistrationOverall) { - Map proxyMap = new HashMap<>(); - proxyMap.put("pushToken", token); - proxyMap.put("deviceIdentifier", pushRegistrationOverall.getOcs().getData(). - getDeviceIdentifier()); - proxyMap.put("deviceIdentifierSignature", pushRegistrationOverall.getOcs() - .getData().getSignature()); - proxyMap.put("userPublicKey", pushRegistrationOverall.getOcs() - .getData().getPublicKey()); - - registerDeviceWithPushProxy(pushRegistrationOverall, proxyMap, token, userEntity); - } - - @Override - public void onError(@NonNull Throwable e) { - eventBus.post(new EventStatus(userEntity.getId(), - EventStatus.EventType.PUSH_REGISTRATION, false)); - } - - @Override - public void onComplete() { - // unused atm - } - }); + registerDeviceWithNextcloud(nextcloudRegisterPushMap, token, userEntity); } } } @@ -307,91 +273,125 @@ public class PushUtils { } } - private void registerDeviceWithPushProxy( - @androidx.annotation.NonNull PushRegistrationOverall pushRegistrationOverall, - Map proxyMap, - String token, - UserEntity userEntity) { - ncApi.registerDeviceForNotificationsWithPushProxy( - ApiUtils.getUrlPushProxy(), proxyMap) - .subscribeOn(Schedulers.io()) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - // unused atm + private void registerDeviceWithNextcloud(Map nextcloudRegisterPushMap, String token, UserEntity userEntity) { + String credentials = ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()); + + ncApi.registerDeviceForNotificationsWithNextcloud( + credentials, + ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl()), nextcloudRegisterPushMap) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + // unused atm + } + + @Override + public void onNext(@NonNull PushRegistrationOverall pushRegistrationOverall) { + Map proxyMap = new HashMap<>(); + proxyMap.put("pushToken", token); + proxyMap.put("deviceIdentifier", pushRegistrationOverall.getOcs().getData(). + getDeviceIdentifier()); + proxyMap.put("deviceIdentifierSignature", pushRegistrationOverall.getOcs() + .getData().getSignature()); + proxyMap.put("userPublicKey", pushRegistrationOverall.getOcs() + .getData().getPublicKey()); + + registerDeviceWithPushProxy(proxyMap, userEntity); + } + + @Override + public void onError(@NonNull Throwable e) { + eventBus.post(new EventStatus(userEntity.getId(), + EventStatus.EventType.PUSH_REGISTRATION, false)); + } + + @Override + public void onComplete() { + // unused atm + } + }); + } + + private void registerDeviceWithPushProxy(Map proxyMap, UserEntity userEntity) { + ncApi.registerDeviceForNotificationsWithPushProxy(ApiUtils.getUrlPushProxy(), proxyMap) + .subscribeOn(Schedulers.io()) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + // unused atm + } + + @Override + public void onNext(@NonNull Void aVoid) { + try { + createOrUpdateUser(proxyMap, userEntity); + } catch (IOException e) { + Log.e(TAG, "IOException while updating user", e); } + } - @Override - public void onNext(@NonNull Void aVoid) { - PushConfigurationState pushConfigurationState = - new PushConfigurationState(); - pushConfigurationState.setPushToken(token); - pushConfigurationState.setDeviceIdentifier( - pushRegistrationOverall.getOcs() - .getData().getDeviceIdentifier()); - pushConfigurationState.setDeviceIdentifierSignature( - pushRegistrationOverall - .getOcs().getData().getSignature()); - pushConfigurationState.setUserPublicKey( - pushRegistrationOverall.getOcs() - .getData().getPublicKey()); - pushConfigurationState.setUsesRegularPass(false); + @Override + public void onError(@NonNull Throwable e) { + eventBus.post(new EventStatus(userEntity.getId(), + EventStatus.EventType.PUSH_REGISTRATION, false)); + } - try { - userUtils.createOrUpdateUser(null, - null, null, - userEntity.getDisplayName(), - LoganSquare.serialize(pushConfigurationState), null, - null, userEntity.getId(), null, null, null) - .subscribe(new Observer() { - @Override - public void onSubscribe(@NonNull Disposable d) { - // unused atm - } + @Override + public void onComplete() { + // unused atm + } + }); + } - @Override - public void onNext(@NonNull UserEntity userEntity) { - eventBus.post(new EventStatus(userEntity.getId(), EventStatus.EventType.PUSH_REGISTRATION, true)); - } + private void createOrUpdateUser(Map proxyMap, UserEntity userEntity) throws IOException { + PushConfigurationState pushConfigurationState = new PushConfigurationState(); + pushConfigurationState.setPushToken(proxyMap.get("pushToken")); + pushConfigurationState.setDeviceIdentifier(proxyMap.get("deviceIdentifier")); + pushConfigurationState.setDeviceIdentifierSignature(proxyMap.get("deviceIdentifierSignature")); + pushConfigurationState.setUserPublicKey(proxyMap.get("userPublicKey")); + pushConfigurationState.setUsesRegularPass(false); - @Override - public void onError(@NonNull Throwable e) { - eventBus.post(new EventStatus - (userEntity.getId(), - EventStatus.EventType - .PUSH_REGISTRATION, false)); - } + userUtils.createOrUpdateUser(null, + null, + null, + userEntity.getDisplayName(), + LoganSquare.serialize(pushConfigurationState), + null, + null, + userEntity.getId(), + null, + null, + null) + .subscribe(new Observer() { + @Override + public void onSubscribe(@NonNull Disposable d) { + // unused atm + } - @Override - public void onComplete() { - // unused atm - } - }); - } catch (IOException e) { - Log.e(TAG, "IOException while updating user", e); - } - } + @Override + public void onNext(@NonNull UserEntity userEntity) { + eventBus.post(new EventStatus(userEntity.getId(), EventStatus.EventType.PUSH_REGISTRATION, true)); + } - @Override - public void onError(@NonNull Throwable e) { - eventBus.post(new EventStatus(userEntity.getId(), - EventStatus.EventType.PUSH_REGISTRATION, false)); - } + @Override + public void onError(@NonNull Throwable e) { + eventBus.post(new EventStatus(userEntity.getId(), EventStatus.EventType.PUSH_REGISTRATION, false)); + } - @Override - public void onComplete() { - // unused atm - } - }); + @Override + public void onComplete() { + // unused atm + } + }); } private Key readKeyFromString(boolean readPublicKey, String keyString) { if (readPublicKey) { keyString = keyString.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", - "").replace("-----END PUBLIC KEY-----", ""); + "").replace("-----END PUBLIC KEY-----", ""); } else { keyString = keyString.replaceAll("\\n", "").replace("-----BEGIN PRIVATE KEY-----", - "").replace("-----END PRIVATE KEY-----", ""); + "").replace("-----END PRIVATE KEY-----", ""); } KeyFactory keyFactory = null; From 01b0452d6f3ff4a238373ad7aac1ac5eb81a129d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 13 Jan 2022 15:09:42 +0100 Subject: [PATCH 04/18] bump firebase-messaging - bump firebase-messaging to 23.0.0 - add gplayImplementation: play-services-base:17.6.0 (for class GoogleApiAvailability) Signed-off-by: Marcel Hibbe --- app/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index c7724b7a2..7d39033fb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -317,7 +317,8 @@ dependencies { spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0' spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7' - gplayImplementation "com.google.firebase:firebase-messaging:20.1.2" + gplayImplementation 'com.google.android.gms:play-services-base:18.0.1' + gplayImplementation "com.google.firebase:firebase-messaging:23.0.0" } task ktlint(type: JavaExec, group: "verification") { From 31f2f40bcf764254090e68d244c58923e04d408a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 17 Jan 2022 11:18:35 +0100 Subject: [PATCH 05/18] refactor PushUtils Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/utils/PushUtils.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 372155ded..ea44175a1 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -85,21 +85,17 @@ public class PushUtils { @Inject NcApi ncApi; - private File keysFile; - private File publicKeyFile; - private File privateKeyFile; + private final File publicKeyFile; + private final File privateKeyFile; - private String proxyServer; + private final String proxyServer; public PushUtils() { NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); - keysFile = NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeyStore", Context.MODE_PRIVATE); - - publicKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", - Context.MODE_PRIVATE), "push_key.pub"); - privateKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", - Context.MODE_PRIVATE), "push_key.priv"); + String keyPath = NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", Context.MODE_PRIVATE).getAbsolutePath(); + publicKeyFile = new File(keyPath, "push_key.pub"); + privateKeyFile = new File(keyPath, "push_key.priv"); proxyServer = NextcloudTalkApplication.Companion.getSharedApplication().getResources(). getString(R.string.nc_push_server_url); } @@ -190,9 +186,6 @@ public class PushUtils { public int generateRsa2048KeyPair() { if (!publicKeyFile.exists() && !privateKeyFile.exists()) { - if (!keysFile.exists()) { - keysFile.mkdirs(); - } KeyPairGenerator keyGen = null; try { @@ -226,7 +219,6 @@ public class PushUtils { String token = appPreferences.getPushToken(); if (!TextUtils.isEmpty(token)) { - String credentials; String pushTokenHash = generateSHA512Hash(token).toLowerCase(); PublicKey devicePublicKey = (PublicKey) readKeyFromFile(true); if (devicePublicKey != null) { From 1bd28f5ef4a75210b5fde28d6c3045e64dd450b0 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 18 Jan 2022 13:05:36 +0100 Subject: [PATCH 06/18] add logging Signed-off-by: Marcel Hibbe --- app/src/main/java/com/nextcloud/talk/utils/PushUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index ea44175a1..cc3c51860 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -279,6 +279,9 @@ public class PushUtils { @Override public void onNext(@NonNull PushRegistrationOverall pushRegistrationOverall) { + Log.d(TAG, + "pushToken successfully registered at nextcloud server. pushToken= " + token.substring(0,5) + "..."); + Map proxyMap = new HashMap<>(); proxyMap.put("pushToken", token); proxyMap.put("deviceIdentifier", pushRegistrationOverall.getOcs().getData(). @@ -316,6 +319,9 @@ public class PushUtils { @Override public void onNext(@NonNull Void aVoid) { try { + Log.d(TAG, + "pushToken successfully registered at pushproxy. pushToken= " + proxyMap.get("pushToken").substring(0,5) + + "..."); createOrUpdateUser(proxyMap, userEntity); } catch (IOException e) { Log.e(TAG, "IOException while updating user", e); From b339aa9d33ad67739ec8e0a45d411c971bc60176 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 18 Jan 2022 13:06:51 +0100 Subject: [PATCH 07/18] refactor check if token should be registered Signed-off-by: Marcel Hibbe --- .../main/java/com/nextcloud/talk/utils/PushUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index cc3c51860..8a5c59c37 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -245,9 +245,12 @@ public class PushUtils { accountPushData = null; } - if (((TextUtils.isEmpty(providerValue) || accountPushData == null) - && !userEntity.getScheduledForDeletion()) || - (accountPushData != null && !accountPushData.getPushToken().equals(token) && !userEntity.getScheduledForDeletion())) { + boolean userHasNoPushData = (TextUtils.isEmpty(providerValue) || accountPushData == null); + boolean userIsNotMarkedForDeletion = !userEntity.getScheduledForDeletion(); + boolean tokenHasChanged = + accountPushData != null && !accountPushData.getPushToken().equals(token); + + if (userIsNotMarkedForDeletion && (userHasNoPushData || tokenHasChanged)) { Map nextcloudRegisterPushMap = new HashMap<>(); nextcloudRegisterPushMap.put("format", "json"); From aacd6d53774de18fa6e570f2c701f2775ceb871d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 18 Jan 2022 13:49:44 +0100 Subject: [PATCH 08/18] also register push token again on server&proxy no matter if it didn't change on device Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/utils/PushUtils.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 8a5c59c37..a5f06573e 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -229,29 +229,10 @@ public class PushUtils { devicePublicKeyBase64 = "-----BEGIN PUBLIC KEY-----\n" + devicePublicKeyBase64 + "\n-----END PUBLIC KEY-----\n"; if (userUtils.anyUserExists()) { - String providerValue; - PushConfigurationState accountPushData = null; for (Object userEntityObject : userUtils.getUsers()) { UserEntity userEntity = (UserEntity) userEntityObject; - providerValue = userEntity.getPushConfigurationState(); - if (!TextUtils.isEmpty(providerValue)) { - try { - accountPushData = LoganSquare.parse(providerValue, PushConfigurationState.class); - } catch (IOException e) { - Log.d(TAG, "Failed to parse account push data"); - accountPushData = null; - } - } else { - accountPushData = null; - } - - boolean userHasNoPushData = (TextUtils.isEmpty(providerValue) || accountPushData == null); - boolean userIsNotMarkedForDeletion = !userEntity.getScheduledForDeletion(); - boolean tokenHasChanged = - accountPushData != null && !accountPushData.getPushToken().equals(token); - - if (userIsNotMarkedForDeletion && (userHasNoPushData || tokenHasChanged)) { + if (!userEntity.getScheduledForDeletion()) { Map nextcloudRegisterPushMap = new HashMap<>(); nextcloudRegisterPushMap.put("format", "json"); nextcloudRegisterPushMap.put("pushTokenHash", pushTokenHash); From 55da4528877804d36b519ffef46300b69623ac61 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 18 Jan 2022 13:51:00 +0100 Subject: [PATCH 09/18] add project_id from google-services.json to setup.xml Signed-off-by: Marcel Hibbe --- app/src/main/res/values/setup.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index a4c9ed908..fd304c3c0 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -47,12 +47,15 @@ com.nextcloud.client nextcloud - + + + 829118773643-cq33cmhv7mnv7iq8mjv6rt7t15afc70k.apps.googleusercontent.com https://nextcloud-a7dea.firebaseio.com 829118773643 AIzaSyAWIyOcLafaFp8PFL61h64cy1NNZW2cU_s 1:829118773643:android:54b65087c544d819 + nextcloud-a7dea AIzaSyAWIyOcLafaFp8PFL61h64cy1NNZW2cU_s nextcloud-a7dea.appspot.com From 06afd7bec62b6486e171dbf91c160cfd85f2c82d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 18 Jan 2022 16:43:47 +0100 Subject: [PATCH 10/18] set up periodic fetch of firebase token in ClosedInterface for gplay move OneTimeWorkRequest for PushRegistrationWorker from NextcloudTalkApplication to ClosedInterface for gplay add check in PushRegistrationWorker if google services are available Signed-off-by: Marcel Hibbe --- .../talk/utils/ClosedInterfaceImpl.java | 5 ++ .../talk/jobs/GetFirebasePushTokenWorker.kt | 64 ++++++++++++++++++ .../talk/utils/ClosedInterfaceImpl.java | 57 ---------------- .../talk/utils/ClosedInterfaceImpl.kt | 65 +++++++++++++++++++ .../application/NextcloudTalkApplication.kt | 13 ++-- .../talk/interfaces/ClosedInterface.kt | 1 + .../talk/jobs/PushRegistrationWorker.java | 17 +++-- .../talk/utils/ClosedInterfaceImpl.java | 5 ++ 8 files changed, 159 insertions(+), 68 deletions(-) create mode 100644 app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt delete mode 100644 app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java create mode 100644 app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt diff --git a/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java b/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java index 66496bd31..71c25e757 100644 --- a/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java +++ b/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java @@ -33,4 +33,9 @@ public class ClosedInterfaceImpl implements ClosedInterface { public boolean isGooglePlayServicesAvailable() { return false; } + + @Override + public void setUpPushTokenRegistration() { + // no push notifications for generic build flavour :( + } } diff --git a/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt b/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt new file mode 100644 index 000000000..89e3bd64a --- /dev/null +++ b/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt @@ -0,0 +1,64 @@ +/* + * Nextcloud Talk application + * + * @author Marcel Hibbe + * Copyright (C) 2022 Marcel Hibbe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.jobs + +import android.annotation.SuppressLint +import android.content.Context +import android.util.Log +import androidx.work.OneTimeWorkRequest +import androidx.work.WorkManager +import androidx.work.Worker +import androidx.work.WorkerParameters +import com.google.android.gms.tasks.OnCompleteListener +import com.google.firebase.messaging.FirebaseMessaging +import com.nextcloud.talk.utils.preferences.AppPreferences +import javax.inject.Inject + +class GetFirebasePushTokenWorker(val context: Context, workerParameters: WorkerParameters) : + Worker(context, workerParameters) { + + @JvmField + @Inject + var appPreferences: AppPreferences? = null + + @SuppressLint("LongLogTag") + override fun doWork(): Result { + FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task -> + if (!task.isSuccessful) { + Log.w(TAG, "Fetching FCM registration token failed", task.exception) + return@OnCompleteListener + } + + val token = task.result + Log.d(TAG, "Fetching FCM registration token succeeded. token = $token") + + appPreferences?.pushToken = token + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + WorkManager.getInstance(context).enqueue(pushRegistrationWork) + }) + + return Result.success() + } + + companion object { + const val TAG = "GetFirebasePushTokenWorker" + } +} diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java deleted file mode 100644 index 7be5866f2..000000000 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.utils; - - -import android.content.Intent; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.security.ProviderInstaller; -import com.google.android.gms.security.ProviderInstaller.ProviderInstallListener; -import com.nextcloud.talk.application.NextcloudTalkApplication; -import com.nextcloud.talk.interfaces.ClosedInterface; - -public class ClosedInterfaceImpl implements ClosedInterface, ProviderInstallListener { - @Override - public void providerInstallerInstallIfNeededAsync() { - ProviderInstaller.installIfNeededAsync(NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext(), - this); - } - - @Override - public boolean isGooglePlayServicesAvailable() { - GoogleApiAvailability api = GoogleApiAvailability.getInstance(); - int code = - api.isGooglePlayServicesAvailable(NextcloudTalkApplication.Companion.getSharedApplication().getApplicationContext()); - return code == ConnectionResult.SUCCESS; - } - - @Override - public void onProviderInstalled() { - - } - - @Override - public void onProviderInstallFailed(int i, Intent intent) { - - } -} diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt new file mode 100644 index 000000000..b183eb087 --- /dev/null +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -0,0 +1,65 @@ +package com.nextcloud.talk.utils + +import android.content.Intent +import androidx.work.ExistingPeriodicWorkPolicy +import androidx.work.OneTimeWorkRequest +import androidx.work.PeriodicWorkRequest +import androidx.work.WorkManager +import autodagger.AutoInjector +import com.google.android.gms.common.ConnectionResult +import com.google.android.gms.common.GoogleApiAvailability +import com.google.android.gms.security.ProviderInstaller +import com.nextcloud.talk.application.NextcloudTalkApplication +import com.nextcloud.talk.interfaces.ClosedInterface +import com.nextcloud.talk.jobs.GetFirebasePushTokenWorker +import com.nextcloud.talk.jobs.PushRegistrationWorker +import java.util.concurrent.TimeUnit + +@AutoInjector(NextcloudTalkApplication::class) +class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallListener { + + override val isGooglePlayServicesAvailable : Boolean = isGPlayServicesAvailable() + + override fun providerInstallerInstallIfNeededAsync() { + NextcloudTalkApplication.sharedApplication?.let { + ProviderInstaller.installIfNeededAsync( + it.applicationContext, + this + ) + } + } + + override fun onProviderInstalled() { + } + + override fun onProviderInstallFailed(p0: Int, p1: Intent?) { + } + + override fun setUpPushTokenRegistration() { + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + WorkManager.getInstance().enqueue(pushRegistrationWork) + + val periodicPushRegistration = PeriodicWorkRequest.Builder( + GetFirebasePushTokenWorker::class.java, 15, // TODO: discuss intervall. joas 24h, google 1 month + TimeUnit.MINUTES + ) + .build() + + WorkManager.getInstance() + .enqueueUniquePeriodicWork( + "periodicPushRegistration", ExistingPeriodicWorkPolicy.REPLACE, + periodicPushRegistration + ) + } + + private fun isGPlayServicesAvailable() : Boolean { + val api = GoogleApiAvailability.getInstance() + val code = + NextcloudTalkApplication.sharedApplication?.let { + api.isGooglePlayServicesAvailable( + it.applicationContext + ) + } + return code == ConnectionResult.SUCCESS + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt index 0dda6430c..66c766c34 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -53,7 +53,6 @@ import com.nextcloud.talk.dagger.modules.DatabaseModule import com.nextcloud.talk.dagger.modules.RestModule import com.nextcloud.talk.jobs.AccountRemovalWorker import com.nextcloud.talk.jobs.CapabilitiesWorker -import com.nextcloud.talk.jobs.PushRegistrationWorker import com.nextcloud.talk.jobs.SignalingSettingsWorker import com.nextcloud.talk.utils.ClosedInterfaceImpl import com.nextcloud.talk.utils.DeviceUtils @@ -165,7 +164,8 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver { ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync() DeviceUtils.ignoreSpecialBatteryFeatures() - val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + ClosedInterfaceImpl().setUpPushTokenRegistration() + val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build() val periodicCapabilitiesUpdateWork = PeriodicWorkRequest.Builder( CapabilitiesWorker::class.java, @@ -174,11 +174,10 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver { val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java).build() val signalingSettingsWork = OneTimeWorkRequest.Builder(SignalingSettingsWorker::class.java).build() - WorkManager.getInstance().enqueue(pushRegistrationWork) - WorkManager.getInstance().enqueue(accountRemovalWork) - WorkManager.getInstance().enqueue(capabilitiesUpdateWork) - WorkManager.getInstance().enqueue(signalingSettingsWork) - WorkManager.getInstance().enqueueUniquePeriodicWork( + WorkManager.getInstance(applicationContext).enqueue(accountRemovalWork) + WorkManager.getInstance(applicationContext).enqueue(capabilitiesUpdateWork) + WorkManager.getInstance(applicationContext).enqueue(signalingSettingsWork) + WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork( "DailyCapabilitiesUpdateWork", ExistingPeriodicWorkPolicy.REPLACE, periodicCapabilitiesUpdateWork diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt b/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt index 8e678d5e1..fee12d99b 100644 --- a/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt +++ b/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt @@ -24,4 +24,5 @@ interface ClosedInterface { val isGooglePlayServicesAvailable: Boolean fun providerInstallerInstallIfNeededAsync() + fun setUpPushTokenRegistration() } diff --git a/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java index ae6ccc3af..a4a917b70 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java @@ -21,9 +21,13 @@ package com.nextcloud.talk.jobs; import android.content.Context; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.work.Worker; import androidx.work.WorkerParameters; + +import com.nextcloud.talk.utils.ClosedInterfaceImpl; import com.nextcloud.talk.utils.PushUtils; public class PushRegistrationWorker extends Worker { @@ -36,10 +40,15 @@ public class PushRegistrationWorker extends Worker { @NonNull @Override public Result doWork() { - PushUtils pushUtils = new PushUtils(); - pushUtils.generateRsa2048KeyPair(); - pushUtils.pushRegistrationToServer(); + if(new ClosedInterfaceImpl().isGooglePlayServicesAvailable()){ + PushUtils pushUtils = new PushUtils(); + pushUtils.generateRsa2048KeyPair(); + pushUtils.pushRegistrationToServer(); - return Result.success(); + return Result.success(); + } + Log.w(TAG, "executing PushRegistrationWorker doesn't make sense because Google Play Services are not " + + "available"); + return Result.failure(); } } diff --git a/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java b/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java index 66496bd31..34c10d888 100644 --- a/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java +++ b/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java @@ -33,4 +33,9 @@ public class ClosedInterfaceImpl implements ClosedInterface { public boolean isGooglePlayServicesAvailable() { return false; } + + @Override + public void setUpPushTokenRegistration() { + // no push notifications for qa build flavour :( + } } From 76cab3b9a0acbf839dce873ba717b43340be7397 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 19 Jan 2022 12:33:00 +0100 Subject: [PATCH 11/18] add PeriodicWorkRequest to register local token every 24h Signed-off-by: Marcel Hibbe --- .../talk/utils/ClosedInterfaceImpl.kt | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt index b183eb087..7ab19d8bb 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -35,23 +35,6 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi override fun onProviderInstallFailed(p0: Int, p1: Intent?) { } - override fun setUpPushTokenRegistration() { - val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() - WorkManager.getInstance().enqueue(pushRegistrationWork) - - val periodicPushRegistration = PeriodicWorkRequest.Builder( - GetFirebasePushTokenWorker::class.java, 15, // TODO: discuss intervall. joas 24h, google 1 month - TimeUnit.MINUTES - ) - .build() - - WorkManager.getInstance() - .enqueueUniquePeriodicWork( - "periodicPushRegistration", ExistingPeriodicWorkPolicy.REPLACE, - periodicPushRegistration - ) - } - private fun isGPlayServicesAvailable() : Boolean { val api = GoogleApiAvailability.getInstance() val code = @@ -62,4 +45,43 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi } return code == ConnectionResult.SUCCESS } + + override fun setUpPushTokenRegistration() { + registerLocalToken() + setUpPeriodicLocalTokenRegistration() + setUpPeriodicTokenRefreshFromFCM() + } + + private fun registerLocalToken(){ + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + WorkManager.getInstance().enqueue(pushRegistrationWork) + } + + private fun setUpPeriodicLocalTokenRegistration () { + val periodicTokenRegistration = PeriodicWorkRequest.Builder( + PushRegistrationWorker::class.java, 1, + TimeUnit.DAYS + ) + .build() + + WorkManager.getInstance() + .enqueueUniquePeriodicWork( + "periodicTokenRegistration", ExistingPeriodicWorkPolicy.REPLACE, + periodicTokenRegistration + ) + } + + private fun setUpPeriodicTokenRefreshFromFCM () { + val periodicTokenRefreshFromFCM = PeriodicWorkRequest.Builder( + GetFirebasePushTokenWorker::class.java, 30, + TimeUnit.DAYS + ) + .build() + + WorkManager.getInstance() + .enqueueUniquePeriodicWork( + "periodicTokenRefreshFromFCM", ExistingPeriodicWorkPolicy.REPLACE, + periodicTokenRefreshFromFCM + ) + } } \ No newline at end of file From 4629d02dc48c23672416606a25f10597e98fb785 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 19 Jan 2022 13:16:39 +0100 Subject: [PATCH 12/18] add copyright + minor refactoring Signed-off-by: Marcel Hibbe --- .../talk/utils/ClosedInterfaceImpl.java | 5 ++++ .../talk/jobs/GetFirebasePushTokenWorker.kt | 1 - .../talk/utils/ClosedInterfaceImpl.kt | 23 ++++++++++++++++++- .../application/NextcloudTalkApplication.kt | 6 +++-- .../talk/interfaces/ClosedInterface.kt | 2 ++ .../talk/jobs/PushRegistrationWorker.java | 2 ++ .../com/nextcloud/talk/utils/PushUtils.java | 12 +++++----- app/src/main/res/values/setup.xml | 2 ++ .../talk/utils/ClosedInterfaceImpl.java | 2 ++ 9 files changed, 45 insertions(+), 10 deletions(-) diff --git a/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java b/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java index 71c25e757..19ca5448b 100644 --- a/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java +++ b/app/src/generic/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java @@ -2,7 +2,9 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Marcel Hibbe * Copyright (C) 2017-2018 Mario Danic + * Copyright (C) 2022 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,5 +39,8 @@ public class ClosedInterfaceImpl implements ClosedInterface { @Override public void setUpPushTokenRegistration() { // no push notifications for generic build flavour :( + // If you want to develop push notifications without google play services, here is a good place to start... + // Also have a look at app/src/gplay/AndroidManifest.xml to see how to include a service that handles push + // notifications. } } diff --git a/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt b/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt index 89e3bd64a..236e50a43 100644 --- a/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt +++ b/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt @@ -48,7 +48,6 @@ class GetFirebasePushTokenWorker(val context: Context, workerParameters: WorkerP } val token = task.result - Log.d(TAG, "Fetching FCM registration token succeeded. token = $token") appPreferences?.pushToken = token val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt index 7ab19d8bb..3c19854d4 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -1,3 +1,24 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * @author Marcel Hibbe + * Copyright (C) 2017-2019 Mario Danic + * Copyright (C) 2022 Marcel Hibbe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.nextcloud.talk.utils import android.content.Intent @@ -84,4 +105,4 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi periodicTokenRefreshFromFCM ) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt index 66c766c34..02b26ed4b 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -2,8 +2,10 @@ * * Nextcloud Talk application * - * @author Mario Danic - * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com) + * @author Mario Danic + * @author Marcel Hibbe + * Copyright (C) 2017 Mario Danic + * Copyright (C) 2022 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt b/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt index fee12d99b..6ece537a1 100644 --- a/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt +++ b/app/src/main/java/com/nextcloud/talk/interfaces/ClosedInterface.kt @@ -2,7 +2,9 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Marcel Hibbe * Copyright (C) 2017-2018 Mario Danic + * Copyright (C) 2022 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java index a4a917b70..583bf7ed4 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java @@ -2,7 +2,9 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Marcel Hibbe * Copyright (C) 2017 Mario Danic + * Copyright (C) 2022 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index a5f06573e..f92b0a5ce 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -2,7 +2,9 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Marcel Hibbe * Copyright (C) 2017 Mario Danic + * Copyright (C) 2022 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -254,7 +256,8 @@ public class PushUtils { ncApi.registerDeviceForNotificationsWithNextcloud( credentials, - ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl()), nextcloudRegisterPushMap) + ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl()), + nextcloudRegisterPushMap) .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { @@ -263,8 +266,7 @@ public class PushUtils { @Override public void onNext(@NonNull PushRegistrationOverall pushRegistrationOverall) { - Log.d(TAG, - "pushToken successfully registered at nextcloud server. pushToken= " + token.substring(0,5) + "..."); + Log.d(TAG, "pushToken successfully registered at nextcloud server."); Map proxyMap = new HashMap<>(); proxyMap.put("pushToken", token); @@ -303,9 +305,7 @@ public class PushUtils { @Override public void onNext(@NonNull Void aVoid) { try { - Log.d(TAG, - "pushToken successfully registered at pushproxy. pushToken= " + proxyMap.get("pushToken").substring(0,5) + - "..."); + Log.d(TAG, "pushToken successfully registered at pushproxy."); createOrUpdateUser(proxyMap, userEntity); } catch (IOException e) { Log.e(TAG, "IOException while updating user", e); diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index fd304c3c0..8bf763543 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -3,7 +3,9 @@ ~ Nextcloud Talk application ~ ~ @author Mario Danic + ~ @author Marcel Hibbe ~ Copyright (C) 2017-2019 Mario Danic + ~ Copyright (C) 2022 Marcel Hibbe ~ ~ This program is free software: you can redistribute it and/or modify ~ it under the terms of the GNU General Public License as published by diff --git a/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java b/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java index 34c10d888..1625c9867 100644 --- a/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java +++ b/app/src/qa/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.java @@ -2,7 +2,9 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Marcel Hibbe * Copyright (C) 2017-2018 Mario Danic + * Copyright (C) 2022 Marcel Hibbe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From bdef83d402b2135c05cefe37beab15ba662e8b74 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 19 Jan 2022 15:22:02 +0100 Subject: [PATCH 13/18] reformat code Signed-off-by: Marcel Hibbe Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/utils/ClosedInterfaceImpl.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt index 3c19854d4..d120e17b4 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit @AutoInjector(NextcloudTalkApplication::class) class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallListener { - override val isGooglePlayServicesAvailable : Boolean = isGPlayServicesAvailable() + override val isGooglePlayServicesAvailable: Boolean = isGPlayServicesAvailable() override fun providerInstallerInstallIfNeededAsync() { NextcloudTalkApplication.sharedApplication?.let { @@ -56,7 +56,7 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi override fun onProviderInstallFailed(p0: Int, p1: Intent?) { } - private fun isGPlayServicesAvailable() : Boolean { + private fun isGPlayServicesAvailable(): Boolean { val api = GoogleApiAvailability.getInstance() val code = NextcloudTalkApplication.sharedApplication?.let { @@ -73,12 +73,12 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi setUpPeriodicTokenRefreshFromFCM() } - private fun registerLocalToken(){ + private fun registerLocalToken() { val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() WorkManager.getInstance().enqueue(pushRegistrationWork) } - private fun setUpPeriodicLocalTokenRegistration () { + private fun setUpPeriodicLocalTokenRegistration() { val periodicTokenRegistration = PeriodicWorkRequest.Builder( PushRegistrationWorker::class.java, 1, TimeUnit.DAYS @@ -92,7 +92,7 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi ) } - private fun setUpPeriodicTokenRefreshFromFCM () { + private fun setUpPeriodicTokenRefreshFromFCM() { val periodicTokenRefreshFromFCM = PeriodicWorkRequest.Builder( GetFirebasePushTokenWorker::class.java, 30, TimeUnit.DAYS From c8274fe74021dbb341c76d36d4461ff627e5e05c Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 19 Jan 2022 18:14:06 +0100 Subject: [PATCH 14/18] add string for origin to PushRegistrationWorker for debugging Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt | 7 ++++++- .../services/firebase/MagicFirebaseMessagingService.kt | 6 +++++- .../java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt | 9 ++++++++- .../talk/application/NextcloudTalkApplication.kt | 1 + .../talk/controllers/AccountVerificationController.java | 7 ++++++- .../talk/controllers/WebViewLoginController.java | 8 +++++++- .../com/nextcloud/talk/jobs/PushRegistrationWorker.java | 6 ++++++ .../main/java/com/nextcloud/talk/utils/PushUtils.java | 4 ++++ 8 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt b/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt index 236e50a43..38206210a 100644 --- a/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt +++ b/app/src/gplay/java/com/nextcloud/talk/jobs/GetFirebasePushTokenWorker.kt @@ -23,6 +23,7 @@ package com.nextcloud.talk.jobs import android.annotation.SuppressLint import android.content.Context import android.util.Log +import androidx.work.Data import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import androidx.work.Worker @@ -50,7 +51,11 @@ class GetFirebasePushTokenWorker(val context: Context, workerParameters: WorkerP val token = task.result appPreferences?.pushToken = token - val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + + val data: Data = Data.Builder().putString(PushRegistrationWorker.ORIGIN, "GetFirebasePushTokenWorker").build() + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java) + .setInputData(data) + .build() WorkManager.getInstance(context).enqueue(pushRegistrationWork) }) diff --git a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt index a6cd04693..1cb242863 100644 --- a/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt +++ b/app/src/gplay/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.kt @@ -131,7 +131,11 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() { sharedApplication!!.componentApplication.inject(this) appPreferences!!.pushToken = token Log.d(TAG, "onNewToken. token = $token") - val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + + val data: Data = Data.Builder().putString(PushRegistrationWorker.ORIGIN, "onNewToken").build() + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java) + .setInputData(data) + .build() WorkManager.getInstance().enqueue(pushRegistrationWork) } diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt index d120e17b4..bc8b08d31 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -22,6 +22,7 @@ package com.nextcloud.talk.utils import android.content.Intent +import androidx.work.Data import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.OneTimeWorkRequest import androidx.work.PeriodicWorkRequest @@ -74,15 +75,21 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi } private fun registerLocalToken() { - val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java).build() + val data: Data = Data.Builder().putString(PushRegistrationWorker.ORIGIN, "ClosedInterfaceImpl#registerLocalToken").build() + val pushRegistrationWork = OneTimeWorkRequest.Builder(PushRegistrationWorker::class.java) + .setInputData(data) + .build() WorkManager.getInstance().enqueue(pushRegistrationWork) } private fun setUpPeriodicLocalTokenRegistration() { + val data: Data = Data.Builder().putString(PushRegistrationWorker.ORIGIN, "ClosedInterfaceImpl#setUpPeriodicLocalTokenRegistration").build() + val periodicTokenRegistration = PeriodicWorkRequest.Builder( PushRegistrationWorker::class.java, 1, TimeUnit.DAYS ) + .setInputData(data) .build() WorkManager.getInstance() diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt index 02b26ed4b..e31fe0daf 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -130,6 +130,7 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver { //region Overridden methods override fun onCreate() { + Log.d(TAG, "onCreate") sharedApplication = this val securityKeyManager = SecurityKeyManager.getInstance() diff --git a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java index 47aaaf42f..59d9d9f4a 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java @@ -377,7 +377,12 @@ public class AccountVerificationController extends BaseController { } private void registerForPush() { - OneTimeWorkRequest pushRegistrationWork = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class).build(); + Data data = + new Data.Builder().putString(PushRegistrationWorker.ORIGIN, "AccountVerificationController#registerForPush").build(); + + OneTimeWorkRequest pushRegistrationWork = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class) + .setInputData(data) + .build(); WorkManager.getInstance().enqueue(pushRegistrationWork); } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java index 542ecfbad..1d5f7a05b 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java @@ -76,6 +76,7 @@ import javax.inject.Inject; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.res.ResourcesCompat; +import androidx.work.Data; import androidx.work.OneTimeWorkRequest; import androidx.work.WorkManager; import autodagger.AutoInjector; @@ -407,7 +408,12 @@ public class WebViewLoginController extends BaseController { ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType); } - OneTimeWorkRequest pushRegistrationWork = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class).build(); + Data data = + new Data.Builder().putString(PushRegistrationWorker.ORIGIN, + "WebViewLoginController#parseAndLoginFromWebView").build(); + OneTimeWorkRequest pushRegistrationWork = new OneTimeWorkRequest.Builder(PushRegistrationWorker.class) + .setInputData(data) + .build(); WorkManager.getInstance().enqueue(pushRegistrationWork); getRouter().popCurrentController(); diff --git a/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java index 583bf7ed4..71cbc29b2 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/PushRegistrationWorker.java @@ -26,6 +26,7 @@ import android.content.Context; import android.util.Log; import androidx.annotation.NonNull; +import androidx.work.Data; import androidx.work.Worker; import androidx.work.WorkerParameters; @@ -34,6 +35,7 @@ import com.nextcloud.talk.utils.PushUtils; public class PushRegistrationWorker extends Worker { public static final String TAG = "PushRegistrationWorker"; + public static final String ORIGIN = "origin"; public PushRegistrationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); @@ -43,6 +45,10 @@ public class PushRegistrationWorker extends Worker { @Override public Result doWork() { if(new ClosedInterfaceImpl().isGooglePlayServicesAvailable()){ + Data data = getInputData(); + String origin = data.getString("origin"); + Log.d(TAG, "PushRegistrationWorker called via " + origin); + PushUtils pushUtils = new PushUtils(); pushUtils.generateRsa2048KeyPair(); pushUtils.pushRegistrationToServer(); diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index f92b0a5ce..bf363681d 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -230,10 +230,14 @@ public class PushUtils { devicePublicKeyBase64 = "-----BEGIN PUBLIC KEY-----\n" + devicePublicKeyBase64 + "\n-----END PUBLIC KEY-----\n"; + Log.d(TAG, "userUtils.getUsers().size(): " + userUtils.getUsers().size()); + if (userUtils.anyUserExists()) { for (Object userEntityObject : userUtils.getUsers()) { UserEntity userEntity = (UserEntity) userEntityObject; + Log.d(TAG, "userEntity.getUsername(): " + userEntity.getUsername()); + if (!userEntity.getScheduledForDeletion()) { Map nextcloudRegisterPushMap = new HashMap<>(); nextcloudRegisterPushMap.put("format", "json"); From 6f302c25c47f8ce912e5ebef61f7a0e735d68da8 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 20 Jan 2022 11:02:06 +0100 Subject: [PATCH 15/18] add flexinterval for PeriodicWorkRequests so the actions are not triggered when PeriodicWorkRequests are created. Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/utils/ClosedInterfaceImpl.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt index bc8b08d31..7dc8ff74d 100644 --- a/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt +++ b/app/src/gplay/java/com/nextcloud/talk/utils/ClosedInterfaceImpl.kt @@ -86,8 +86,11 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi val data: Data = Data.Builder().putString(PushRegistrationWorker.ORIGIN, "ClosedInterfaceImpl#setUpPeriodicLocalTokenRegistration").build() val periodicTokenRegistration = PeriodicWorkRequest.Builder( - PushRegistrationWorker::class.java, 1, - TimeUnit.DAYS + PushRegistrationWorker::class.java, + 24, + TimeUnit.HOURS, + 10, + TimeUnit.HOURS ) .setInputData(data) .build() @@ -101,8 +104,11 @@ class ClosedInterfaceImpl : ClosedInterface, ProviderInstaller.ProviderInstallLi private fun setUpPeriodicTokenRefreshFromFCM() { val periodicTokenRefreshFromFCM = PeriodicWorkRequest.Builder( - GetFirebasePushTokenWorker::class.java, 30, - TimeUnit.DAYS + GetFirebasePushTokenWorker::class.java, + 30, + TimeUnit.DAYS, + 10, + TimeUnit.DAYS, ) .build() From f582525fef4b2afba8e88d54e23ee4172975fc08 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 20 Jan 2022 11:24:54 +0100 Subject: [PATCH 16/18] remove logging so the actions are not triggered when PeriodicWorkRequests are created. Signed-off-by: Marcel Hibbe --- app/src/main/java/com/nextcloud/talk/utils/PushUtils.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index bf363681d..03b273d00 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -230,14 +230,10 @@ public class PushUtils { devicePublicKeyBase64 = "-----BEGIN PUBLIC KEY-----\n" + devicePublicKeyBase64 + "\n-----END PUBLIC KEY-----\n"; - Log.d(TAG, "userUtils.getUsers().size(): " + userUtils.getUsers().size()); - if (userUtils.anyUserExists()) { for (Object userEntityObject : userUtils.getUsers()) { UserEntity userEntity = (UserEntity) userEntityObject; - Log.d(TAG, "userEntity.getUsername(): " + userEntity.getUsername()); - if (!userEntity.getScheduledForDeletion()) { Map nextcloudRegisterPushMap = new HashMap<>(); nextcloudRegisterPushMap.put("format", "json"); @@ -270,7 +266,7 @@ public class PushUtils { @Override public void onNext(@NonNull PushRegistrationOverall pushRegistrationOverall) { - Log.d(TAG, "pushToken successfully registered at nextcloud server."); + Log.d(TAG, "pushTokenHash successfully registered at nextcloud server."); Map proxyMap = new HashMap<>(); proxyMap.put("pushToken", token); From 9b55467af344aabf0fdea18e20b149f7f2857732 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 20 Jan 2022 11:34:46 +0100 Subject: [PATCH 17/18] moved execution of setUpPushTokenRegistration so token is registered everytime the conversation list is opened. In NextcloudTalkApplication it was not executed when app was still in background when opening Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/application/NextcloudTalkApplication.kt | 2 -- .../talk/controllers/ConversationsListController.java | 4 ++++ scripts/analysis/lint-results.txt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt index e31fe0daf..4c391d3b5 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -167,8 +167,6 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver { ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync() DeviceUtils.ignoreSpecialBatteryFeatures() - ClosedInterfaceImpl().setUpPushTokenRegistration() - val accountRemovalWork = OneTimeWorkRequest.Builder(AccountRemovalWorker::class.java).build() val periodicCapabilitiesUpdateWork = PeriodicWorkRequest.Builder( CapabilitiesWorker::class.java, diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java index e2a152572..76b3867ba 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -85,6 +85,7 @@ import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.models.json.participants.Participant; import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment; import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.ClosedInterfaceImpl; import com.nextcloud.talk.utils.ConductorRemapping; import com.nextcloud.talk.utils.DisplayUtils; import com.nextcloud.talk.utils.KeyboardUtils; @@ -285,6 +286,9 @@ public class ConversationsListController extends BaseController implements Searc @Override protected void onAttach(@NonNull View view) { super.onAttach(view); + + new ClosedInterfaceImpl().setUpPushTokenRegistration(); + if (!eventBus.isRegistered(this)) { eventBus.register(this); } diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index 96101281e..7d0dd5fec 100644 --- a/scripts/analysis/lint-results.txt +++ b/scripts/analysis/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 1 error and 222 warnings + Lint Report: 1 error and 224 warnings From 772fde2334aca9b856ff7ca2be6cbabb3801b286 Mon Sep 17 00:00:00 2001 From: drone Date: Thu, 20 Jan 2022 15:03:27 +0000 Subject: [PATCH 18/18] Drone: update FindBugs results to reflect reduced error/warning count [skip ci] Signed-off-by: drone --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index 4c38412cc..c02176735 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -559 \ No newline at end of file +558 \ No newline at end of file