-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(android/engine): Parse keyboards.json for FirstVoices app #11943
Conversation
User Test ResultsTest specification and instructions
Test Artifacts |
I note the keyboard names now come straight from the individual keyboard kmn |
Test Results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way this is going. But I think we need to have better error handling and a unit test for the new function.
https://keyman.sentry.io/issues/?project=5983532&statsPeriod=90d shows that we are collecting Sentry data for FV Keyboards (this report needs auditing by the way), so let's leverage that in this function as well -- let exceptions propagate to Sentry.
if (!jsonFile.exists()) { | ||
return list; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it should be fatal because if this cannot be loaded, we don't get any data for the keyboards, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to throw fatal Error if keyboards.json doesn't exist
if (keyboardsArray == null) { | ||
Log.d("loadRegionList", "unable to load keyboards.json"); | ||
return list; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Malformed data should at the very least be reporting to sentry, or killing the app so we know that there is something wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the following to use KMLog to sentry.
Are you wanting to throw fatal errors for all of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you wanting to throw fatal errors for all of them?
I think so -- if our keyboards.json is invalid, we should reject the build at startup.
if (keyboardObj == null) { | ||
Log.d("loadRegionList", "keyboard Obj is null"); | ||
continue; | ||
} | ||
JSONArray languageArray = keyboardObj.getJSONArray("languages"); | ||
if (languageArray == null) { | ||
Log.d("loadRegionList", "language Array is null"); | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
File resourceRoot = new File(getResourceRoot()); | ||
PackageProcessor kmpProcessor = new PackageProcessor(resourceRoot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. removed
File resourceRoot = new File(getResourceRoot()); | ||
PackageProcessor kmpProcessor = new PackageProcessor(resourceRoot); | ||
JSONParser parser = new JSONParser(); | ||
File jsonFile = new File(getPackagesDir() + FVDefault_PackageID + File.separator + FVKeyboards_JSON); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pass this path in as a parameter, then we could add a unit test for this quite easily I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add the keyboards.json path as a parameter to loadRegionList().
I don't think the FV project is running any unit tests, so I'd have to add some plumbing for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add the keyboards.json path as a parameter to loadRegionList().
Good stuff.
I don't think the FV project is running any unit tests, so I'd have to add some plumbing for that.
Yep, future project :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, future project :)
Tracked as #12098
} catch (Exception e) { | ||
Log.e("createKeyboardList", "Error: " + e); | ||
// We'll return a malformed list for now in this situation | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be crashing the app so we can detect this -- a malformed list will make the app unusable anyway, won't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block was pre-existing.
I've updated to throw fatal error
if (BuildConfig.DEBUG) { | ||
KMManager.setDebugMode(true); | ||
} | ||
KMManager.initialize(getApplicationContext(), KMManager.KeyboardType.KEYBOARD_TYPE_INAPP); | ||
|
||
FVShared.getInstance().initialize(this); | ||
|
||
FVShared.getInstance().upgradeTo12(); | ||
FVShared.getInstance().upgradeTo14(); | ||
FVShared.getInstance().preloadPackages(); | ||
|
||
if (BuildConfig.DEBUG) { | ||
KMManager.setDebugMode(true); | ||
} | ||
KMManager.initialize(getApplicationContext(), KMManager.KeyboardType.KEYBOARD_TYPE_INAPP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this change in initialization order cause problems for upgrade scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure - atm I don't have a clear way to test upgrade scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the purpose of changing the order? Was it needed for the load?
Re testing upgrade scenarios, can't we just get user testers to install an old version of say 12.x or 14.x and then upgrade it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, KMManager.initialize()
hasn't happened yet, so the fv_all.kmp file hasn't been extracted.
This is why we've been copying keyboards.csv
into the assets folder during the build.sh process (at the same folder as fv_all.kmp).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small change requested but apart from that LGTM
String errorMsg = "loadRegionList had malformed keyboard list"; | ||
KMLog.LogException(TAG, errorMsg, e); | ||
// Crash the app | ||
throw new Error(errorMsg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an antipattern -- masking the original error in the thrown exception. Should re-throw e.
After cleanup, ready for re-testing |
Test Results
|
Changes in this pull request will be available for download in Keyman version 18.0.85-alpha |
Relates to #2036
This PR migrates the FirstVoices for Android app from using keyboards.csv to using the keyboards.json metadata file published within fv_all.kmp (as of keymanapp/keyboards#2872)
All the keyboard info along with region names are included in keyboards.json, so startup is just a matter of populating the keyboard info from it.
Note: I'm leaving keyboards.csv in the repo because the FirstVoices app for iOS still uses it.
User Testing
Setup - Install the PR build of FirstVoices for Android on an Android device/emulator