From a91f1d42b0bbbb78220aadd8c5166d02fa33be05 Mon Sep 17 00:00:00 2001 From: banji180 Date: Tue, 23 Aug 2022 09:52:50 -0700 Subject: [PATCH] Update cache when awsconfig file changes (#2946) * Update cache when awsconfig file changes * added comment to the change Co-authored-by: Banji Jolaoso --- .../com/amazonaws/mobile/client/AWSMobileClient.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java b/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java index 501f9b6adf..2e3b30d790 100644 --- a/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java +++ b/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java @@ -705,19 +705,18 @@ JSONObject getHostedUIJSON() { JSONObject getHostedUIJSON(final AWSConfiguration awsConfig) { try { JSONObject hostedUIJSONFromJSON = getHostedUIJSONFromJSON(awsConfig); - if (hostedUIJSONFromJSON == null) { - return null; - } - final String hostedUIString = mStore.get(HOSTED_UI_KEY); JSONObject hostedUIJSON = null; try { hostedUIJSON = new JSONObject(hostedUIString); } catch (Exception e) { Log.w(TAG, - "Failed to parse HostedUI settings from store. Defaulting to awsconfiguration.json", e); + "Failed to parse HostedUI settings from store", e); } - if (hostedUIJSON == null && hostedUIJSONFromJSON != null) { + + // Since there is no file watcher to keep track of when config file changes, this logic is intended to always check if the config file is different from mstore cache and updates the later accordingly. + // If config file cannot be loaded, the mstore data still prevails. + if (hostedUIJSONFromJSON != null && (hostedUIJSON == null || hostedUIJSON.toString() != hostedUIJSONFromJSON.toString())) { hostedUIJSON = new JSONObject(hostedUIJSONFromJSON.toString()); mStore.set(HOSTED_UI_KEY, hostedUIJSON.toString()); }