Merge pull request #7781 from keymanapp/fix/android/cloud-catalog-for-local-test

fix(android/engine): Make it easier to test keyboard updates
This commit is contained in:
Darcy Wong 2022-11-24 08:19:36 +07:00 committed by GitHub
commit 6098e33eb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 22 deletions

View file

@ -30,12 +30,12 @@ import java.lang.IllegalArgumentException;
import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;
import com.tavultesoft.kmapro.BuildConfig;
import com.tavultesoft.kmapro.MainActivity;
import com.tavultesoft.kmapro.R;
import com.tavultesoft.kmea.KmpInstallMode;
import com.tavultesoft.kmea.util.KMLog;
import com.tavultesoft.kmea.util.KMString;
import com.tavultesoft.kmea.util.VersionUtils;
public class CheckInstallReferrer {
private static final String TAG = "CheckInstallReferrer";
@ -66,8 +66,7 @@ public class CheckInstallReferrer {
editor.commit();
// local environment or test builds are nearly always side loaded
if (BuildConfig.VERSION_ENVIRONMENT.equalsIgnoreCase("local") ||
BuildConfig.VERSION_NAME.matches("^.*(-test-\\d+)$")) {
if (VersionUtils.isLocalBuild() || VersionUtils.isTestBuild()) {
return;
}

View file

@ -153,20 +153,24 @@ public class CloudDataJsonUtil {
for (int i = 0; i < KeyboardController.getInstance().get().size(); i++) {
Keyboard kbd = KeyboardController.getInstance().getKeyboardInfo(i);
String version = kbd.getVersion();
String updateKMP = kbd.getUpdateKMP();
if (keyboardID.equalsIgnoreCase(kbd.getKeyboardID()) &&
FileUtils.compareVersions(cloudVersion, version) == FileUtils.VERSION_GREATER &&
updateKMP != null &&
!updateKMP.equalsIgnoreCase(cloudKMP)) {
// Update keyboard with the latest KMP link
kbd.setUpdateKMP(cloudKMP);
KeyboardController.getInstance().add(kbd);
FileUtils.compareVersions(cloudVersion, version) == FileUtils.VERSION_GREATER) {
// Cloud catalog has newer KMP version available
String updateKMP = kbd.getUpdateKMP();
if (updateKMP != null) {
if (!updateKMP.equalsIgnoreCase(cloudKMP)) {
// Update keyboard info with the latest KMP link
kbd.setUpdateKMP(cloudKMP);
KeyboardController.getInstance().add(kbd);
saveKeyboardList = true;
}
// Update bundle list
Bundle bundle = new Bundle(kbd.buildDownloadBundle());
updateBundles.add(bundle);
saveKeyboardList = true;
if (!updateKMP.isEmpty()) {
// Update bundle list for update notifications
Bundle bundle = new Bundle(kbd.buildDownloadBundle());
updateBundles.add(bundle);
}
}
}
}
}

View file

@ -18,6 +18,7 @@ import com.tavultesoft.kmea.data.KeyboardController;
import com.tavultesoft.kmea.data.LanguageResource;
import com.tavultesoft.kmea.data.LexicalModel;
import com.tavultesoft.kmea.util.FileUtils;
import com.tavultesoft.kmea.util.VersionUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -69,7 +70,8 @@ public class CloudCatalogDownloadCallback implements ICloudDownloadCallback<Data
};
}
private Bundle updateCheck(LanguageResource cloudResource, LanguageResource existingMatch) {
if (DEBUG_SIMULATE_UPDATES) {
// For local and PR test builds, invalidate cache to make keyboard updates easier
if (DEBUG_SIMULATE_UPDATES || VersionUtils.isLocalOrTestBuild()) {
return cloudResource.buildDownloadBundle();
}

View file

@ -20,6 +20,7 @@ import com.tavultesoft.kmea.cloud.CloudDownloadMgr;
import com.tavultesoft.kmea.packages.JSONUtils;
import com.tavultesoft.kmea.util.BCP47;
import com.tavultesoft.kmea.util.KMLog;
import com.tavultesoft.kmea.util.VersionUtils;
import org.json.JSONArray;
import org.json.JSONException;
@ -89,6 +90,7 @@ public class CloudRepository {
boolean loadResourcesFromCache = this.shouldUseCache(context, CloudDataJsonUtil.getResourcesCacheFile(context));
boolean cacheValid = loadLexicalModelsFromCache && loadResourcesFromCache;
return cacheValid;
}
@ -238,7 +240,8 @@ public class CloudRepository {
{
boolean cacheValid = getCacheValidity(context);
if(cacheValid && shouldUseMemCache(context)) {
// For local and PR test builds, force update dataset
if(cacheValid && shouldUseMemCache(context) && !VersionUtils.isLocalOrTestBuild()) {
onSuccess.run();
return; // isn't null - checked by `shouldUseCache`.
}
@ -365,7 +368,8 @@ public class CloudRepository {
private void downloadMetaDataFromServer(@NonNull Context context, UpdateHandler updateHandler, Runnable onSuccess, Runnable onFailure) {
boolean cacheValid = getCacheValidity(context);
if(cacheValid && shouldUseMemCache(context)) {
// For local and PR test builds, force download of metadata
if(cacheValid && shouldUseMemCache(context) && !VersionUtils.isLocalOrTestBuild()) {
return; // isn't null - checked by `shouldUseCache`.
} else if (!KMManager.hasInternetPermission(context) || !KMManager.hasConnection(context)) {
// noop if no internet permission or network connection
@ -383,7 +387,8 @@ public class CloudRepository {
// int cloudQueryEntries = 0;
List<CloudApiTypes.CloudApiParam> cloudQueries = new ArrayList<>(2);
if (!cacheValid) {
// For local and PR test builds, force check of keyboard updates
if (!cacheValid || VersionUtils.isLocalOrTestBuild()) {
cloudQueries.add(prepareResourcesUpdateQuery(context));
}

View file

@ -28,6 +28,7 @@ import com.tavultesoft.kmea.KeyboardEventHandler;
import com.tavultesoft.kmea.R;
import com.tavultesoft.kmea.data.CloudRepository;
import com.tavultesoft.kmea.util.KMLog;
import com.tavultesoft.kmea.util.VersionUtils;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
@ -296,6 +297,11 @@ public class ResourcesUpdateTool implements KeyboardEventHandler.OnKeyboardDownl
* @return true if the notification should be ignored
*/
private boolean shouldIgnoreNotification(String id) {
// For local and PR test builds, return false to make it easier to get updates for testing
if (VersionUtils.isLocalOrTestBuild()) {
return false;
}
SharedPreferences prefs = currentContext.getSharedPreferences(currentContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
String ignoredNotificationsStr = prefs.getString(PREF_KEY_IGNORE_NOTIFICATIONS, null);
@ -464,6 +470,10 @@ public class ResourcesUpdateTool implements KeyboardEventHandler.OnKeyboardDownl
}
public boolean shouldCheckUpdate(Context aContext) {
// For local and PR test builds, invalidate cache to make keyboard updates easier
if (VersionUtils.isLocalOrTestBuild() || FORCE_RESOURCE_UPDATE) {
return true;
}
boolean shouldCheckUpdate = false;
if (lastUpdateCheck == null) {
SharedPreferences prefs = aContext.getSharedPreferences(aContext.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
@ -491,9 +501,6 @@ public class ResourcesUpdateTool implements KeyboardEventHandler.OnKeyboardDownl
shouldCheckUpdate = true;
}
if(FORCE_RESOURCE_UPDATE)
shouldCheckUpdate = true;
return shouldCheckUpdate;
}

View file

@ -0,0 +1,26 @@
/**
* Copyright (C) 2022 SIL International. All rights reserved.
*/
package com.tavultesoft.kmea.util;
import com.tavultesoft.kmea.BuildConfig;
/**
* Utilities to determine if a build is local or a test (PR) build.
*/
public final class VersionUtils {
public static final String TAG = "VersionUtils";
public static boolean isLocalBuild() {
return BuildConfig.VERSION_ENVIRONMENT.equalsIgnoreCase("local");
}
public static boolean isTestBuild() {
return BuildConfig.VERSION_ENVIRONMENT.equalsIgnoreCase("test");
}
// Utility for local and PR test builds - e.g. force check of keyboard updates
public static boolean isLocalOrTestBuild() {
return isLocalBuild() || isTestBuild();
}
}