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

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

@ -103,7 +103,13 @@ this.WebappManager = {
sendMessageToJava({ sendMessageToJava({
type: "Webapps:InstallApk", type: "Webapps:InstallApk",
filePath: filePath, 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)); }, }).bind(this)); },
@ -493,7 +499,7 @@ this.WebappManager = {
sendMessageToJava({ sendMessageToJava({
type: "Webapps:InstallApk", type: "Webapps:InstallApk",
filePath: apk.filePath, filePath: apk.filePath,
data: JSON.stringify(msg), data: msg,
}); });
} }
} else { } else {