1

I created a custom .rc file (/etc/init/nerding.rc) which initializes a custom "service" I made (/system/bin/listen) at boot, but after an hour or so my Android gets sluggish, isn't very responsive and when I check the dmesg, my nerding thing has failed and restarted thousands and thousands of times. Like once every 3 seconds.

The idea behind my file is that it listens for specific volume key and touchscreen taps whereupon it then hides or unhides some specific apps. Think 'Apex,' but with less evidence. I'll post the code and see if anyone has any suggestions/ideas. Please keep in mind that I only have JavaScript experience, so my BASH (or whatever Android's version is called) coding is haphazard at best. I am guessing my issue is because I'm not running my service as a 'oneshot,' but if I don't then the listen tool only listens once and quits. It needs to run every...2-5 seconds?

  • code for /etc/init/nerding.rc *
service nerding /system/bin/listen
   class main
   priority 10
   user root
   #oneshot
   seclabel u:object_r:system_file:s0

end of code

  • code for /system/bin/listen *
#!/system/bin/sh
function checkQuickHide {
  ups=$( dmesg | grep '(released) HW keycode = 0' | wc -l ) 
  if [ $ups -gt 4 ]; then 
    dmesg -C 
    pm hide jackpal.androidterm 
    hider 
    exit 
  else 
    checkuptime 
  fi 
}
function checkuptime { 
  #grab last 115 (volume up key)
  uptm=$(dmesg | grep 'keycode = 115' | tail -1 | tr -s ' ' | cut -d ' ' -f2 | cut -d ']' -f0 | cut -d "." -f0) 
  if [[ $uptm -eq '' ]]; then 
    dmesg -C
    exit
  else
    checkdowntime
  fi 
}
function checkdowntime {
  #grab last 114 (volume down key)
  dntm=$(dmesg | grep 'keycode = 114' | tail -1 | tr -s ' ' | cut -d ' ' -f2 | cut -d ']' -f0 | cut -d "." -f0) 
  if [[ $dntm -eq '' ]]; then 
    dmesg -C
    exit
  else
    checkdiff
  fi 
}
function checkdiff {
  daff=$(( $dntm-$uptm )) 
  if [[ "$daff"  -gt 3 ]]; then 
    dmesg -C 
    exit 
  fi 
  if [[ "$daff" -lt 0 ]]; then 
    dmesg -C 
    exit 
  fi 
  fing1
}
#Screentouching
function fing1 {
  #first finger
  f1x=$( dmesg | grep 'tpd_down id: 0' | tail -1 | cut -d ':' -f4 | cut -d ',' -f0 ) 
  if [[ $f1x -eq '' ]]; then 
    let f1x=1000 
    exit
  fi 
  f1y=$( dmesg | grep 'tpd_down id: 0' | tail -1 | cut -d ':' -f5 | cut -d '-' -f0 ) 
  if [[ $f1y -eq '' ]]; then 
    let f1y=1000 
    exit
  fi 
  fing2 
}
function fing2 {
  #2nd finger
  f2x=$( dmesg | grep 'tpd_down id: 1' | tail -1 | cut -d ':' -f4 | cut -d ',' -f0 ) 
  if [[ $f2x -eq '' ]]; then 
    let f2x=1000 
    exit
  fi 
  f2y=$( dmesg | grep 'tpd_down id: 1' | tail -1 | cut -d ':' -f5 | cut -d '-' -f0 ) 
  if [[ $f2y -eq '' ]]; then 
    let f2y=1000 
    exit 
  fi 
  finglocs 
}
function finglocs {
  if [[ $f1x -lt 740 ]]; then 
    exit 
  fi 
  if [[ $f1y -gt 50 ]]; then 
    exit 
  fi
  if [[ $f2x -gt 50 ]]; then 
    exit 
  fi 
  if [[ $f2y -lt 1200 ]]; then 
    exit 
  fi  
  endgame 
}
function endgame {
  dmesg -C 
  app=$( pm list packages | grep jackpal.androidterm ) 
  if [[ $app != '' ]]; then
    pm hide jackpal.androidterm 
    hider
    exit  
  else 
   # echo 'Reveal Hidden App' 
    pm enable jackpal.androidterm 
    pm unhide jackpal.androidterm 
    exit 
  fi 
}
function hider {
  svc wifi disable
  appst=/data/data/jackpal.androidterm/app_HOME/apps.txt
  app=$( cat $appst )
  for x in `cat $appst`; 
    do 
      if [ -e /data/data/$x ]; then 
        pm hide $x 
      fi
    done 
  exit 
}
checkQuickHide 

end of code

I'm sure this could be more succinct and efficient, but everytime I tried to combine some steps I broke it!

The error I constantly get in dmesg is (with a higher pid each time):

[  277.585578] (3)[1:init]init: Service 'nerding' (pid 4073) exited with status 0
[  277.585621] (3)[1:init]init: Sending signal 9 to service 'nerding' (pid 4073) process group...
[  277.585871] (3)[1:init]init: PropSet [init.svc.nerding]=[restarting] Done
[  282.457675] (1)[1:init]init: starting service 'nerding'...
[  282.458615] (1)[1:init]init: PropSet [init.svc.nerding]=[running] Done
[  282.458687] (1)[1:init]init: property_set("ro.boottime.nerding", "282427639311") failed: property already set

Please, any suggestions, revisions, or criticisms are greatly appreciated.

Mikey Mill
  • 21
  • 2

0 Answers0