提交 25fc0613 编写于 作者: A Adam Barth

SkyDemo should use explicit intents

This CL switches SkyDemo over to using explicit intents for deciding which Sky
apps to run. This change lets us get rid of the hacky "sky" URI scheme.
Instead, we use normal URLs but we require the sender of the intent to be
explicit in directing the VIEW intent to us.

TBR=eseidel@google.com

Review URL: https://codereview.chromium.org/1221123003.
上级 ec1f3271
......@@ -15,11 +15,6 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sky" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
</manifest>
......@@ -5,8 +5,6 @@
package org.domokit.sky.demo;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import org.domokit.sky.shell.SkyActivity;
......@@ -14,28 +12,17 @@ import org.domokit.sky.shell.SkyActivity;
* Main activity for SkyDemo.
*/
public class SkyDemoActivity extends SkyActivity {
private static final String DEFAULT_URL = "https://domokit.github.io/home.dart";
/**
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "https://domokit.github.io/home.dart";
protected void onSkyReady() {
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri skyUri = intent.getData();
Uri httpsUri = skyUri.buildUpon().scheme("https").build();
// This is a hack to disable https for local testing.
// getHost may be null if we're passed a non-normalized url.
if (skyUri.getHost() != null
&& skyUri.getHost().equals("localhost")) {
httpsUri = skyUri.buildUpon().scheme("http").build();
}
url = httpsUri.toString();
}
String action = intent.getAction();
loadUrl(url);
if (Intent.ACTION_MAIN.equals(action)) {
loadUrl(DEFAULT_URL);
} else if (Intent.ACTION_VIEW.equals(action)) {
loadUrl(intent.getDataString());
}
}
}
......@@ -21,11 +21,14 @@ import 'package:sky/widgets/tool_bar.dart';
void launch(String relativeUrl) {
Uri url = Uri.base.resolve(relativeUrl);
url = url.replace(scheme: 'sky');
ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound();
ComponentName component = new ComponentName()
..packageName = 'org.domokit.sky.demo'
..className = 'org.domokit.sky.demo.SkyDemoActivity';
Intent intent = new Intent()
..action = 'android.intent.action.VIEW'
..component = component
..url = url.toString();
shell.requestService(null, activityManager);
activityManager.ptr.startActivity(intent);
......
......@@ -4,9 +4,15 @@
module intents;
struct ComponentName {
string package_name;
string class_name;
};
struct Intent {
string action;
string url;
ComponentName? component;
};
// TODO(abarth): This interface seems very specific to Android. Do we want to
......
......@@ -11,6 +11,7 @@ import android.util.Log;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojom.intents.ActivityManager;
import org.chromium.mojom.intents.ComponentName;
import org.chromium.mojom.intents.Intent;
/**
......@@ -34,6 +35,14 @@ public class ActivityManagerImpl implements ActivityManager {
public void startActivity(Intent intent) {
final android.content.Intent androidIntent = new android.content.Intent(
intent.action, Uri.parse(intent.url));
if (intent.component != null) {
ComponentName component = intent.component;
android.content.ComponentName androidComponent =
new android.content.ComponentName(component.packageName, component.className);
androidIntent.setComponent(androidComponent);
}
androidIntent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
try {
......
......@@ -41,7 +41,7 @@ public class SkyActivity extends Activity {
setContentView(mView);
mTracingController = new TracingController(this);
loadSnapshotIfAvailable();
onSkyReady();
}
/**
......@@ -65,7 +65,10 @@ public class SkyActivity extends Activity {
super.onBackPressed();
}
private void loadSnapshotIfAvailable() {
/**
* Override this function to customize startup behavior.
*/
protected void onSkyReady() {
File dataDir = new File(PathUtils.getDataDirectory(this));
File snapshot = new File(dataDir, SkyApplication.SNAPSHOT);
if (snapshot.exists()) {
......
......@@ -26,11 +26,12 @@ SRC_ROOT = os.path.dirname(SKY_ROOT)
GDB_PORT = 8888
SKY_SERVER_PORT = 9888
OBSERVATORY_PORT = 8181
DEFAULT_URL = "sky://domokit.github.io/home.dart"
DEFAULT_URL = "https://domokit.github.io/home.dart"
APK_NAME = 'SkyDemo.apk'
ADB_PATH = os.path.join(SRC_ROOT,
'third_party/android_tools/sdk/platform-tools/adb')
ANDROID_PACKAGE = "org.domokit.sky.demo"
ANDROID_COMPONENT = '%s/%s.SkyDemoActivity' % (ANDROID_PACKAGE, ANDROID_PACKAGE)
SHA1_PATH = '/sdcard/%s/%s.sha1' % (ANDROID_PACKAGE, APK_NAME)
PID_FILE_PATH = "/tmp/skydemo.pids"
......@@ -104,12 +105,6 @@ class Pids(object):
logging.warn('Failed to write pid file: %s' % path)
def _convert_to_sky_url(url):
parts = urlparse.urlsplit(url)
parts = parts._replace(scheme='sky')
return parts.geturl()
# A free function for possible future sharing with a 'load' command.
def _url_from_args(args, pids):
if urlparse.urlparse(args.url_or_path).scheme:
......@@ -117,9 +112,8 @@ def _url_from_args(args, pids):
# The load happens on the remote device, use the remote port.
remote_sky_server_port = pids.get('remote_sky_server_port',
pids['sky_server_port'])
url = SkyServer.url_for_path(remote_sky_server_port,
return SkyServer.url_for_path(remote_sky_server_port,
pids['sky_server_root'], args.url_or_path)
return _convert_to_sky_url(url)
def dev_packages_root(build_dir):
......@@ -235,11 +229,11 @@ class StartSky(object):
])
pids['remote_sky_server_port'] = sky_server.port
subprocess.check_call([ADB_PATH, 'shell',
'am', 'start',
'-a', 'android.intent.action.VIEW',
'-d', _url_from_args(args, pids)])
'-d', _url_from_args(args, pids),
ANDROID_COMPONENT])
if not args.gdb:
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册