Verified Commit 6cc1290e authored by FabioWidmer's avatar FabioWidmer
Browse files

Update to v1.0.1

parent 231e51ba
{
"name": "@ablota/store-cordova-plugin",
"version": "1.0.0",
"version": "1.0.1",
"description": "Cordova Plugin is an extension for the Ablota Store and offers several native implementations.",
"keywords": [
"ablota",
......
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://apache.org/cordova/ns/plugins/1.0" id="ablota-store-cordova-plugin" version="1.0.0">
<plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://apache.org/cordova/ns/plugins/1.0" id="ablota-store-cordova-plugin" version="1.0.1">
<engines>
<engine name="cordova" version=">=10.0.0"/>
<engine name="cordova-android" version=">=9.0.0"/>
......@@ -74,7 +74,7 @@
</receiver>
</config-file>
<config-file parent="/manifest/application/activity" target="AndroidManifest.xml">
<intent-filter>
<intent-filter android:autoVerify="false">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
......@@ -84,9 +84,8 @@
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
<data android:scheme="http" android:host="store.ablota.com"/>
<data android:scheme="https"/>
<data android:host="store.ablota.com"/>
</intent-filter>
<intent-filter android:autoVerify="false">
<action android:name="android.intent.action.VIEW"/>
......
......@@ -14,8 +14,8 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
......@@ -99,54 +100,56 @@ public class FilePlugin extends CordovaPlugin {
query.setFilterById(requestId);
Cursor cursor = downloadManager.query(query);
cursor.moveToFirst();
if(cursor.moveToFirst()) {
int statusNew = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
int statusNew = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
if(statusNew == DownloadManager.STATUS_SUCCESSFUL) {
downloading = false;
if(statusNew == DownloadManager.STATUS_SUCCESSFUL) {
downloading = false;
JSONObject data = Helpers.callbackData(Helpers.STATUS_SUCCESS);
data.put("localUri", cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)));
data.put("contentUri", downloadManager.getUriForDownloadedFile(requestId).toString());
JSONObject data = Helpers.callbackData(Helpers.STATUS_SUCCESS);
data.put("localUri", cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)));
data.put("contentUri", downloadManager.getUriForDownloadedFile(requestId).toString());
callbackContext.success(data);
} else if(statusNew == DownloadManager.STATUS_RUNNING) {
int bytesCurrent = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
int bytesTotal = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
callbackContext.success(data);
} else if(statusNew == DownloadManager.STATUS_RUNNING) {
int bytesCurrent = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
int bytesTotal = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
if(bytesCurrent > 0 && bytesTotal > 0) {
int progressNew = (int) ((bytesCurrent * 100L) / bytesTotal);
if(bytesCurrent > 0 && bytesTotal > 0) {
int progressNew = (int) ((bytesCurrent * 100L) / bytesTotal);
if(progress != progressNew) {
progress = progressNew;
if(progress != progressNew) {
progress = progressNew;
JSONObject data = Helpers.callbackData(Helpers.STATUS_UPDATE);
data.put("progress", progress);
data.put("bytesCurrent", bytesCurrent);
data.put("bytesTotal", bytesTotal);
JSONObject data = Helpers.callbackData(Helpers.STATUS_UPDATE);
data.put("progress", progress);
data.put("bytesCurrent", bytesCurrent);
data.put("bytesTotal", bytesTotal);
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data);
pluginResult.setKeepCallback(true);
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
callbackContext.sendPluginResult(pluginResult);
}
}
}
} else if(statusNew == DownloadManager.STATUS_PAUSED && status != statusNew) {
int code = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
} else if(statusNew == DownloadManager.STATUS_PAUSED && status != statusNew) {
int code = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, Helpers.callbackData(Helpers.STATUS_UPDATE, code, null));
pluginResult.setKeepCallback(true);
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, Helpers.callbackData(Helpers.STATUS_UPDATE, code, null));
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
} else if(statusNew == DownloadManager.STATUS_FAILED) {
downloading = false;
int code = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
callbackContext.sendPluginResult(pluginResult);
} else if(statusNew == DownloadManager.STATUS_FAILED) {
downloading = false;
int code = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
callbackContext.success(Helpers.callbackData(Helpers.STATUS_FAILURE, code, null));
}
callbackContext.success(Helpers.callbackData(Helpers.STATUS_FAILURE, code, null));
status = statusNew;
}
status = statusNew;
cursor.close();
}
} else {
URL connectionUrl = new URL(url);
......@@ -171,7 +174,7 @@ public class FilePlugin extends CordovaPlugin {
int bytesTotal = httpConnection.getContentLength();
int progress = -1;
try(BufferedInputStream in = new BufferedInputStream(httpConnection.getInputStream()); FileOutputStream out = new FileOutputStream(destination)) {
try(InputStream in = new BufferedInputStream(httpConnection.getInputStream()); OutputStream out = new BufferedOutputStream(new FileOutputStream(destination))) {
int n;
byte[] buffer = new byte[16384];
......@@ -245,7 +248,7 @@ public class FilePlugin extends CordovaPlugin {
if(!dir.isDirectory() && !dir.mkdirs()) throw new FileNotFoundException("Failed to ensure directory: " + dir.getAbsolutePath());
if(zipEntry.isDirectory()) continue;
try(FileOutputStream fileOutputStream = new FileOutputStream(file)) {
try(OutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(file))) {
while((n = zipInputStream.read(buffer)) >= 0) {
bytesCurrent += n;
......@@ -287,7 +290,7 @@ public class FilePlugin extends CordovaPlugin {
JarEntry indexEntry = (JarEntry) jarFile.getEntry("index-v1.json");
StringBuilder indexContent = new StringBuilder();
try(InputStream indexInputStream = jarFile.getInputStream(indexEntry); BufferedReader reader = new BufferedReader(new InputStreamReader(indexInputStream))) {
try(InputStream indexInputStream = new BufferedInputStream(jarFile.getInputStream(indexEntry)); BufferedReader reader = new BufferedReader(new InputStreamReader(indexInputStream))) {
String line;
while((line = reader.readLine()) != null) {
......@@ -324,7 +327,7 @@ public class FilePlugin extends CordovaPlugin {
try {
File content = new File(new URI(Uri.parse(file).toString()));
try(InputStream in = new FileInputStream(content)) {
try(InputStream in = new BufferedInputStream(new FileInputStream(content))) {
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] buffer = new byte[16384];
int n;
......
......@@ -24,7 +24,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
......@@ -32,6 +32,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
......@@ -257,7 +258,7 @@ public class PackagePlugin extends CordovaPlugin {
private void addApkToInstallSession(String file, String hash, PackageInstaller.Session session) throws IOException, URISyntaxException, NoSuchAlgorithmException, RuntimeException {
File apk = new File(new URI(Uri.parse(file).toString()));
try(OutputStream out = session.openWrite(apk.getName(), 0, apk.length()); InputStream in = new FileInputStream(apk)) {
try(OutputStream out = session.openWrite(apk.getName(), 0, apk.length()); InputStream in = new BufferedInputStream(new FileInputStream(apk))) {
byte[] buffer = new byte[16384];
int n;
......@@ -268,15 +269,16 @@ public class PackagePlugin extends CordovaPlugin {
session.fsync(out);
}
try(InputStream in = session.openRead(apk.getName()); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
try(InputStream in = new BufferedInputStream(session.openRead(apk.getName()))) {
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] buffer = new byte[16384];
int n;
while((n = in.read(buffer)) >= 0) {
out.write(buffer, 0, n);
md.update(buffer, 0, n);
}
if(!hash.toLowerCase().equals(Helpers.byte2Hex(Helpers.sha256(out.toByteArray())).toLowerCase())) {
if(!hash.toLowerCase().equals(Helpers.byte2Hex(md.digest()).toLowerCase())) {
throw new RuntimeException("Exception while validating package.");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment