SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/system/bin/sh
  2. PATH=/sbin:/system/sbin:/system/bin:/system/xbin
  3.  
  4. export FOS_FLAGS_ADB_ON=0x1
  5. export FOS_FLAGS_CONSOLE_ON=0x4
  6. export FOS_FLAGS_RAMDUMP_ON=0x8
  7. export FOS_FLAGS_VERBOSITY_ON=0x10
  8. export FOS_FLAGS_ADB_AUTH_DISABLE=0x20
  9.  
  10. # General FOS flags, shared across devices
  11. fosflagsfile="/proc/idme/fos_flags"
  12. # Optional device specific flags
  13. devflagsfile="/proc/idme/dev_flags"
  14. # User controllable flags (privilege not required to set)
  15. usrflagsfile="/proc/idme/usr_flags"
  16. # adb closed device
  17. adb_cd="/system/etc/adb_cd.sh"
  18. WIPE="/system/bin/wipe_fos_flags"
  19. FACTORYMODE="/data/system/FACTORYMODE"
  20.  
  21.  
  22. function unset_adb_persistent_property()
  23. {
  24.     local lcl_usb_prop=$(getprop persist.sys.usb.config)
  25.  
  26.     if [[ $lcl_usb_prop != *adb* ]]; then
  27.         log -t FOSFLAGS "adb is not enabled, nothing to do"
  28.         return
  29.     fi
  30.  
  31.     #adb is typically the last property, but it might not be the case,
  32.     # better be safe and tokenize
  33.     usb_tokens=(${lcl_usb_prop//,/ })
  34.     if [ ${#usb_tokens[@]} -eq 1 ]; then
  35.         lcl_usb_prop="none"
  36.     else
  37.         unset lcl_usb_prop
  38.         for i in ${usb_tokens[@]}; do
  39.             if [[ $i == "adb" ]]; then continue; fi
  40.  
  41.             if [[ $lcl_usb_prop ]]; then
  42.                 lcl_usb_prop=$lcl_usb_prop,$i
  43.             else
  44.                 lcl_usb_prop=$i
  45.             fi
  46.         done
  47.     fi
  48.     log -t FOSFLAGS "Disable ADB from persist property"
  49.     setprop persist.sys.usb.config $lcl_usb_prop
  50. }
  51.  
  52.  
  53. if [ -f $fosflagsfile ]; then
  54.     FOSFLAGS=$(cat $fosflagsfile)
  55.  
  56.     # Ensure input is only hexadecimal
  57.     in_size=${#FOSFLAGS}
  58.     FOSFLAGS=${FOSFLAGS//[!^a-fA-F0-9]/}
  59.     # If size differs, there might be something wrong
  60.     if [ ${#FOSFLAGS} -ne $in_size ]; then
  61.         FOSFLAGS=0
  62.     fi
  63.     # If empty, set safe value
  64.     if [[ ! $FOSFLAGS ]];then
  65.         FOSFLAGS=0
  66.     fi
  67.  
  68.     export FOSFLAGS=0x$FOSFLAGS
  69.  
  70.     log -t FOSFLAGS Read FOS flags:$FOSFLAGS
  71.  
  72.     if [ $# -gt 0 -a $1 = "wipe" ]; then
  73.       if [ ! -x ${WIPE} ]; then
  74.         log -t FOSFLAGS No wipe_fos_flags found - fos_flags wipe not supported
  75.         exit 1
  76.       fi
  77.       if [ "$FOSFLAGS" = "0x0" ]; then
  78.         log -t FOSFLAGS FOS flags already cleared - disabling adb
  79.         unset_adb_persistent_property
  80.       else
  81.         FOSFLAGS=0x$(${WIPE} 2>/dev/null)
  82.         if [ "$FOSFLAGS" = "0x0" ]; then
  83.           log -t FOSFLAGS fos_flags wipe succeeded
  84.           unset_adb_persistent_property
  85.         else
  86.           log -t FOSFLAGS fos_flags wipe failed
  87.           exit 1
  88.         fi
  89.       fi
  90.       exit 0
  91.     fi
  92.  
  93.     if [ $(( $FOS_FLAGS_ADB_ON & $FOSFLAGS )) != 0 ]; then
  94.         log -t FOSFLAGS "Enabling adb from FOS flags"
  95.         old_usb_prop=$(getprop persist.sys.usb.config)
  96.  
  97.         if [[ ! $old_usb_prop == *adb* ]]; then
  98.             if [[ $old_usb_prop == "none" ]]; then
  99.                 usb_prop=adb
  100.             else
  101.                 usb_prop="${old_usb_prop},adb"
  102.             fi
  103.             setprop persist.sys.usb.config $usb_prop
  104.         fi
  105.     else
  106.         # Check if cleanup is required
  107.         if [ x$(getprop ro.boot.clear_fos_adb) == xtrue ]; then
  108.             unset_adb_persistent_property
  109.         elif [ -f $adb_cd ]; then
  110.             # Check if its a closed device
  111.             closed_device=$($adb_cd)
  112.             if [ $closed_device == closed ]; then
  113.                 unset_adb_persistent_property
  114.             fi
  115.         fi
  116.     fi
  117.  
  118.     if [ $(( $FOS_FLAGS_CONSOLE_ON & $FOSFLAGS )) != 0 ]; then
  119.         log -t FOSFLAGS "Enabling console from FOS flags"
  120.         start console
  121.     fi
  122.  
  123.     if [ $(( $FOS_FLAGS_VERBOSITY_ON & $FOSFLAGS )) != 0 ]; then
  124.         log -t FOSFLAGS "Enabling verbose logging from FOS flags"
  125.         # KLOG_DEBUG = 7
  126.         setprop sys.init_log_level 7
  127.     fi
  128.  
  129.     if [ $(( $FOS_FLAGS_RAMDUMP_ON & $FOSFLAGS )) != 0 ]; then
  130.         log -t FOSFLAGS "Setting ramdump property on"
  131.         setprop persist.sys.mdump.enable 1
  132.     else
  133.         mdump_prop=$(getprop persist.sys.mdump.enable)
  134.         if [[ $mdump_prop && $(getprop persist.sys.mdump.enable) -eq 1 ]]; then
  135.             log -t FOSFLAGS "Disable ramdump property"
  136.             setprop persist.sys.mdump.enable 0
  137.         fi
  138.     fi
  139.  
  140.     if [ $(( $FOS_FLAGS_ADB_AUTH_DISABLE & $FOSFLAGS )) != 0 -o -f $FACTORYMODE ]; then
  141.       # set a property to signal higher layers that adb auth is temporarily
  142.       # suspended
  143.       setprop amazon.fos_flags.noadbauth 1
  144.     fi
  145. fi
  146.  
  147. if [ -f $usrflagsfile ]; then
  148.     export USRFLAGS=`cat $usrflagsfile`
  149.     log -t FOSFLAGS Read USR flags:$USRFLAGS
  150. fi
  151.  
  152. PRODUCT=$(getprop ro.product.device)
  153. if [ -z "$PRODUCT" ]; then
  154.     log -t FOSFLAGS "ro.product.device is not set";
  155.     PRODUCT="NOTSET_ERROR_ro.product.device";
  156. fi
  157.  
  158. DEVFLAGS_SH="/system/etc/init.fosflags.${PRODUCT}.sh"
  159. if [ -f "$devflagsfile" -a -f "$DEVFLAGS_SH" ]; then
  160.     /system/bin/sh $DEVFLAGS_SH
  161. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top