Closed Bug 560664 Opened 12 years ago Closed 12 years ago

Need mechanism to launch with command line args

Categories

(Core :: Widget: Android, defect)

All
Android
defect
Not set
blocker

Tracking

()

RESOLVED FIXED

People

(Reporter: bmoss, Assigned: mwu)

Details

We need to write the code which will launch fennec on android and accept command line arguments.
Specifically, we need to do this for testing.  That means we have the following stipulations:

= Reftest class =
* Drop the reftest.jar chrome pieces and the reftest-cmdline.js into the proper locations on android, have the browser self-register that extension.
* call firefox with the newly provided command line like so: firefox.app -profile /my/test/profile -reftest http://remotereftestAddress:port/reftest/layout/reftests/reftest.list

= Mochitest class =
* We generally use --ENVIRON variables for things like NO_EM_RESTART and we specify those on the firefox command line for mochitest when we run this way.
* firefox.app --environ:NO_EM_RESTART=1 -profile /my/test/profile http://mochi.test:8888/tests/content/base/test?logFile=%2Ftests%2Flogfile.log&close-when-done=1&autorun=1

Those are done by memory, so I'm not going to vouch on their absolute correctness, but that is the basic format of the URLs that we launch firefox & fennec with when we run these classes of tests.

In general:
* <appanme> <url>
* <appname> <profileDirectory> <url>
* <appname> <environment settings> <profileDirectory> <url>
* <appname> <profileDirectory> <cmdline handler from extension> <cmdline specific to that handler>

And we'll need a way to register an extension.  Given the file permissions on Android, we may have to provide a specific API for this and have the browser write the extension components into the proper locations.

And in case it isn't clear why we set this to "Blocker", all further test infrastructure work on Android is at a standstill until this is resolved.
The following android java code will launch the native browser: When sArgs[0] is "com.android.browser" and sArgs[1] is set to the desired URL.

public String StartJavaPrg(String [] sArgs)
	{
	String sRet = "";

	Intent prgIntent = new Intent();
	prgIntent.setPackage(sArgs[0]);
	prgIntent.setAction(Intent.ACTION_VIEW);

	if (sArgs.length == 2)
		prgIntent.setData(Uri.parse(sArgs[1]));
	else
		prgIntent.setData(Uri.parse("about:blank"));
		
	try 
		{
		SUTAgentAndroid.me.startActivity(prgIntent);
		}
	catch(ActivityNotFoundException anf)
		{
		anf.printStackTrace();
		}
	return (sRet);
	}
(In reply to comment #1)
> In general:
> * <appanme> <url>
> * <appname> <profileDirectory> <url>
> * <appname> <environment settings> <profileDirectory> <url>
> * <appname> <profileDirectory> <cmdline handler from extension> <cmdline
> specific to that handler>
> 
There's no direct way to launch fennec from the command line but there is a program which will do that for us. Unfortunately, there is currently no way to pass command line arguments. I'll investigate supporting that.

> And we'll need a way to register an extension.  Given the file permissions on
> Android, we may have to provide a specific API for this and have the browser
> write the extension components into the proper locations.
> 
That shouldn't be a problem on rooted devices.
what bmoss is doing here is the equivalent of what we do with the am utility. We should be able to pick up the data he's adding the intent.
Assignee: nobody → mwu
Ok. I added some support for command line arguments - http://hg.mozilla.org/users/vladimir_mozilla.com/mozilla-droid/rev/19c7b5770384

Here's an example of how to use it.

am start -n org.mozilla.fennec/org.mozilla.fennec.fennec --es args "-jsconsole"

The arguments go in the quotes where -jsconsole is.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Note that this code isn't particularly smart. Spaces can't be escaped in the arguments. Let me know if you really need that.
tracking-fennec: ? → ---
Hardware: ARM → All
Version: 1.9.2 Branch → Trunk
You need to log in before you can comment on or make changes to this bug.