Author Topic: ScriptBasic for Android  (Read 75044 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
ScriptBasic for Android
« on: April 07, 2012, 03:13:39 PM »
Armando Rivera and our new ScriptBasic developer Steve Dover were able to get scriba (ScriptBasic command line interpreter) working on Google Android Linux.



If you would like to run scriba on a unrooted device, you need to install it in the /data/data/jackpal.androidterm directory (or the directory your terminal app uses) to make it executable and read/write files.

Quote
It would be nice if you could put native binaries directly onto the SD card (either external or built-in) but you can't. Well, you can — but you won't be able to set execute permissions on them, which means they won't run. The SD card is mounted in such a way as to prohibit setting 'x' permissions. You can set execute permissions in the app storage area — that part of the filesystem that is rooted at /data/data. On an unrooted device you won't be able to create files just anywhere in this directory, because each app has its own security credentials — effectively each app runs as a different user. Only one directory under /data/data will be writeable by a specific app. Once you've found that directory, you can copy a binary into it, and run it at the terminal emulator prompt.

Quote
The results show that native C applications can be up to 30 times as fast as an identical algorithm running in Dalvik VM. Java applications can become a speed-up of up to 10 times if utilizing JNI.

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #1 on: April 07, 2012, 08:01:12 PM »
Quote from: AIR
If you're using the Android Terminal app,  I think you should be able to create a directory via adb called /data/local/bin on a non-rooted device.  Then use adb to copy scriba there, and when you launch the Terminal app, scriba will be in the path that the app sets up.

I've managed to embed scriba within the Term.apk file itself, but it needs to be extracted from the apk so that the shell can find it, which I haven't worked out yet (building Win7 systems for a client this weekend.  Yuck.  sysprep to the rescue.)

A.

Updated Instructions

Code: [Select]
adb shell
mkdir /data/local/bin
exit
adb push scriba /data/local/bin/
adb push hello4.bas /sdcard

adb shell
cd /data/local/bin
ls -l (check permissions)

if needed, chmod 755 scriba

Then in Term app: scriba /sdcard/hello4.bas
« Last Edit: April 28, 2012, 09:26:50 PM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #2 on: May 03, 2012, 01:33:31 PM »
The phone I have been waiting for.

   

Samsung Galaxy S III

quad core 1.4 GHz Exynos CPU

Detailed Review
« Last Edit: May 05, 2012, 11:43:20 PM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #3 on: May 06, 2012, 09:01:14 PM »
I was able to get ScriptBasic for Android to display an Android GUI message box (makeToast) from a SB script. This is using the SL4A (Scripting Layer for Android)

Code: [Select]
OPEN "localhost:56098" FOR SOCKET AS #1
PRINT #1,"{id:1,method:makeToast,params:[\"ScriptBasic\"]}"


Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #4 on: May 08, 2012, 12:29:06 AM »
I was using SL4A r4 to run my initial tests. I found that I had to look at the properties of the RPC server to get the port it assigned. This was a PITA but this is proof of concept so I didn't mind the extra step. I recently installed SL4A r5 and it allows setting a default port for the RPC server.

What's new in SL4A - Scripting Layer for Android r5:
  • MediaRecorderFacade: If you record a video file with extension mp4 or 3gp it uses the appropriate format with the more common h264 codec.
  • SensorManagerFacade: Orientation threshold events were causing excessive entries into the Event Queue, so I have limited entries to threshold crossing both ways.
  • New media recorder option: recorderStartVideo allows you to specify video size.
  • Improved error trapping in the activityForResult functions, and now you can specify mimetype without data.
  • Changed eventWaitFor to check for events already in queue.
  • Support for full screen user interface
  • Ability to set server port to a known value (Preferences-->General-->Server Port)
  • Editor: goto line number, and ability to turn of autocomplete, set no wrap, find and replace, auto-indent
  • Added "inputType" parameter to dialogCreateInput
  • Better support for "unsupported" interpreters
  • Assorted other fixes and tweaks.

Android API
« Last Edit: May 08, 2012, 12:59:33 AM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #5 on: May 12, 2012, 10:46:26 PM »
Here is an example of a request / response call to the SL4A RPC server. This is opening a SB socket and sending a JSON packet to the RPC scripting server. (see attached screenshot)

The Androids API (scripting version) is fairly extensive. I would be willing to help build this interface if others contribute. I'll post a few high level functions to get the ball rolling and see what happens. My initial goal was to create a proof of concept and see if others saw promise or not. If there is no interest by others then I'll return to my IUP project and revisit this again at later time.
« Last Edit: May 13, 2012, 09:11:23 AM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #6 on: May 13, 2012, 10:25:12 AM »
I'm playing around with a JSON response parser that creates a SB associative array. This is my first stab at it and may find a better way.

Code: [Select]
r = """{"error":null,"id":1,"result":"gsm"}"""
r = MID(r,2)
r = LEFT(r,LEN(r) - 1)
r = REPLACE(r, "\"", "")
SPLITA r BY "," TO t
FOR x = 0 to UBOUND(t)
  a{LEFT(t[x],INSTR(t[x],":")-1)} = MID(t[x],INSTR(t[x],":")+1)
NEXT

PRINT a{"error"},"\n"
PRINT a{"id"},"\n"
PRINT a{"result"},"\n"

jrs@laptop:~/sb/test$ scriba json_in.sb
null
1
gsm
jrs@laptop:~/sb/test$

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #7 on: May 13, 2012, 12:11:22 PM »
The following Facade's are available for ownership. Please let us know which Facade you will be working on. I will be doing random functions to help with areas that aren't well documented.

Android SL4A API

  • ActivityResultFacade
  • AndroidFacade
  • ApplicationManagerFacade
  • BatteryManagerFacade
  • BluetoothFacade
  • CameraFacade
  • CommonIntentsFacade
  • ContactsFacade
  • EventFacade
  • LocationFacade
  • MediaPlayerFacade
  • MediaRecorderFacade
  • PhoneFacade
  • PreferencesFacade
  • SensorManagerFacade
  • SettingsFacade
  • SignalStrengthFacade
  • SmsFacade
  • SpeechRecognitionFacade
  • TextToSpeechFacade
  • ToneGeneratorFacade
  • UiFacade
  • WakeLockFacade
  • WebCamFacade
  • WifiFacade

« Last Edit: May 13, 2012, 01:53:53 PM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #8 on: May 13, 2012, 02:34:51 PM »
I started building an Android SL4A module to kick things off. Don't wait too long or your favorite Facade may be taken.  ;)

Code: [Select]
' Android SL4A Interface
'
' ScriptBasic Open Source Project
'
' Contributors:
'   John Spikowski (JRS)
'
' Change Log:
'   20120513 - Initial module created

MODULE DVM

OPEN "localhost:9999" FOR SOCKET AS #1

id = 1

FUNCTION JSON2SB(json_response)
  LOCAL r,t,x,a
  r = MID(json_response,2)
  r = LEFT(r,LEN(r) - 1)
  r = REPLACE(r, "\"", "")
  SPLITA r BY "," TO t
  FOR x = 0 to UBOUND(t)
    a{LEFT(t[x],INSTR(t[x],":")-1)} = MID(t[x],INSTR(t[x],":")+1)
  NEXT
  JSON2SB = a
END FUNCTION


'**************
' PhoneFacade *
'**************

FUNCTION getPhoneType()
  LOCAL r, a
  PRINT #1,"""{"id":""" & id & ""","method":"getPhoneType","params":[]}\n"""
  LINE INPUT #1, r
  a = JSON2SB(r)
  IF a{"error") <> "null" THEN
    getPhoneType = undef
  ELSE
    getPhoneType = a{"result"}
  END IF
  id += 1
END FUNCTION


END MODULE

Untested at time of posting.
« Last Edit: May 13, 2012, 02:40:41 PM by support »

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #9 on: May 13, 2012, 04:14:30 PM »
I have lots of catching up to do John, you are moving right along. That is great.

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #10 on: May 13, 2012, 09:08:39 PM »
While testing the new DVM module, I discoved that calling a SUB or FUNCTION puts it in an endless loop. The same test programs work fine on Ubuntu scriba. I have a funny feeling the initial ARM gcc bug that Steve found has raised it's ugly head again.  >:(

kryton9

  • Guest
How did you install SB and Terminal in AVD
« Reply #11 on: May 13, 2012, 11:47:10 PM »
John, I finally got Android SDK installed with eclipse and setup an AVD device, but I can't figure out how you got Scriptbasic and the Terminal App as well as sl4a on it, the Virtual Android Device, not a real one?

updated:
I tried ADB and got scriba over there, but how did you download terminal and get that over to it?  Thanks in advance.
« Last Edit: May 14, 2012, 12:02:23 AM by kryton9 »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #12 on: May 14, 2012, 12:10:09 AM »
You can get the jackpal terminal from github

SL4A can be downloaded from HERE.

I don't see the FUNCTION/SUB looping issue taking too long to fix.

If your using the Linux Android emulator, I use adb to push everything to the SDCARD. (emulated with a file)

« Last Edit: May 14, 2012, 12:13:13 AM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic for Android
« Reply #13 on: May 14, 2012, 12:26:57 AM »
Good News!

I found a workaround until the SB dev team solves the SUB/FUNCTION issue. SL4A allows you to access the RPC server on the phone/pad/emulator if you start the server as a public connection. This assigns an accessible IP address rather then localhost. I can use scriba that is running on my Ubuntu 64 box and control the Android device via RPC. I should be able to move the scripts (untouched) to the Android device once Armando generates a new scriba.

« Last Edit: May 14, 2012, 12:00:08 PM by support »

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #14 on: May 14, 2012, 09:41:17 AM »
Thanks John for the links. I decided to use the emulator, first to learn it and also to try to match what you are doing and then when it works on the emulator then try it on the tablet. Since my cell phone is my only phone and I need to rely on it, I don't want to experiment too much with it.