DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


sample_code:superuser

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:superuser [2015/03/20 21:23] (current)
stevegarman created
Line 1: Line 1:
 +====== Use superuser privileges ======
 +This code will only function on a rooted device.
  
 +===== Code =====
 +
 +<code JavaScript su.js>
 +
 +var globs={};​
 +
 +//​Called when application is started.
 +function OnStart()
 +{
 +  var lay = app.CreateLayout("​Linear","​Vertical,​FillXY"​);​
 +  globs.lst = app.CreateList(""​);​
 +  lay.AddChild(globs.lst);​
 +  app.AddLayout(lay);​
 +
 +  globs.sys = app.CreateSysProc( "​su"​ );​
 +  var shellfolder = "/​sdcard/​sjgApps/​shell/"​
 +  app.MakeFolder(shellfolder);​
 +  globs.stdout = shellfolder + "​stdouttemp.txt"​
 +  globs.redir = "​ >>​ "​ + globs.stdout + "​ 2>&​1 \n ";​
 +
 +  sysEmpty();​
 +  sysOut("​ls -l /​data/​ "​);​
 +  sysOut("​exit"​);​
 +  setTimeout(display,​500);​
 + } 
 +
 +function display()
 +{
 +   //​create list eqivalent to app.ListFolder
 +   var list = app.ReadFile(globs.stdout).replace(/​\ +/​g,​ '​ '​).split("​\n"​);​
 +   //​populate
 +   var s = "";​
 +   var len = list.length;​
 +   for (var i=0;​i<​len;​i++)
 +   {
 +      var rec = list[i];​
 +      var isfolder = (rec.charAt(0)=="​d"​)
 +      var fil=rec.slice(rec.lastIndexOf("​ "​)+1);​
 +      globs.lst.AddItem("/​sdcard/"​+fil,​null,​(isfolder?"​folder":​null));​
 +   }
 +}
 +function sysEmpty(stamp)
 +{
 +    app.DeleteFile(globs.stdout);​
 +    if(stamp) sysStamp();​
 +}
 +
 +function sysOut (cmd,​ stamp)
 +{
 +   if(stamp) sysStamp();​
 +   globs.sys.Out(cmd + globs.redir)
 +}
 +
 +function sysEcho(msg,​ stamp)
 +{
 +    sysOut('​echo "'​ + msg +'"',​ stamp );​
 +
 +
 +function sysStamp()
 +{
 +    var d = new Date();​
 +    sysEcho("​**************************"​);​
 +    sysEcho(d.toISOString()+"​ *"​);​
 +    sysEcho("​**************************"​);​
 +}
 +</​code>​
sample_code/superuser.txt · Last modified: 2015/03/20 21:23 by stevegarman