I am root?

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can try this code (requires the Phone library).
It tries to get root permission for the process.

I didn't test it on a rooted phone.
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim p As Phone
   Dim IsRoot As Boolean
   Try
      p.Shell("su", Null, Null, Null)
      File.WriteString("/", "test.txt", "")
      IsRoot = True
   Catch
      IsRoot = False
   End Try
   ToastMessageShow("Root=" & IsRoot, True)
End Sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Here is the bottom portion of the log, since when I run the app, I just see a black screen and then a message saying that the app is not responding.

B4X:
Key dispatching timed out sending to com.sometest.delete/com.sometest.delete.main
 Previous dispatch state: {{KeyEvent{action=1 code=4 repeat=0 meta=0 scancode=158 mFlags=72} to Window{4631b1c0 com.htc.launcher/com.htc.launcher.Launcher paused=false} @ 1325169126849 lw=Window{4631b1c0 com.htc.launcher/com.htc.launcher.Launcher paused=false} lb=android.os.BinderProxy@4631b018 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4631b1c0 com.htc.launcher/com.htc.launcher.Launcher paused=false}}}
Current dispatch state: {{null to Window{4634a2c0 com.sometest.delete/com.sometest.delete.main paused=false} @ 1325169220149 lw=Window{4634a2c0 com.sometest.delete/com.sometest.delete.main paused=false} lb=android.os.BinderProxy@46492868 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4634a2c0 com.sometest.delete/com.sometest.delete.main paused=false}}}
waitedFor: 15000, keyDispatchingTimeout: 15000
ANR in com.sometest.delete (com.sometest.delete/.main)
 Reason: keyDispatchingTimedOut
Load: 1.13 / 1.26 / 1.17
CPU usage from 177112ms to 56ms ago:
  oomberg.android: 2% = 2% user + 0% kernel / faults: 1655 minor
  system_server: 2% = 1% user + 0% kernel / faults: 955 minor
  m.android.phone: 0% = 0% user + 0% kernel / faults: 143 minor
  om.htc.launcher: 0% = 0% user + 0% kernel / faults: 1250 minor
  rild: 0% = 0% user + 0% kernel
  LocationService: 0% = 0% user + 0% kernel / faults: 23 minor
  droid.apps.maps: 0% = 0% user + 0% kernel / faults: 163 minor
  android.vending: 0% = 0% user + 0% kernel / faults: 126 minor
  ufou.android.su: 0% = 0% user + 0% kernel / faults: 102 minor
  com.bandcaster: 0% = 0% user + 0% kernel / faults: 94 minor
  logcat: 0% = 0% user + 0% kernel / faults: 209 minor
  android.iqagent: 0% = 0% user + 0% kernel / faults: 81 minor
  ient.android.im: 0% = 0% user + 0% kernel / faults: 48 minor
  com.htc.bgp: 0% = 0% user + 0% kernel / faults: 60 minor
   com.svox.pico: 0% = 0% user + 0% kernel / faults: 41 minor
  init: 0% = 0% user + 0% kernel
  akmd: 0% = 0% user + 0% kernel / faults: 69 minor
  dhd_dpc: 0% = 0% user + 0% kernel
  smd_tty: 0% = 0% user + 0% kernel
  iqfd: 0% = 0% user + 0% kernel
  servicemanager: 0% = 0% user + 0% kernel
  tc.android.mail: 0% = 0% user + 0% kernel / faults: 66 minor
  mediaserver: 0% = 0% user + 0% kernel / faults: 3 minor
  events/0: 0% = 0% user + 0% kernel
  iqd: 0% = 0% user + 0% kernel
  sqn_tx: 0% = 0% user + 0% kernel
  sequansd: 0% = 0% user + 0% kernel / faults: 177 minor
  com.android.mms: 0% = 0% user + 0% kernel / faults: 45 minor
  atmel_wq: 0% = 0% user + 0% kernel
  zygote: 0% = 0% user + 0% kernel / faults: 16 minor
  d.process.acore: 0% = 0% user + 0% kernel / faults: 22 minor
  wpa_supplicant: 0% = 0% user + 0% kernel
  ndroid.settings: 0% = 0% user + 0% kernel / faults: 12 minor
  e.process.gapps: 0% = 0% user + 0% kernel / faults: 26 minor
  htcloggerd: 0% = 0% user + 0% kernel
  le.android.epst: 0% = 0% user + 0% kernel / faults: 14 minor
  rint.ce.updater: 0% = 0% user + 0% kernel / faults: 16 minor
  oid.voicedialer: 0% = 0% user + 0% kernel / faults: 7 minor
  e.pluginmanager: 0% = 0% user + 0% kernel / faults: 8 minor
  xcxin.filexpert: 0% = 0% user + 0% kernel / faults: 32 minor
  ackageinstaller: 0% = 0% user + 0% kernel / faults: 7 minor
 +sometest.delete: 0% = 0% user + 0% kernel
 +sh: 0% = 0% user + 0% kernel
 +sometest.delete: 0% = 0% user + 0% kernel
 +sh: 0% = 0% user + 0% kernel
