Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko.webapp;
8 import android.app.Activity;
9 import android.content.Intent;
10 import android.os.Bundle;
11 import android.util.Log;
13 public class Dispatcher extends Activity {
14 private static final String LOGTAG = "GeckoWebappDispatcher";
16 @Override
17 protected void onCreate(Bundle bundle) {
18 super.onCreate(bundle);
20 Allocator allocator = Allocator.getInstance(getApplicationContext());
22 if (bundle == null) {
23 bundle = getIntent().getExtras();
24 }
26 if (bundle == null) {
27 Log.e(LOGTAG, "Passed intent data missing.");
28 return;
29 }
31 String packageName = bundle.getString("packageName");
33 if (packageName == null) {
34 Log.e(LOGTAG, "Package name data missing.");
35 return;
36 }
38 int index = allocator.getIndexForApp(packageName);
39 boolean isInstalled = index >= 0;
40 if (!isInstalled) {
41 index = allocator.findOrAllocatePackage(packageName);
42 }
44 // Copy the intent, without interfering with it.
45 Intent intent = new Intent(getIntent());
47 // Only change it's destination.
48 intent.setClassName(getApplicationContext(), getPackageName() + ".WebApps$WebApp" + index);
50 // If and only if we haven't seen this before.
51 intent.putExtra("isInstalled", isInstalled);
53 startActivity(intent);
54 }
55 }