From 285d21db06a00d8e8316100fa41afe7e906df06d Mon Sep 17 00:00:00 2001 From: Jeasmine Nahui Date: Thu, 13 May 2021 15:40:36 -0300 Subject: [PATCH 1/2] Add setDisableGMSMissingPrompt public method * Add public setter for disableGMSMissingPrompt, delay setter until remote params are set, do not override dashboard configuration * Use param under showUpdateGPSDialog --- .../GooglePlayServicesUpgradePrompt.java | 2 +- .../onesignal/OSRemoteParamController.java | 7 +++++- .../com/onesignal/OSTaskRemoteController.java | 2 ++ .../main/java/com/onesignal/OneSignal.java | 25 +++++++++++++++++++ .../com/onesignal/OneSignalRemoteParams.java | 6 ++--- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java index 33777df19a..d8c4253349 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java @@ -44,7 +44,7 @@ static void showUpdateGPSDialog() { @Override public void run() { final Activity activity = OneSignal.getCurrentActivity(); - if (activity == null) + if (activity == null || OneSignal.getDisableGMSMissingPrompt()) return; // Load resource strings so a developer can customize this dialog diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSRemoteParamController.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSRemoteParamController.java index b0891b7cf1..abed21ef79 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSRemoteParamController.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSRemoteParamController.java @@ -47,7 +47,8 @@ void saveRemoteParams(OneSignalRemoteParams.Params remoteParams, logger.debug("OneSignal saveInfluenceParams: " + remoteParams.influenceParams.toString()); trackerFactory.saveInfluenceParams(remoteParams.influenceParams); - saveGMSMissingPromptDisable(remoteParams.disableGMSMissingPrompt); + if (remoteParams.disableGMSMissingPrompt != null) + saveGMSMissingPromptDisable(remoteParams.disableGMSMissingPrompt); if (remoteParams.unsubscribeWhenNotificationsDisabled != null) saveUnsubscribeWhenNotificationsAreDisabled(remoteParams.unsubscribeWhenNotificationsDisabled); if (remoteParams.locationShared != null) @@ -64,6 +65,10 @@ OneSignalRemoteParams.Params getRemoteParams() { return remoteParams; } + boolean hasDisableGMSMissingPromptKey() { + return remoteParams != null && remoteParams.disableGMSMissingPrompt != null; + } + boolean hasLocationKey() { return remoteParams != null && remoteParams.locationShared != null; } diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSTaskRemoteController.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSTaskRemoteController.java index 9ef813c990..8a8927d1d2 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSTaskRemoteController.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSTaskRemoteController.java @@ -19,6 +19,7 @@ class OSTaskRemoteController extends OSTaskController { static final String SEND_TAG = "sendTag()"; static final String SEND_TAGS = "sendTags()"; static final String SET_LOCATION_SHARED = "setLocationShared()"; + static final String SET_DISABLE_GMS_MISSING_PROMPT = "setDisableGMSMissingPrompt()"; static final String SET_REQUIRES_USER_PRIVACY_CONSENT = "setRequiresUserPrivacyConsent()"; static final String UNSUBSCRIBE_WHEN_NOTIFICATION_ARE_DISABLED = "unsubscribeWhenNotificationsAreDisabled()"; static final String HANDLE_NOTIFICATION_OPEN = "handleNotificationOpen()"; @@ -44,6 +45,7 @@ class OSTaskRemoteController extends OSTaskController { SEND_TAG, SEND_TAGS, SET_LOCATION_SHARED, + SET_DISABLE_GMS_MISSING_PROMPT, SET_REQUIRES_USER_PRIVACY_CONSENT, UNSUBSCRIBE_WHEN_NOTIFICATION_ARE_DISABLED, HANDLE_NOTIFICATION_OPEN, diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java index e189018a1f..7258060514 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java @@ -2616,6 +2616,31 @@ public void run() { OneSignalStateSynchronizer.setSubscription(!disable); } + + /** + * This method will be replaced by remote params set + */ + public static void setDisableGMSMissingPrompt(final boolean promptDisable) { + if (taskRemoteController.shouldQueueTaskForInit(OSTaskRemoteController.SET_DISABLE_GMS_MISSING_PROMPT)) { + logger.error("Waiting for remote params. " + + "Moving " + OSTaskRemoteController.SET_DISABLE_GMS_MISSING_PROMPT + " operation to a pending task queue."); + taskRemoteController.addTaskToQueue(new Runnable() { + @Override + public void run() { + logger.debug("Running " + OSTaskRemoteController.SET_DISABLE_GMS_MISSING_PROMPT + " operation from pending task queue."); + setDisableGMSMissingPrompt(promptDisable); + } + }); + return; + } + + // Already set by remote params + if (getRemoteParamController().hasDisableGMSMissingPromptKey()) + return; + + getRemoteParamController().saveGMSMissingPromptDisable(promptDisable); + } + /** * This method will be replaced by remote params set */ diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalRemoteParams.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalRemoteParams.java index eb8423d9fc..43c4224696 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalRemoteParams.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalRemoteParams.java @@ -83,7 +83,7 @@ static class Params { boolean restoreTTLFilter; boolean clearGroupOnSummaryClick; boolean receiveReceiptEnabled; - boolean disableGMSMissingPrompt; + Boolean disableGMSMissingPrompt; Boolean unsubscribeWhenNotificationsDisabled; Boolean locationShared; Boolean requiresUserPrivacyConsent; @@ -182,9 +182,9 @@ static private void processJson(String json, final @NonNull Callback callBack) { clearGroupOnSummaryClick = responseJson.optBoolean("clear_group_on_summary_click", true); receiveReceiptEnabled = responseJson.optBoolean("receive_receipts_enable", false); - disableGMSMissingPrompt = responseJson.optBoolean(DISABLE_GMS_MISSING_PROMPT, false); // Null assignation to avoid remote param override user configuration until backend is done - // TODO remove has check when backend has new remote params and user sets inside OneSignal.java were removed + // TODO remove the has check when backend has new remote params and sets inside OneSignal.java are removed + disableGMSMissingPrompt = !responseJson.has(DISABLE_GMS_MISSING_PROMPT) ? null : responseJson.optBoolean(DISABLE_GMS_MISSING_PROMPT, false); unsubscribeWhenNotificationsDisabled = !responseJson.has(UNSUBSCRIBE_ON_NOTIFICATION_DISABLE) ? null : responseJson.optBoolean(UNSUBSCRIBE_ON_NOTIFICATION_DISABLE, true); locationShared = !responseJson.has(LOCATION_SHARED) ? null : responseJson.optBoolean(LOCATION_SHARED, true); requiresUserPrivacyConsent = !responseJson.has(REQUIRES_USER_PRIVACY_CONSENT) ? null : responseJson.optBoolean(REQUIRES_USER_PRIVACY_CONSENT, false); From c51471281485e8367a4ac4e21b655ecbaf84feb7 Mon Sep 17 00:00:00 2001 From: Jeasmine Nahui Date: Mon, 17 May 2021 19:41:06 -0300 Subject: [PATCH 2/2] Improve disableGMSMissingPrompt handling * Rename from setDisableGMSMissingPrompt to disableGMSMissingPrompt * Move disableGMSMissingPrompt check before changing thread * Remove delay from disableGMSMissingPrompt, since this is data is needed immediately after setting remote params --- .../GooglePlayServicesUpgradePrompt.java | 7 +++++-- .../src/main/java/com/onesignal/OneSignal.java | 15 +-------------- .../com/onesignal/ShadowPushRegistratorFCM.java | 1 - 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java index d8c4253349..32bd9f7cc9 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GooglePlayServicesUpgradePrompt.java @@ -28,7 +28,10 @@ private static boolean isGooglePlayStoreInstalled() { } static void showUpdateGPSDialog() { - if (!OSUtils.isAndroidDeviceType() || !isGooglePlayStoreInstalled()) + if (!OSUtils.isAndroidDeviceType()) + return; + + if (!isGooglePlayStoreInstalled() || OneSignal.getDisableGMSMissingPrompt()) return; boolean userSelectedSkip = @@ -44,7 +47,7 @@ static void showUpdateGPSDialog() { @Override public void run() { final Activity activity = OneSignal.getCurrentActivity(); - if (activity == null || OneSignal.getDisableGMSMissingPrompt()) + if (activity == null) return; // Load resource strings so a developer can customize this dialog diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java index 7258060514..41d91e919f 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java @@ -2620,20 +2620,7 @@ public void run() { /** * This method will be replaced by remote params set */ - public static void setDisableGMSMissingPrompt(final boolean promptDisable) { - if (taskRemoteController.shouldQueueTaskForInit(OSTaskRemoteController.SET_DISABLE_GMS_MISSING_PROMPT)) { - logger.error("Waiting for remote params. " + - "Moving " + OSTaskRemoteController.SET_DISABLE_GMS_MISSING_PROMPT + " operation to a pending task queue."); - taskRemoteController.addTaskToQueue(new Runnable() { - @Override - public void run() { - logger.debug("Running " + OSTaskRemoteController.SET_DISABLE_GMS_MISSING_PROMPT + " operation from pending task queue."); - setDisableGMSMissingPrompt(promptDisable); - } - }); - return; - } - + public static void disableGMSMissingPrompt(final boolean promptDisable) { // Already set by remote params if (getRemoteParamController().hasDisableGMSMissingPromptKey()) return; diff --git a/OneSignalSDK/unittest/src/test/java/com/onesignal/ShadowPushRegistratorFCM.java b/OneSignalSDK/unittest/src/test/java/com/onesignal/ShadowPushRegistratorFCM.java index 720f3735a2..271901592d 100644 --- a/OneSignalSDK/unittest/src/test/java/com/onesignal/ShadowPushRegistratorFCM.java +++ b/OneSignalSDK/unittest/src/test/java/com/onesignal/ShadowPushRegistratorFCM.java @@ -74,7 +74,6 @@ public void registerForPush(Context context, String senderId, PushRegistrator.Re @Implementation public void internalRegisterForPush(String senderId) {} - public static void fireLastCallback() { lastCallback.complete(fail ? null : regId, fail ? -7 : 1); }