Removed errors from PackageProcessor integration. gff_amh_7 keyboard still has problems, though.

This commit is contained in:
Joshua A. Horton 2018-01-19 11:47:36 +07:00
parent 8c223a10ed
commit 2b3cb459e5
3 changed files with 35 additions and 21 deletions

View file

@ -194,14 +194,14 @@ public class KMKeyboardDownloaderActivity extends Activity {
public void onClick(DialogInterface dialog, int which) {
try {
// Downgrade/reinstall package
List<Map<String, String>> installedKbds = PackageProcessor.processKMP(packagePath, true);
installedPackageKeyboards = PackageProcessor.processKMP(packagePath, true);
// Do the notifications!
boolean success = installedKbds.size() == 0;
boolean success = installedPackageKeyboards.size() != 0;
if(success) {
notifyPackageInstallListeners(KeyboardEventHandler.EventType.PACKAGE_INSTALLED, installedKbds, 1);
notifyPackageInstallListeners(KeyboardEventHandler.EventType.PACKAGE_INSTALLED, installedPackageKeyboards, 1);
} else {
Log.d("KMEA", "Forced install of a package returned no updated keyboards!");
}
finishTask(success ? -2 : 1);
} catch (Exception e) {
Log.e("Package installation", "Error: " + e);
@ -313,9 +313,10 @@ public class KMKeyboardDownloaderActivity extends Activity {
pendingDialogSpec.show();
} else if(this.installedPackageKeyboards != null) {
notifyPackageInstallListeners(KeyboardEventHandler.EventType.PACKAGE_INSTALLED, this.installedPackageKeyboards, 1);
finishTask(result);
} else {
// Normal scenario after package has been downloaded and installed
finishTask(result);
// Normal scenario after package has been downloaded and installed
finishTask(result);
}
}
@ -340,7 +341,9 @@ public class KMKeyboardDownloaderActivity extends Activity {
}
((Activity) context).finish();
notifyListeners(KeyboardEventHandler.EventType.KEYBOARD_DOWNLOAD_FINISHED, result);
if(this.installedPackageKeyboards == null) {
notifyListeners(KeyboardEventHandler.EventType.KEYBOARD_DOWNLOAD_FINISHED, result);
}
}
private void dismissProgressDialog() {
@ -367,6 +370,8 @@ public class KMKeyboardDownloaderActivity extends Activity {
protected int downloadKMPKeyboard(String remoteUrl) throws Exception {
int ret = -2;
Log.d("KMEA", "Downloading .kmp from " + remoteUrl);
// Use the KMP filename for the package ID.
// Expect last 4 characters in filename to end in ".kmp"
String sourceKMPFilename = FileUtils.getFilename(remoteUrl);
@ -388,6 +393,8 @@ public class KMKeyboardDownloaderActivity extends Activity {
return ret;
}
String version = PackageProcessor.getPackageVersion(kmpFile, true);
List<Map<String, String>> installedKbds = PackageProcessor.processKMP(kmpFile);
if (installedKbds.size() == 0) {
// Install probably failed - shouldn't have an empty package.

View file

@ -2,6 +2,7 @@ package com.tavultesoft.kmea.packages;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import com.tavultesoft.kmea.KMManager;
import com.tavultesoft.kmea.JSONParser;
@ -91,8 +92,12 @@ public class PackageProcessor {
static JSONObject loadPackageInfo(File packagePath) {
File infoFile = new File(packagePath, "kmp.json");
JSONParser parser = new JSONParser();
return parser.getJSONObjectFromFile(infoFile);
if(infoFile.exists()) {
JSONParser parser = new JSONParser();
return parser.getJSONObjectFromFile(infoFile);
} else {
return null;
}
}
// Call this once per each entry of the JSON `keyboards` array, then concatenate the resulting arrays for a full list.
@ -147,7 +152,11 @@ public class PackageProcessor {
* @throws JSONException
*/
public static String getPackageVersion(JSONObject json) throws JSONException {
return json.getJSONObject("system").getString("fileVersion");
if(json == null) {
return null;
} else {
return json.getJSONObject("info").getJSONObject("version").getString("description");
}
}
public static String getPackageVersion(File kmpPath, boolean installed) throws IOException, JSONException {
@ -303,14 +312,12 @@ public class PackageProcessor {
if(KMManager.isReservedNamespace(getPackageName(path))) {
return new ArrayList<>();
}
File tempPath;
if(!preExtracted) {
tempPath = unzipKMP(path);
} else {
tempPath = constructPath(path, true);
}
JSONObject newInfoJSON = loadPackageInfo(tempPath);
String packageId = getPackageName(path);

View file

@ -52,7 +52,7 @@ public class PackageProcessorTest {
File tempPkgAlt = PackageProcessor.unzipKMP(TEST_GFF_KMP_FILE_ALT);
JSONObject json = PackageProcessor.loadPackageInfo(tempPkgAlt);
json.getJSONObject("system").put("fileVersion", "8.0"); // Make it look newer!
json.getJSONObject("info").getJSONObject("version").put("description", "1.5"); // Make it look newer!
// Write out the JSON file.
File jsonFile = new File(tempPkgAlt, "kmp.json");
@ -181,13 +181,13 @@ public class PackageProcessorTest {
installedKbds = PackageProcessor.processKMP(TEST_GFF_KMP_FILE);
version = PackageProcessor.getPackageVersion(PackageProcessor.loadPackageInfo(installedKMP));
Assert.assertEquals(TEST_GFF_KBD_COUNT, installedKbds.size());
Assert.assertEquals("7.0", version);
Assert.assertEquals("1.4", version);
createAlternateKMP();
installedKbds = PackageProcessor.processKMP(TEST_GFF_KMP_FILE_ALT, false, true);
version = PackageProcessor.getPackageVersion(PackageProcessor.loadPackageInfo(installedKMP));
Assert.assertEquals(TEST_GFF_KBD_COUNT, installedKbds.size());
Assert.assertEquals("8.0", version);
Assert.assertEquals("1.5", version);
}
@Test
@ -200,18 +200,18 @@ public class PackageProcessorTest {
installedKbds = PackageProcessor.processKMP(TEST_GFF_KMP_FILE_ALT, false, true);
version = PackageProcessor.getPackageVersion(PackageProcessor.loadPackageInfo(installedKMP));
Assert.assertEquals(TEST_GFF_KBD_COUNT, installedKbds.size());
Assert.assertEquals("8.0", version);
Assert.assertEquals("1.5", version);
// Blocked downgrade attempt.
installedKbds = PackageProcessor.processKMP(TEST_GFF_KMP_FILE, false);
version = PackageProcessor.getPackageVersion(PackageProcessor.loadPackageInfo(installedKMP));
Assert.assertEquals(0, installedKbds.size());
Assert.assertEquals("8.0", version);
Assert.assertEquals("1.5", version);
installedKbds = PackageProcessor.processKMP(TEST_GFF_KMP_FILE, true);
version = PackageProcessor.getPackageVersion(PackageProcessor.loadPackageInfo(installedKMP));
Assert.assertEquals(TEST_GFF_KBD_COUNT, installedKbds.size());
Assert.assertEquals("7.0", version);
Assert.assertEquals("1.4", version);
}
@Test
@ -248,7 +248,7 @@ public class PackageProcessorTest {
createAlternateKMP();
PackageProcessor.processKMP(TEST_GFF_KMP_FILE_ALT, false, true);
Assert.assertEquals("8.0", PackageProcessor.getPackageVersion(TEST_GFF_KMP_FILE, true));
Assert.assertEquals("7.0", PackageProcessor.getPackageVersion(TEST_GFF_KMP_FILE, false));
Assert.assertEquals("1.5", PackageProcessor.getPackageVersion(TEST_GFF_KMP_FILE, true));
Assert.assertEquals("1.4", PackageProcessor.getPackageVersion(TEST_GFF_KMP_FILE, false));
}
}