Sunday, April 11, 2010

Now it is easy to distribute DroidScript scripts

I have uploaded a new version of DroidScript that has a feature for easily distributing DroidScript scripts. With a new pair of tags, you can publish scripts on any web page (like this blog) and open and run them from the DroidScript app on your Android device.

It is as easy as opening a web page, and that said, this is also an easy way of distributing malicious code.

BE VERY CAREFUL WITH WHAT YOU DOWNLOAD!

I will say this again, because it is important:

BE VERY CAREFUL WITH WHAT YOU DOWNLOAD!

At present, DroidScript has the following permissions:

android.permission.INTERNET
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.CAMERA
android.permission.ACCESS_FINE_LOCATION

So a script could erase your files, mess with your camera, and so on.

That said, I think this is a really cool feature, and it shows how powerful dynamic languages are when it comes to ease of distributing and running programs. And with improved security handling, the risks of distributing scripts could be reduced.

I do like the openness of the web, and native apps are sadly not open for inspection and modification by the user. With DroidScript, the script is always available for preview and modification in the editor on the device before you decide to run it. Still, it is a big security risk to be open, but so much more fun. It is like life, a life without risk taking is no life.

DroidScript is an ongoing experiment, and it is possible to package a program in alternative ways. You could, for instance, embed DroidScript in a native Android app, store JavaScript files in the application space (as resources or files), and no one would be able to tamper with the scripts or download new scripts, and the user would not even notice that the app is written in JavaScript.

Now for an example:
DROIDSCRIPT_BEGIN
function onCreate(bubble)
{
    var Button = Packages.android.widget.Button;
    var Color = Packages.android.graphics.Color;
    var Typeface = Packages.android.graphics.Typeface;

    var numberOfClicks = 0;
    var font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
    var button = new Button(Activity);
    button.setText("Hello World!");
    button.setTypeface(font);
    button.setTextSize(26);
    button.setBackgroundColor(Color.rgb(0, 0, 64));
    button.setTextColor(Color.rgb(255, 255, 255));
    button.setOnClickListener(function () {
        ++numberOfClicks;
        button.setText(
            "You Clicked Me" +
            (1 == numberOfClicks ? "!" : 
                " " + numberOfClicks + " Times!")); })
    Activity.setContentView(button);
}
DROIDSCRIPT_END
How to run the above program:
  • Download the latest DroidScript app (instructions are found here
  • Start the app and select "Open script" in the options menu
  • Enter the short url to this page: http://bit.ly/9kFqEi
  • Then press "Run Activity"
(The short url is quicker to type on the device)

DroidScript will find the code between the tags and filter out the rest of the web page. This makes it very easy to publish scripts embedded on blogs and other web pages. You can of course also put your script in a plain text file and upload that to the web, then you will not need the begin and end tags.

Since a script can open images over the internet, and open other scripts, it is possible to create truly dynamic applications that have the capabilities of native Android applications and the dynamic flow and instant access of web pages.

0 comments:

Post a Comment