Bug 957067 - Stop verifying manifestUrl in installApk. r=wesj

This commit is contained in:
Martyn Haigh 2014-06-03 09:19:00 -04:00
Родитель adfd373291
Коммит 7ff4704ab2
2 изменённых файлов: 32 добавлений и 27 удалений

Просмотреть файл

@ -8,12 +8,15 @@ package org.mozilla.gecko.webapp;
import org.mozilla.gecko.ActivityHandlerHelper;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.favicons.decoders.FaviconDecoder;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.NativeEventListener;
import org.mozilla.gecko.util.NativeJSObject;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.WebappAllocator;
@ -30,15 +33,15 @@ import android.net.Uri;
import android.util.Log;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class EventListener implements GeckoEventListener {
public class EventListener implements NativeEventListener {
private static final String LOGTAG = "GeckoWebappEventListener";
@ -63,10 +66,10 @@ public class EventListener implements GeckoEventListener {
}
@Override
public void handleMessage(String event, JSONObject message) {
public void handleMessage(String event, NativeJSObject message, EventCallback callback) {
try {
if (AppConstants.MOZ_ANDROID_SYNTHAPKS && event.equals("Webapps:InstallApk")) {
installApk(GeckoAppShell.getGeckoInterface().getActivity(), message.getString("filePath"), message.getString("data"));
installApk(GeckoAppShell.getGeckoInterface().getActivity(), message, callback);
} else if (event.equals("Webapps:Postinstall")) {
if (AppConstants.MOZ_ANDROID_SYNTHAPKS) {
postInstallWebapp(message.getString("apkPackageName"), message.getString("origin"));
@ -94,12 +97,12 @@ public class EventListener implements GeckoEventListener {
JSONObject obj = new JSONObject();
obj.put("profile", preInstallWebapp(name, manifestURL, origin).toString());
EventDispatcher.sendResponse(message, obj);
callback.sendSuccess(obj);
} else if (event.equals("Webapps:GetApkVersions")) {
JSONObject obj = new JSONObject();
obj.put("versions", getApkVersions(GeckoAppShell.getGeckoInterface().getActivity(),
message.getJSONArray("packageNames")));
EventDispatcher.sendResponse(message, obj);
message.getStringArray("packageNames")));
callback.sendSuccess(obj);
}
} catch (Exception e) {
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
@ -180,25 +183,27 @@ public class EventListener implements GeckoEventListener {
}
}
public static void installApk(final Activity context, String filePath, String data) {
// This is the data that mozApps.install sent to Webapps.jsm.
JSONObject argsObj = null;
public static void installApk(final Activity context, NativeJSObject message, EventCallback callback) {
final JSONObject messageData;
// We get the manifest url out of javascript here so we can use it as a checksum
// in a minute, when a package has been installed.
String manifestUrl = null;
String filePath = null;
try {
argsObj = new JSONObject(data);
manifestUrl = argsObj.getJSONObject("app").getString("manifestURL");
filePath = message.getString("filePath");
messageData = new JSONObject(message.getObject("data").toString());
manifestUrl = messageData.getJSONObject("app").getString("manifestURL");
} catch (JSONException e) {
Log.e(LOGTAG, "can't get manifest URL from JSON data", e);
// TODO: propagate the error back to the mozApps.install caller.
Log.wtf(LOGTAG, "Error getting file path and data", e);
callback.sendError("Error getting file path and data: " + e.toString());
return;
}
// We will check the manifestUrl from the one in the APK.
// Thus, we can have a one-to-one mapping of apk to receiver.
final InstallListener receiver = new InstallListener(manifestUrl, argsObj);
final InstallListener receiver = new InstallListener(manifestUrl, messageData);
// Listen for packages being installed.
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
@ -208,7 +213,7 @@ public class EventListener implements GeckoEventListener {
File file = new File(filePath);
if (!file.exists()) {
Log.wtf(LOGTAG, "APK file doesn't exist at path " + filePath);
// TODO: propagate the error back to the mozApps.install caller.
callback.sendError("APK file doesn't exist at path " + filePath);
return;
}
@ -239,15 +244,9 @@ public class EventListener implements GeckoEventListener {
private static final int DEFAULT_VERSION_CODE = -1;
public static JSONObject getApkVersions(Activity context, JSONArray packageNames) {
public static JSONObject getApkVersions(Activity context, String[] packageNames) {
Set<String> packageNameSet = new HashSet<String>();
for (int i = 0; i < packageNames.length(); i++) {
try {
packageNameSet.add(packageNames.getString(i));
} catch (JSONException e) {
Log.w(LOGTAG, "exception populating settings item", e);
}
}
packageNameSet.addAll(Arrays.asList(packageNames));
final PackageManager pm = context.getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);

Просмотреть файл

@ -103,7 +103,13 @@ this.WebappManager = {
sendMessageToJava({
type: "Webapps:InstallApk",
filePath: filePath,
data: JSON.stringify(aMessage),
data: aMessage,
}, (data, error) => {
if (!!error) {
aMessage.error = error;
aMessageManager.sendAsyncMessage("Webapps:Install:Return:KO", aMessage);
debug("error downloading APK: " + error);
}
});
}).bind(this)); },
@ -493,7 +499,7 @@ this.WebappManager = {
sendMessageToJava({
type: "Webapps:InstallApk",
filePath: apk.filePath,
data: JSON.stringify(msg),
data: msg,
});
}
} else {