voku1987

"SpicaTweak Lite" v1.5 (voku1987)

Jan 10th, 2012
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/system/bin/sh
  2. #
  3. # file: /system/etc/init.d/98spicaTweakLite v1.5
  4. # - adapted from "SSSwitch by voku1987 [voku(at)voku-online(dot)de] (Screen State Switch Lite)"
  5. #  
  6.  
  7.  
  8. # =========
  9. # One-time tweaks to apply on every boot;
  10. # =========
  11. STL=`ls -d /sys/block/stl*`;
  12. BML=`ls -d /sys/block/bml*`;
  13. MMC=`ls -d /sys/block/mmc*`;
  14.  
  15. # =========
  16. # Remount all partitions
  17. # =========
  18. for j in $(busybox mount | cut -d " " -f3);
  19. do
  20.     sync;
  21.     busybox mount -o remount,noatime,nodiratime $j;
  22. done;
  23.  
  24. for k in $(busybox mount | grep relatime | cut -d " " -f3);
  25. do
  26.     sync;
  27.     busybox mount -o remount,noatime,nodiratime $k;
  28. done;
  29.  
  30. for l in $(busybox mount | grep ext3 | cut -d " " -f3);
  31. do
  32.     sync;
  33.     busybox mount -o remount,noatime,nodiratime,commit=15 $l;
  34. done;
  35.  
  36. for m in $(busybox mount | grep ext4 | cut -d " " -f3);
  37. do
  38.     sync;
  39.     busybox mount -o remount,noatime,nodiratime,commit=15 $m;
  40. done;
  41.  
  42. # =========
  43. # Optimize io scheduler
  44. # =========
  45. for i in $STL $BML $MMC;
  46. do
  47.     if [ -e $i/queue/scheduler ];
  48.     then
  49.         /system/xbin/echo "bfq" > $i/queue/scheduler;
  50.     fi;
  51.  
  52.     if [ -e $i/queue/iostats ];
  53.     then
  54.         /system/xbin/echo "0" > $i/queue/iostats;
  55.     fi;
  56.  
  57.     if [ -e $i/queue/iosched/back_seek_penalty ];
  58.     then
  59.         /system/xbin/echo "1" > $i/queue/iosched/back_seek_penalty;
  60.     fi;
  61.  
  62.     if [ -e $i/queue/iosched/slice_idle ];
  63.     then
  64.         #/system/xbin/echo "3" > $i/queue/iosched/slice_idle;
  65.         /system/xbin/echo "0" > $i/queue/iosched/slice_idle;
  66.     fi;
  67.  
  68.     if [ -e $i/queue/iosched/slice_async_rq ];
  69.     then
  70.         /system/xbin/echo "2" > $i/queue/iosched/slice_async_rq;
  71.     fi;
  72.  
  73.     if [ -e $i/queue/read_ahead_kb ];
  74.     then
  75.         /system/xbin/echo "512" > $i/queue/read_ahead_kb;
  76.     fi;
  77.  
  78.     if [ -e $i/queue/iosched/back_seek_max ];
  79.     then
  80.         /system/xbin/echo "1000000000" > $i/queue/iosched/back_seek_max;
  81.     fi;
  82.  
  83.     if [ -e $i/queue/iosched/quantu ];
  84.     then
  85.         /system/xbin/echo "16" > $i/queue/iosched/quantum;
  86.     fi;
  87.  
  88.     if [ -e $i/queue/nr_requests ];
  89.     then
  90.         #/system/xbin/echo "2048" > $i/queue/nr_requests;
  91.         /system/xbin/echo "256" > $i/queue/nr_requests;
  92.     fi;
  93.  
  94.     if [ -e $i/queue/iosched/group_isolation ];
  95.     then
  96.         /system/xbin/echo "0" > $i/queue/iosched/group_isolation;
  97.     fi;
  98. done;
  99.    
  100. # =========
  101. # Optimize read-speed
  102. # =========
  103. if [ -e /sys/class/bdi/179:0/read_ahead_kb ];
  104. then
  105.     /system/xbin/echo "512" > /sys/class/bdi/179:0/read_ahead_kb;
  106. fi;
  107.  
  108. # =========
  109. # Optimize SQLite databases from apps
  110. # =========
  111. #
  112. for i in `busybox find /data -iname "*.db"`;
  113. do
  114.   /system/xbin/sqlite3 $i 'VACUUM;';
  115.   /system/xbin/sqlite3 $i 'REINDEX;';
  116. done;
  117.  
  118. if [ -d "/dbdata" ]; then
  119.     for i in `busybox find /dbdata -iname "*.db"`;
  120.     do
  121.         /system/xbin/sqlite3 $i 'VACUUM;';
  122.         /system/xbin/sqlite3 $i 'REINDEX;';
  123.     done;
  124. fi;
  125.  
  126. if [ -d "/datadata" ]; then
  127.     for i in `busybox find /datadata -iname "*.db"`;
  128.     do
  129.         /system/xbin/sqlite3 $i 'VACUUM;';
  130.         /system/xbin/sqlite3 $i 'REINDEX;';
  131.     done;
  132. fi;
  133.  
  134. if [ -d "/sdcard" ]; then
  135.     for i in `busybox find /sdcard -iname "*.db"`;
  136.     do
  137.         /system/xbin/sqlite3 $i 'VACUUM;';
  138.         /system/xbin/sqlite3 $i 'REINDEX;';
  139.     done;
  140. fi;
  141.  
  142. # =========
  143. # TWEAKS: for TCP read/write
  144. # =========
  145. /system/xbin/echo "0" > /proc/sys/net/ipv4/tcp_timestamps;
  146. /system/xbin/echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse;
  147. /system/xbin/echo "1" > /proc/sys/net/ipv4/tcp_sack;
  148. /system/xbin/echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle;
  149. /system/xbin/echo "1" > /proc/sys/net/ipv4/tcp_window_scaling;
  150. /system/xbin/echo "5" > /proc/sys/net/ipv4/tcp_keepalive_probes;
  151. /system/xbin/echo "30" > /proc/sys/net/ipv4/tcp_keepalive_intvl;
  152. /system/xbin/echo "30" > /proc/sys/net/ipv4/tcp_fin_timeout;
  153. /system/xbin/echo "404480" > /proc/sys/net/core/wmem_max;
  154. /system/xbin/echo "404480" > /proc/sys/net/core/rmem_max;
  155. /system/xbin/echo "256960" > /proc/sys/net/core/rmem_default;
  156. /system/xbin/echo "256960" > /proc/sys/net/core/wmem_default;
  157. /system/xbin/echo "4096 16384 404480" > /proc/sys/net/ipv4/tcp_wmem;
  158. /system/xbin/echo "4096 87380 404480" > /proc/sys/net/ipv4/tcp_rmem;
  159. setprop net.tcp.buffersize.default 4096,87380,404480,4096,16384,404480;
  160. setprop net.tcp.buffersize.wifi 4096,87380,404480,4096,16384,404480;
  161. setprop net.tcp.buffersize.umts 4096,87380,404480,4096,16384,404480;
  162.  
  163. # =========
  164. # TWEAKS: optimized for 3G/Edge speed
  165. # =========
  166. setprop ro.ril.hsxpa 2;
  167. setprop ro.ril.gprsclass 12;
  168. setprop ro.ril.hep 1;
  169. setprop ro.ril.enable.dtm 1;
  170. setprop ro.ril.hsdpa.category 8;
  171. setprop ro.ril.enable.a53 1;
  172. setprop ro.ril.enable.3g.prefix 1;
  173. setprop ro.ril.htcmaskw1.bitmask 4294967295;
  174. setprop ro.ril.htcmaskw1 14449;
  175. setprop ro.ril.hsupa.category 5;
  176.  
  177. # =========
  178. # TWEAKS
  179. # =========
  180. setprop ro.telephony.call_ring.delay 1000;
  181. setprop wifi.supplicant_scan_interval 180;
  182. setprop windowsmgr.max_events_per_sec 60;
  183. setprop ro.media.dec.jpeg.memcap 20000000;
  184. setprop ro.media.enc.jpeg.quality 85,75,65;
  185. setprop dalvik.vm.startheapsize 12m;
  186. setprop dalvik.vm.heapsize 32m;
  187. setprop debug.sf.hw 1;
  188. /system/xbin/echo "8" > /proc/sys/vm/page-cluster;
  189. /system/xbin/echo "1" /proc/sys/kernel/sched_compat_yield;
  190. /system/xbin/echo "0" /proc/sys/kernel/sched_child_runs_first;
  191. /system/xbin/echo "256000" /proc/sys/kernel/sched_shares_ratelimit;
  192. /system/xbin/echo "64000" > /proc/sys/kernel/msgmni;
  193. /system/xbin/echo "64000" > /proc/sys/kernel/msgmax;
  194. /system/xbin/echo "10" > /proc/sys/fs/lease-break-time;
  195. /system/xbin/echo "500 512000 64 2048" > /proc/sys/kernel/sem;
  196. /system/xbin/echo "5000" > /proc/sys/kernel/threads-max;
  197. /system/xbin/echo "0" > /proc/sys/vm/oom_kill_allocating_task;
  198. /system/xbin/echo "0" > /proc/sys/vm/panic_on_oom;
  199.  
  200. # =========
  201. # Battery-TWEAKS
  202. # =========
  203. mount -t debugfs none /sys/kernel/debug;
  204. /system/xbin/echo "NO_NEW_FAIR_SLEEPERS" > /sys/kernel/debug/sched_features;
  205. /system/xbin/echo "NO_NORMALIZED_SLEEPERS" > /sys/kernel/debug/sched_features;
  206. umount /sys/kernel/debug;
  207.  
  208. # =========
  209. # MEMORY-TWEAKS
  210. # =========
  211. /system/xbin/echo "50" > /proc/sys/vm/swappiness;
  212. /system/xbin/echo "50" > /proc/sys/vm/vfs_cache_pressure;
  213. /system/xbin/echo "4096" > /proc/sys/vm/min_free_kbytes;
  214. /system/xbin/echo "500" > /proc/sys/vm/dirty_expire_centisecs;
  215. /system/xbin/echo "3000" > /proc/sys/vm/dirty_writeback_centisecs;
  216. /system/xbin/echo "22" > /proc/sys/vm/dirty_ratio;
  217. /system/xbin/echo "4" > /proc/sys/vm/dirty_background_ratio;
  218. /system/xbin/echo "3" > /proc/sys/vm/drop_caches;
  219. /system/xbin/echo "1" > /proc/sys/vm/overcommit_memory;
  220. /system/xbin/echo "8" > /proc/sys/vm/min_free_order_shift;
  221. /system/xbin/echo "0,1,2,4,6,15" > /sys/module/lowmemorykiller/parameters/adj;
  222. /system/xbin/echo "0" > /sys/module/lowmemorykiller/parameters/debug_level;
  223. /system/xbin/echo "64" > /sys/module/lowmemorykiller/parameters/cost;
  224. # Define the memory thresholds at which the above process classes will
  225. # be killed. These numbers are in pages (4k) -> (1 MB * 1024) / 4 = 256
  226. FOREGROUND_APP_MEM=1536;
  227. VISIBLE_APP_MEM=2048;
  228. SECONDARY_SERVER_MEM=4096;
  229. BACKUP_APP_MEM=4096;
  230. HOME_APP_MEM=4096;
  231. HIDDEN_APP_MEM=5120;
  232. CONTENT_PROVIDER_MEM=15360;
  233. EMPTY_APP_MEM=23040;
  234. /system/xbin/echo "$FOREGROUND_APP_MEM,$VISIBLE_APP_MEM,$SECONDARY_SERVER_MEM,$HIDDEN_APP_MEM,$CONTENT_PROVIDER_MEM,$EMPTY_APP_MEM" > /sys/module/lowmemorykiller/parameters/minfree;
  235.  
  236. # =========
  237. # CPU-TWEAKS
  238. # =========
  239. #GOVERNOR=ondemand;
  240. #/system/xbin/echo "$GOVERNOR" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor;
  241. #/system/xbin/echo "10000000" > /proc/sys/kernel/sched_latency_ns;
  242. #/system/xbin/echo "1000000" > /proc/sys/kernel/sched_wakeup_granularity_ns;
  243. #/system/xbin/echo "800000" > /proc/sys/kernel/sched_min_granularity_ns;
  244. #/system/xbin/echo "-1" > /proc/sys/kernel/sched_rt_runtime_us;
  245. #/system/xbin/echo "100000" > /proc/sys/kernel/sched_rt_period_us;
  246.  
  247. # =========
  248. # zipalign-TWEAKS
  249. # =========
  250. LOG_FILE=/data/zipalign.log;
  251. ZIPALIGNDB=/data/zipalign.db;
  252.  
  253. if [ -e $LOG_FILE ]; then
  254.     rm $LOG_FILE;
  255. fi;
  256.  
  257. if [ ! -f $ZIPALIGNDB ]; then
  258.     touch $ZIPALIGNDB;
  259. fi;
  260.  
  261. /system/xbin/echo "Starting FV Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
  262.  
  263. for DIR in /system/app /data/app;
  264. do
  265.     cd $DIR;
  266.     for APK in *.apk ;
  267.     do
  268.         if [ $APK -ot $ZIPALIGNDB ] && [ $(grep "$DIR/$APK" $ZIPALIGNDB|wc -l) -gt 0 ];    
  269.         then
  270.             /system/xbin/echo "Already checked: $DIR/$APK" | tee -a $LOG_FILE;
  271.         else
  272.             zipalign -c 4 $APK;
  273.             if [ $? -eq 0 ];
  274.             then
  275.                 /system/xbin/echo "Already aligned: $DIR/$APK" | tee -a $LOG_FILE;
  276.                 grep "$DIR/$APK" $ZIPALIGNDB > /dev/null || echo $DIR/$APK >> $ZIPALIGNDB;
  277.             else
  278.                 /system/xbin/echo "Now aligning: $DIR/$APK" | tee -a $LOG_FILE;
  279.                 zipalign -f 4 $APK /cache/$APK;
  280.                 busybox mount -o rw,remount /system;
  281.                 cp -f -p /cache/$APK $APK;
  282.                 busybox rm -f /cache/$APK;
  283.                 grep "$DIR/$APK" $ZIPALIGNDB > /dev/null || echo $DIR/$APK >> $ZIPALIGNDB;
  284.             fi;
  285.         fi;
  286.     done;
  287. done;
  288. busybox mount -o ro,remount /system;
  289. touch $ZIPALIGNDB;
  290. /system/xbin/echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
  291.  
  292. # =========
  293. # Firewall-TWEAKS
  294. # =========
  295.  
  296. #ping/icmp protection
  297. /system/xbin/echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts;
  298. /system/xbin/echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all;
  299. /system/xbin/echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses;
  300.  
  301. if [ -e /proc/sys/net/ipv6/icmp_echo_ignore_broadcasts ];
  302. then
  303.     /system/xbin/echo "1" > /proc/sys/net/ipv6/icmp_echo_ignore_broadcasts;
  304. fi
  305.  
  306. if [ -e /proc/sys/net/ipv6/icmp_echo_ignore_all ];
  307. then
  308.     /system/xbin/echo "1" > /proc/sys/net/ipv6/icmp_echo_ignore_all;
  309. fi
  310.  
  311. if [ -e /proc/sys/net/ipv6/icmp_ignore_bogus_error_responses ];
  312. then
  313.     /system/xbin/echo "1" > /proc/sys/net/ipv6/icmp_ignore_bogus_error_responses;
  314. fi
  315.  
  316. #syn protection
  317. /system/xbin/echo "2" > /proc/sys/net/ipv4/tcp_synack_retries;
  318.  
  319. if [ -e /proc/sys/net/ipv6/tcp_synack_retries ];
  320. then
  321.     /system/xbin/echo "2" > /proc/sys/net/ipv6/tcp_synack_retries;
  322. fi
  323.  
  324. if [ -e /proc/sys/net/ipv6/tcp_syncookies ];
  325. then
  326.     /system/xbin/echo "0" > /proc/sys/net/ipv6/tcp_syncookies;
  327. fi
  328.  
  329. if [ -e /proc/sys/net/ipv4/tcp_syncookies ];
  330. then
  331.     /system/xbin/echo "1" > /proc/sys/net/ipv4/tcp_syncookies;
  332. fi
  333.  
  334. #drop spoof, redirects, etc
  335. /system/xbin/echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter;
  336. /system/xbin/echo "1" > /proc/sys/net/ipv4/conf/default/rp_filter;
  337. /system/xbin/echo "0" > /proc/sys/net/ipv4/conf/all/send_redirects;
  338. /system/xbin/echo "0" > /proc/sys/net/ipv4/conf/default/send_redirects;
  339. /system/xbin/echo "0" > /proc/sys/net/ipv4/conf/default/accept_redirects;
  340. /system/xbin/echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route;
  341. /system/xbin/echo "0" > /proc/sys/net/ipv4/conf/default/accept_source_route;
  342.  
  343. if [ -e /proc/sys/net/ipv6/conf/all/rp_filter ];
  344. then
  345.     /system/xbin/echo "1" > /proc/sys/net/ipv6/conf/all/rp_filter;
  346. fi
  347.  
  348. if [ -e /proc/sys/net/ipv6/conf/default/rp_filter ];
  349. then
  350.     /system/xbin/echo "1" > /proc/sys/net/ipv6/conf/default/rp_filter;
  351. fi
  352.  
  353. if [ -e /proc/sys/net/ipv6/conf/all/send_redirects ];
  354. then
  355.     /system/xbin/echo "0" > /proc/sys/net/ipv6/conf/all/send_redirects;
  356. fi
  357.  
  358. if [ -e /proc/sys/net/ipv6/conf/default/send_redirects ];
  359. then
  360.     /system/xbin/echo "0" > /proc/sys/net/ipv6/conf/default/send_redirects;
  361. fi
  362.  
  363. if [ -e /proc/sys/net/ipv6/conf/default/accept_redirects ];
  364. then
  365.     /system/xbin/echo "0" > /proc/sys/net/ipv6/conf/default/accept_redirects;
  366. fi
  367.  
  368. if [ -e /proc/sys/net/ipv6/conf/all/accept_source_route ];
  369. then
  370.     /system/xbin/echo "0" > /proc/sys/net/ipv6/conf/all/accept_source_route;
  371. fi
  372.  
  373. if [ -e /proc/sys/net/ipv6/conf/default/accept_source_route ];
  374. then
  375.     /system/xbin/echo "0" > /proc/sys/net/ipv6/conf/default/accept_source_route;
  376. fi
  377.  
  378. # =========
  379. # CleanUp
  380. # =========
  381.  
  382. #remove cache, tmp, and unused files
  383. #rm -f /cache/*.apk;
  384. #rm -f /cache/*.tmp;
  385. #rm -f /data/dalvik-cache/*.apk;
  386. #rm -f /data/dalvik-cache/*.tmp;
  387.  
  388. #if [ -e /data/system/userbehavior.db ];
  389. #then
  390. #   rm -f /data/system/userbehavior.db;
  391. #fi
  392.  
  393. #if [ -d /data/system/usagestats ];
  394. #then
  395. #   chmod 400 /data/system/usagestats;
  396. #fi
  397.  
  398. #if [ -d /data/system/appusagestats ];
  399. #then
  400. #   chmod 400 /data/system/appusagestats;
  401. #fi
  402.  
  403. #remove main log
  404. #if [ -e /dev/log/main ]
  405. #then
  406. #  rm -f /dev/log/main
  407. #fi
  408.  
  409. #drop caches to free some memory
  410. sync;
  411. /system/xbin/echo "3" > /proc/sys/vm/drop_caches;
  412. sleep 1;
  413. /system/xbin/echo "1" > /proc/sys/vm/drop_caches;
  414.  
  415. # =========
  416. # CPU-Priority for Apps
  417. # =========
  418.  
  419. for i in `seq 0 15`;
  420. do
  421.     ########
  422.     sleep 1;
  423.     ########
  424.     renice -20 `pidof com.android.phone`;
  425.     renice -19 `pidof com.android.inputmethod.latin`;
  426.     renice -19 `pidof com.swype.android.inputmethod`;
  427.     renice -17 `pidof com.android.systemui`;
  428.     renice -9 `pidof com.android.settings`;
  429.     renice -9 `pidof com.android.vending`;
  430.     renice -6 `pidof com.sec.android.app.camera`;
  431.     renice -6 `pidof com.sec.android.app.fm`;
  432.     renice -6 `pidof com.google.android.apps.maps`;
  433.     renice -4 `pidof com.google.android.apps.googlevoice`;
  434.     renice -3 `pidof android.process.media`;
  435.     renice -15 `pgrep android.process.acore`;
  436. done;
  437.  
  438. log -p i -t Tweak_Lite_v1.5 "*** BOOT tweaks ***: applied miscellaneous performance tweaks";
RAW Paste Data