TOTAL: 7% = 6% user + 1% kernel + 0% softirq
get chart
FROM DATABASE
Sending signal. PID: 9405 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
getChartData
Sending signal. PID: 107 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 223 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 243 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 236 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 244 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 942 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 488 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 744 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 338 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 762 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 841 SIG: 3
threadid=3: reacting to signal 3
FROM DB
Wrote stack traces to '/data/anr/traces.txt'
updateRemoveViews(219 221 
Sending signal. PID: 680 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 955 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 347 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 459 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 962 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 662 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 871 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 320 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 1372 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 890 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 709 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 328 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 564 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 753 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 501 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 694 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 480 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 701 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 1051 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 646 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 594 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 806 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 467 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 527 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 686 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 780 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 818 SIG: 3
 threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 239 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 792 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 518 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 721 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 674 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 668 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 656 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 637 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 608 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 294 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
 Sending signal. PID: 546 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 534 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 505 SIG: 3
threadid=3: reacting to signal 3
Wrote stack traces to '/data/anr/traces.txt'
Sending signal. PID: 224 SIG: 3
threadid=3: reacting to signal 3
 Wrote stack traces to '/data/anr/traces.txt'
No window to dispatch pointer action 1
GetAvailableMs
 CdmaCellLocation Available
 Adding Alarm{46627010 type 2 com.google.android.apps.maps} Dec 13 03:47:06 pm
 CdmaCellLocation Available
 Adding Alarm{46486c80 type 2 com.google.android.apps.maps} Dec 13 03:47:06 pm
 CdmaCellLocation Available
 Adding Alarm{463f0bd8 type 2 com.google.android.apps.maps} Dec 13 03:47:06 pm
 GetAvailableMs
 get chart
 FROM DATABASE
getChartData
 GC_FOR_MALLOC freed 11640 objects / 525352 bytes in 39ms
 FROM DB
 updateRemoveViews(219 221 
CdmaCellLocation Available
 Adding Alarm{463fa890 type 2 com.google.android.apps.maps} Dec 13 03:47:06 pm
 GetAvailableMs
 
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
Works for me.


B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone



End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)


 

Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")

File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "df /data" & CRLF & "date" & CRLF & "exit") 'Any commands via crlf, and exit at end 
StdOut.Initialize
StdErr.Initialize

Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)


Msgbox(StdOut.tostring, "")



End Sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
That code doesn't show the MsgBox showing StdOut.ToString, only if I remove this line "Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)" is when I see it, in short, on my rooted device, that example do not work.
 
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
try changing this:

B4X:
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
to


B4X:
Result = Ph.Shell("su", Array As String(Runner), StdOut, StdErr)
 

Attachments

  • root.jpg
    root.jpg
    2.8 KB · Views: 280
Last edited:
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
If I throw this code for my other tablet (non-rooted)
it doesnt crash


B4X:
Try
Result = Ph.Shell("su", Array As String(Runner), StdOut, StdErr)
Msgbox(StdOut.tostring, "")
Catch
Msgbox("NOT ROOTED POSSIBLY!","")
End Try
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Yes, I get that, I continue and nothing.

If I throw this code for my other tablet (non-rooted)
it doesnt crash

On non-rooted it works.

EDIT TO ADD: My rooted phone displays nothing, just a black screen and ask to force close, my rooted tablet shows the "rooted" message then hangs and ask to force close.
 
Last edited:
Upvote 0
Top