FORUMS
Remove All Ads from XDA

[MOD][TWRP] LOS16 Tweak script - Please share yours also![9.0][3/3T][24/07/19]

n/a posts
Thanks Meter: 0
 
By GuestK00264, Guest on 25th July 2019, 03:13 PM
Post Reply Email Thread
The last months I am using LOS16 (Pie) on my OP3T and have implemented some tweaks to let it work as I want it to be.
The tweaks I am doing are implemented after a dirty flash, which I am doing roughly once a month.
After the dirty flash I am using the script enclosed to remove some apps, to clear as much as possible and startup almost clean without loosing settings.
Ofcourse also some other stuff like build.prop and userinit.sh settings are implemented.

Note:
Some people say it is not wise to clean all stuff like I do in the script, because a lot of writing is done afterwards, like building caches etc....
But, in my experience, the OP3(t) is a real killer and the cache building does not bother me.
Even after 3 years of heavy usage, everything is like new and performance is great.
So may be the result is a little more wearage of SSD, but I like a clean system and do not expect any troubles when only doing this once a month.

I want to share the script because it can help others, but I am sure there other OP3(t) users are also using scripts to optimise some settings, remove apps etc.... which can help me also.
So please, feel free to add your script(s) also and make this a place where OP3(t) users can find information to make their own script.

When you have some questions, please let me know!

BTW:
Never use a script like this when you do not know what it is doing, and ofcourse using it at your own risk!!
First read every line of it, try to understand what it is doing and what you are missing afterwards when implementing without any change (apps, launcher etc...)

Code:
#!/sbin/sh
#
# Script by 2Tweak
# Last modified 25-07-2019

################################################

# First setup
clear

sleep 0.3

echo
echo "##########################################"
echo "#           ROM DEBLOAT SCRIPT           #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

sleep 0.3

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
  AntHalService
  AudioFX
  BackupRestoreConfirmation
  BasicDreams
  BluetoothMidiService
  BookmarkProvider
  BuiltInPrintService
  Calendar
  CaptivePortalLogin
  CNEService
  CallLogBackup
  CellBroadcastReceiver
  CompanionDeviceManager
  Contacts
  CtsShimPrebuilt
  CtsShimPrivPrebuilt
  DocumentsUI
  EasterEgg
  Eleven
  Email
  ExactCalculator
  Exchange2
  Gallery2
  HTMLViewer
  InputDevices
  Jelly
  LatinIME
  LineageSetupWizard
  LiveWallpapersPicker
  LockClock
  ManagedProvisioning
  OneTimeInitializer
  OneplusDoze
  OneplusPocketMode
  PhotoTable
  PrintRecommendationService
  SharedStorageBackup
  SimAppDialog
  Stk
  Tag
  Terminal
  Traceur
  TrebuchetQuickStep
  Updater
  UserDictionaryProvider
  VpnDialogs
  WallpaperBackup
  WeatherProvider
  WfdService
"

for appname in $applist
do
  if [ -e /system/app/$appname ]; then
    chmod -R 777 /system/app/$appname
    rm -rf /system/app/$appname
  fi
  if [ -e /system/priv-app/$appname ]; then
    chmod -R 777 /system/priv-app/$appname
    rm -rf /system/priv-app/$appname
  fi
done

echo " done!"
sleep 0.3

################################################

echo -n "Removing junk files................."

# file list to cleanup
filelist="
  /cache
  /data/anr
  /data/backup
  /data/cache
  /data/dalvik-cache
  /data/lineageos_updates
  /data/local/tmp
  /data/lost+found
  /data/ota
  /data/ota_package
  /data/resource-cache
  /data/system/batterystats.bin
  /data/system/dropbox
  /data/system/graphicsstats
  /data/system/install_sessions.xml
  /data/system/last-fstrim
  /data/system/package_cache
  /data/system/procstats
  /data/system/syncmanager-log
  /data/system/uiderrors.txt
  /data/system/usagestats/0/monthly
  /data/system/usagestats/0/weekly
  /data/system/usagestats/0/yearly
  /data/system/usagestats/daily
  /data/tombstones
  /sdcard/DCIM/.thumbnails
  /system/bin/bootanimation
  /system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d $filename ]; then
    chmod -R 777 $filename
    rm -rf $filename/*
  fi
  if [ -f $filename ]; then
    chmod 777 $filename
    rm -f $filename
  fi
done

# Remove bak, log and tmp files
find /data -iname "*.bak" -type f -exec rm -f {} +
find /data -iname "*.log" -type f -exec rm -f {} +
find /data -iname "*.tmp" -type f -exec rm -f {} +
find /data -iname "*.odex" -type f -exec rm -f {} +
find /data -iname "*.vdex" -type f -exec rm -f {} +

find /system -iname "*.bak" -type f -exec rm -f {} +
find /system -iname "*.log" -type f -exec rm -f {} +
find /system -iname "*.tmp" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz

# Reduce fonts to the bare minimum
find /system/fonts ! -iname "*roboto*.*" ! -name "DroidSansMono.ttf" -type f -exec rm -f {} +

# Some resets after firmware upgrades
# Reset NFC
rm -f /data/nfc/nfaStorage.bin1
# Remove passwords
rm -f /data/system/locksettings.db
rm -f /data/system/locksettings.db-shm
rm -f /data/system/locksettings.db-wal
rm -f /data/system/gatekeeper.password.key
rm -f /data/system/gatekeeper.pattern.key
# Reset fingerprint
rm -f /data/system/users/0/fpdata/user.db
rm -f /data/system/users/0/settings_fingerprint.xml

echo " done!"
sleep 0.3

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
  if [ -e /data/data/$i/cache ]; then
    chmod -R 777 /data/data/$i/cache
    rm -rf /data/data/$i/cache/*
  fi
  if [ -e /data/data/$i/code_cache ]; then
    chmod -R 777 /data/data/$i/code_cache
    rm -rf /data/data/$i/code_cache/*
  fi
  if [ -e /data/data/$i/files/.Fabric ]; then
    chmod -R 777 /data/data/$i/files/.Fabric
    rm -rf /data/data/$i/files/.Fabric/*
  fi
  if [ -e /data/data/$i/files/cache ]; then
    chmod -R 777 /data/data/$i/files/cache
    rm -rf /data/data/$i/files/cache/*
  fi
  if [ -e /data/data/$i/app_webview ]; then
    chmod -R 777 /data/data/$i/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/$i/app_webview/Cookies ]; then
         mv -f /data/data/$i/app_webview/Cookies /data/local/tmp/$i.Cookies
    fi
    rm -rf /data/data/$i/app_webview/*
    if [ -e /data/local/tmp/$i.Cookies ]; then
      mv -f /data/local/tmp/$i.Cookies /data/data/$i/app_webview/Cookies
    fi
  fi
done

for j in $(ls /data/app/)
do
  if [ -e /data/app/$j/oat/arm ]; then
    chmod -R 777 /data/app/$j/oat/arm
    rm -rf /data/app/$j/oat/arm/*
  fi
  if [ -e /data/app/$j/oat/arm64 ]; then
    chmod -R 777 /data/app/$j/oat/arm64
    rm -rf /data/app/$j/oat/arm64/*
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/$k/cache ]; then
    chmod -R 777 /sdcard/Android/data/$k/cache
    rm -rf /sdcard/Android/data/$k/cache/*
  fi
done

# App specific
rm -rf /data/data/com.abnamro.nl.mobile.payments/app_dex/oat/arm64/*
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"
sleep 0.3

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

echo " done!"
sleep 0.3

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/system/dropbox
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"
sleep 0.3

################################################

echo -n "Repair Phone Is Starting error......"

rm -f '/system/vendor/bin/hw/[email protected]'
rm -f '/system/vendor/etc/init/[email protected]'
fname="/system/vendor/etc/vintf/manifest.xml"

found=0
startstop=0
tstr=""
nstr=""
IFS=$'\n'
while read line
do
  if [[ "$line" == *'<hal'* ]]; then
    startstop=1
  elif [[ "$line" == *'</hal'* ]]; then
    startstop=2
  elif [[ "$line" == *'livedisplay'* ]]; then
    found=1
  fi
  if [ $startstop -eq 1 ]; then
    tstr="${tstr}\n${line}"
  elif [ $startstop -eq 2 ]; then
    tstr="${tstr}\n${line}"
    if [ $found -eq 0 ]; then
      nstr="${nstr}${tstr}"
    else
      found=0
    fi
    tstr=""
    startstop=0
  else
    if [ "$nstr" == "" ]; then
      nstr="${line}"
    else
      nstr="${nstr}\n${line}"
    fi
  fi
done <"$fname"

echo $nstr > $fname

echo " done!"
sleep 0.3

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging, checks and sending data
logcat.live=disable
profiler.force_disable_err_rpt=1
profiler.force_disable_ulog=1

persist.android.strictmode=0
ro.config.nocheckin=1
ro.kernel.android.checkjni=0
ro.kernel.checkjni=0

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Improve call quality
ro.ril.enable.amr.wideband=1

# Better network signals
persist.cust.tel.eons=1
ro.config.hw_fast_dormancy=1

# Enable Volte functionality
persist.dbg.ims_volte_enable=1
persist.dbg.volte_avail_ovr=1
persist.dbg.vt_avail_ovr=1
persist.dbg.wfc_avail_ovr=1
persist.volte_enalbed_by_hw=1

# Disable scrolling cache
persist.sys.scrollingcache=4

# Optimize Dalvik
dalvik.vm.dexopt-flags=v=n,o=v,m=y

# Power Savings
ro.ril.power_collapse=1
pm.sleep_mode=1
wifi.supplicant_scan_interval=500
ro.mot.eri.losalert.delay=1000

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"
sleep 0.3

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"
sleep 0.3

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Stop perfd before implementing tweaks
stop perfd

# Perfect mount options
mount -o remount,noatime,noauto_da_alloc,nodiratime,barrier=0,commit=60,nobh /system
mount -o remount,noatime,noauto_da_alloc,rw,nosuid,nodev,nodiratime,barrier=0,commit=60,nobh /data
mount -o remount,noatime,noauto_da_alloc,rw,nosuid,nodev,nodiratime,barrier=0,commit=60,nobh /cache

# Flags blocks as non-rotational and increases cache size
LOOP=`ls -d /sys/block/loop*`
RAM=`ls -d /sys/block/ram*`
for j in $LOOP $RAM
do
  chmod 666 $j/queue/rotational
  echo 0 > $j/queue/rotational
  chmod 444 $j/queue/rotational
  chmod 666 $j/queue/read_ahead_kb
  echo 2048 > $j/queue/read_ahead_kb
  chmod 444 $j/queue/read_ahead_kb
done

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

# Enable power_efficient workqueue
chmod 666 sys/module/workqueue/parameters/power_efficient
echo 1 > /sys/module/workqueue/parameters/power_efficient
chmod 444 sys/module/workqueue/parameters/power_efficient

# Battery tweaks
chmod 666 proc/sys/vm/dirty_expire_centisecs
echo 1000 > /proc/sys/vm/dirty_expire_centisecs
chmod 444 proc/sys/vm/dirty_expire_centisecs
chmod 666 proc/sys/vm/dirty_writeback_centisecs
echo 2000 > /proc/sys/vm/dirty_writeback_centisecs
chmod 444 proc/sys/vm/dirty_writeback_centisecs

# Miscellaneous
chmod 666 /sys/module/sync/parameters/fsync_enabled
echo 'N' > /sys/module/sync/parameters/fsync_enabled
chmod 444 /sys/module/sync/parameters/fsync_enabled
chmod 666 /sys/block/sda/queue/iostats
echo '0' > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# Start perfd again
start perfd

# Fstrim on boot
if [ -e /data/adb/magisk/busybox ]; then
  /data/adb/magisk/busybox fstrim /cache &
  /data/adb/magisk/busybox fstrim /data &
  /data/adb/magisk/busybox fstrim /system &
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"
sleep 0.3

################################################

echo -n "Change all timestamps..............."

# Useless but nice to have most dates set to install date again
find / -type d -exec touch {} + 2>/dev/null
find / -type f -exec touch {} + 2>/dev/null

echo " done!"
sleep 0.3

################################################

if [ -e /data/adb/magisk/busybox ]; then
  echo -n "Optimising disks using fstrim......."
  /data/adb/magisk/busybox fstrim /cache
  /data/adb/magisk/busybox fstrim /data
  /data/adb/magisk/busybox fstrim /system
  echo " done!"
fi

echo
Further setup (25-07-2019):
Oxygen 9.04 firmware
TWRP 3.3.1-0
Lineage OS 16
Flashkernel r58 (3.18.140) (sometimes changing to Mady's out of curiousity but performancewise I prefer Flash)
Magisk v19.3
Librechair launcher
No Google stuff, using AuroraStore and AuroraDroid as playstores.
The Following 10 Users Say Thank You to GuestK00264 For This Useful Post: [ View ] Gift GuestK00264 Ad-Free
GuestK00264
12th August 2019, 07:25 PM |#2  
Guest
Thanks Meter: 0
 
More
Made some changes in setup to test if I can live without root and as simple as possible.
Further:
- removed some stuff from script,
- solved some small typings,
- added some more apk's and files to remove
I do not like the chmod lines in my userinit.sh, so probably I will add an array for that later.
Code:
#!/sbin/sh
#
# Script by 2Tweak
# Last modified 12-08-2019

################################################

# First setup
clear

echo
echo "##########################################"
echo "#           ROM DEBLOAT SCRIPT           #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
  AntHalService
  AudioFX
  BackupRestoreConfirmation
  BasicDreams
  BluetoothMidiService
  BookmarkProvider
  BuiltInPrintService
  Calendar
  CaptivePortalLogin
  CNEService
  CallLogBackup
  CellBroadcastReceiver
  CompanionDeviceManager
  com.qualcomm.location
  Contacts
  CtsShimPrebuilt
  CtsShimPrivPrebuilt
  Development
  DocumentsUI
  EasterEgg
  Eleven
  Email
  ExactCalculator
  Exchange2
  Gallery2
  HTMLViewer
  InputDevices
  Jelly
  LatinIME
  LineageSetupWizard
  LiveWallpapersPicker
  LockClock
  ManagedProvisioning
  OneTimeInitializer
  OneplusDoze
  OneplusPocketMode
  PhotoTable
  PrintRecommendationService
  Profiles
  SharedStorageBackup
  SimAppDialog
  Stk
  Tag
  Terminal
  Traceur
  Updater
  UserDictionaryProvider
  VpnDialogs
  WallpaperBackup
  WallpaperCropper
  WeatherProvider
  WfdService
"

for appname in $applist
do
  if [ -e /system/app/$appname ]; then
    chmod -R 777 /system/app/$appname
    rm -rf /system/app/$appname
  fi
  if [ -e /system/priv-app/$appname ]; then
    chmod -R 777 /system/priv-app/$appname
    rm -rf /system/priv-app/$appname
  fi
done

echo " done!"

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
  /cache
  /data/anr
  /data/backup
  /data/cache
  /data/dalvik-cache
  /data/lineageos_updates
  /data/local/tmp
  /data/lost+found
  /data/misc/bootstat
  /data/ota
  /data/ota_package
  /data/resource-cache
  /data/system/batterystats.bin
  /data/system/dropbox
  /data/system/graphicsstats
  /data/system/install_sessions.xml
  /data/system/last-fstrim
  /data/system/package_cache
  /data/system/procstats
  /data/system/syncmanager-log
  /data/system/uiderrors.txt
  /data/system/usagestats/0/daily
  /data/system/usagestats/0/monthly
  /data/system/usagestats/0/weekly
  /data/system/usagestats/0/yearly
  /data/tombstones
  /sdcard/DCIM/thumbnails
  /system/bin/bootanimation
  /system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d $filename ]; then
    chmod -R 777 $filename
    rm -rf $filename/*
  fi
  if [ -f $filename ]; then
    chmod 777 $filename
    rm -f $filename
  fi
done

# Remove bak, log, tmp and dex files
find /data -iname "*.bak" -type f -exec rm -f {} +
find /data -iname "*.log" -type f -exec rm -f {} +
find /data -iname "*.tmp" -type f -exec rm -f {} +
find /data -iname "*.odex" -type f -exec rm -f {} +
find /data -iname "*.vdex" -type f -exec rm -f {} +

find /system -iname "*.bak" -type f -exec rm -f {} +
find /system -iname "*.log" -type f -exec rm -f {} +
find /system -iname "*.tmp" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz
rm -rf /system/vendor/overlay

# Some resets after firmware upgrades
# Reset NFC
rm -f /data/nfc/nfaStorage.bin1
# Remove passwords
rm -f /data/system/locksettings.db
rm -f /data/system/locksettings.db-shm
rm -f /data/system/locksettings.db-wal
rm -f /data/system/gatekeeper.password.key
rm -f /data/system/gatekeeper.pattern.key
# Reset fingerprint
rm -f /data/system/users/0/fpdata/user.db
rm -f /data/system/users/0/settings_fingerprint.xml

# Reduce fonts to the bare minimum
find /system/fonts ! -iname "*roboto*.*" ! -name "DroidSansMono.ttf" ! -name "NotoColorEmoji.ttf" -type f -exec rm -f {} +

echo " done!"

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
  if [ -e /data/data/$i/cache ]; then
    chmod -R 777 /data/data/$i/cache
    rm -rf /data/data/$i/cache/*
  fi
  if [ -e /data/data/$i/code_cache ]; then
    chmod -R 777 /data/data/$i/code_cache
    rm -rf /data/data/$i/code_cache/*
  fi
  if [ -e /data/data/$i/files/.Fabric ]; then
    chmod -R 777 /data/data/$i/files/.Fabric
    rm -rf /data/data/$i/files/.Fabric/*
  fi
  if [ -e /data/data/$i/files/cache ]; then
    chmod -R 777 /data/data/$i/files/cache
    rm -rf /data/data/$i/files/cache/*
  fi
  if [ -e /data/data/$i/app_webview ]; then
    chmod -R 777 /data/data/$i/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/$i/app_webview/Cookies ]; then
         mv -f /data/data/$i/app_webview/Cookies /data/local/tmp/$i.Cookies
    fi
    rm -rf /data/data/$i/app_webview/*
    if [ -e /data/local/tmp/$i.Cookies ]; then
      mv -f /data/local/tmp/$i.Cookies /data/data/$i/app_webview/Cookies
    fi
  fi
done

for j in $(ls /data/app/)
do
  if [ -e /data/app/$j/oat/arm ]; then
    chmod -R 777 /data/app/$j/oat/arm
    rm -rf /data/app/$j/oat/arm/*
  fi
  if [ -e /data/app/$j/oat/arm64 ]; then
    chmod -R 777 /data/app/$j/oat/arm64
    rm -rf /data/app/$j/oat/arm64/*
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/$k/cache ]; then
    chmod -R 777 /sdcard/Android/data/$k/cache
    rm -rf /sdcard/Android/data/$k/cache/*
  fi
done

# App specific
rm -rf /data/data/com.abnamro.nl.mobile.payments/app_dex/oat/arm64/*
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

################################################

echo -n "Repair Phone Is Starting error......"

rm -f '/system/vendor/bin/hw/[email protected]'
rm -f '/system/vendor/etc/init/[email protected]'
fname="/system/vendor/etc/vintf/manifest.xml"

found=0
startstop=0
tstr=""
nstr=""
IFS=$'\n'
while read line
do
  if [[ "$line" == *'<hal'* ]]; then
    startstop=1
  elif [[ "$line" == *'</hal'* ]]; then
    startstop=2
  elif [[ "$line" == *'livedisplay'* ]]; then
    found=1
  fi
  if [ $startstop -eq 1 ]; then
    tstr="${tstr}\n${line}"
  elif [ $startstop -eq 2 ]; then
    tstr="${tstr}\n${line}"
    if [ $found -eq 0 ]; then
      nstr="${nstr}${tstr}"
    else
      found=0
    fi
    tstr=""
    startstop=0
  else
    if [ "$nstr" == "" ]; then
      nstr="${line}"
    else
      nstr="${nstr}\n${line}"
    fi
  fi
done <"$fname"

echo $nstr > $fname

echo " done!"

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging, checks and sending data
logcat.live=disable
profiler.force_disable_err_rpt=1
profiler.force_disable_ulog=1

persist.android.strictmode=0
ro.config.nocheckin=1
ro.kernel.android.checkjni=0
ro.kernel.checkjni=0

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Disable dithering
persist.sys.use_dithering=0

# Disable scrolling cache
persist.sys.scrollingcache=4

# Optimize Dalvik
dalvik.vm.dexopt-flags=v=n,o=v,m=y

# Power Savings
ro.ril.power_collapse=1
pm.sleep_mode=1
wifi.supplicant_scan_interval=500
ro.mot.eri.losalert.delay=1000

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Stop perfd before implementing tweaks
stop perfd

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

# Enable power_efficient workqueue
chmod 666 sys/module/workqueue/parameters/power_efficient
echo '1' > /sys/module/workqueue/parameters/power_efficient
chmod 444 sys/module/workqueue/parameters/power_efficient

# Battery tweaks
chmod 666 proc/sys/vm/dirty_expire_centisecs
echo '1000' > /proc/sys/vm/dirty_expire_centisecs
chmod 444 proc/sys/vm/dirty_expire_centisecs
chmod 666 proc/sys/vm/dirty_writeback_centisecs
echo '2000' > /proc/sys/vm/dirty_writeback_centisecs
chmod 444 proc/sys/vm/dirty_writeback_centisecs

# Disable fsync
chmod 666 /sys/module/sync/parameters/fsync_enabled
echo 'N' > /sys/module/sync/parameters/fsync_enabled
chmod 444 /sys/module/sync/parameters/fsync_enabled

# Disable iostats
chmod 666 /sys/block/sda/queue/iostats
echo '0' > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# Start perfd again
start perfd

# Fstrim on boot
if [ -e /storage/emulated/fstrim ]; then
  chmod 777 /storage/emulated/fstrim
  /storage/emulated/fstrim /cache &
  /storage/emulated/fstrim /data &
  /storage/emulated/fstrim /system &
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"

################################################

if [ -e /sdcard/Config/Device/fstrim ]; then
  echo -n "Optimising disks using fstrim......."
  chmod 777 /sdcard/Config/Device/fstrim
  /sdcard/Config/Device/fstrim /cache
  /sdcard/Config/Device/fstrim /data
  /sdcard/Config/Device/fstrim /system
  echo " done!"
fi

echo
Further setup (12-08-2019):
Oxygen 9.05 firmware
TWRP 3.3.1-0
Lineage OS 16
Flashkernel r58 (3.18.140)
No Google stuff, using AuroraStore and AuroraDroid as playstores.
Magisk removed (no root), back to default Trebuchet launcher

Copied fstrim to /sdcard/Config/Device to use it in my script and userinit.sh.
I used trimmer app to get a good working fstrim, but probably also available elsewhere.
The Following 4 Users Say Thank You to For This Useful Post: [ View ] Gift Ad-Free
GuestK00264
24th August 2019, 11:09 PM |#3  
Guest
Thanks Meter: 0
 
More
Removed some stuff because of issues, not working, or even not existing parameters in build.prop.
Pretty basic but working very well for me.
Code:
#!/sbin/sh
#
# Script by 2Tweak
# Last modified 24-08-2019

# Recommended to read before doing all kind of tweaks:
# https://************/most-common-android-optimization-myths-debunked/

################################################

# First setup
clear

echo
echo "##########################################"
echo "#           ROM DEBLOAT SCRIPT           #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
  AntHalService
  AudioFX
  BackupRestoreConfirmation
  BasicDreams
  BluetoothMidiService
  BookmarkProvider
  BuiltInPrintService
  Calendar
  CaptivePortalLogin
  CNEService
  CallLogBackup
  CellBroadcastReceiver
  CompanionDeviceManager
  Contacts
  CtsShimPrebuilt
  CtsShimPrivPrebuilt
  Development
  DocumentsUI
  EasterEgg
  Eleven
  Email
  ExactCalculator
  Exchange2
  Gallery2
  HTMLViewer
  InputDevices
  Jelly
  LatinIME
  LineageSetupWizard
  LiveWallpapersPicker
  LockClock
  ManagedProvisioning
  OneTimeInitializer
  OneplusDoze
  OneplusPocketMode
  PhotoTable
  PrintRecommendationService
  Profiles
  SharedStorageBackup
  SimAppDialog
  Stk
  Tag
  Terminal
  Traceur
  Updater
  UserDictionaryProvider
  VpnDialogs
  WallpaperBackup
  WallpaperCropper
  WeatherProvider
  WfdService
"

for appname in $applist
do
  if [ -e /system/app/$appname ]; then
    chmod -R 777 /system/app/$appname
    rm -rf /system/app/$appname
  fi
  if [ -e /system/priv-app/$appname ]; then
    chmod -R 777 /system/priv-app/$appname
    rm -rf /system/priv-app/$appname
  fi
done

echo " done!"

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
  /cache
  /data/anr
  /data/backup
  /data/cache
  /data/dalvik-cache
  /data/lineageos_updates
  /data/local/tmp
  /data/lost+found
  /data/misc/bootstat
  /data/ota
  /data/ota_package
  /data/resource-cache
  /data/system/batterystats.bin
  /data/system/dropbox
  /data/system/graphicsstats
  /data/system/install_sessions.xml
  /data/system/last-fstrim
  /data/system/package_cache
  /data/system/procstats
  /data/system/syncmanager-log
  /data/system/uiderrors.txt
  /data/system/usagestats/0/daily
  /data/system/usagestats/0/monthly
  /data/system/usagestats/0/weekly
  /data/system/usagestats/0/yearly
  /data/tombstones
  /sdcard/DCIM/thumbnails
  /system/bin/bootanimation
  /system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d $filename ]; then
    chmod -R 777 $filename
    rm -rf $filename/*
  fi
  if [ -f $filename ]; then
    chmod 777 $filename
    rm -f $filename
  fi
done

# Remove bak, log, tmp and dex files
find /data -iname "*.bak" -type f -exec rm -f {} +
find /data -iname "*.log" -type f -exec rm -f {} +
find /data -iname "*.tmp" -type f -exec rm -f {} +
find /data -iname "*.odex" -type f -exec rm -f {} +
find /data -iname "*.vdex" -type f -exec rm -f {} +

find /system -iname "*.bak" -type f -exec rm -f {} +
find /system -iname "*.log" -type f -exec rm -f {} +
find /system -iname "*.tmp" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz
rm -rf /system/vendor/overlay

# Some resets after firmware upgrades
# Reset NFC
rm -f /data/nfc/nfaStorage.bin1
# Remove passwords
rm -f /data/system/locksettings.db
rm -f /data/system/locksettings.db-shm
rm -f /data/system/locksettings.db-wal
rm -f /data/system/gatekeeper.password.key
rm -f /data/system/gatekeeper.pattern.key
# Reset fingerprint
rm -f /data/system/users/0/fpdata/user.db
rm -f /data/system/users/0/settings_fingerprint.xml

echo " done!"

################################################

echo -n "Disable live display functionality.."

rm -f '/system/vendor/bin/hw/[email protected]'
rm -f '/system/vendor/etc/init/[email protected]'
fname="/system/vendor/etc/vintf/manifest.xml"

found=0
startstop=0
tstr=""
nstr=""
IFS=$'\n'
while read line
do
  if [[ "$line" == *'<hal'* ]]; then
    startstop=1
  elif [[ "$line" == *'</hal'* ]]; then
    startstop=2
  elif [[ "$line" == *'livedisplay'* ]]; then
    found=1
  fi
  if [ $startstop -eq 1 ]; then
    tstr="${tstr}\n${line}"
  elif [ $startstop -eq 2 ]; then
    tstr="${tstr}\n${line}"
    if [ $found -eq 0 ]; then
      nstr="${nstr}${tstr}"
    else
      found=0
    fi
    tstr=""
    startstop=0
  else
    if [ "$nstr" == "" ]; then
      nstr="${line}"
    else
      nstr="${nstr}\n${line}"
    fi
  fi
done <"$fname"

echo $nstr > $fname

echo " done!"

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
  if [ -e /data/data/$i/cache ]; then
    chmod -R 777 /data/data/$i/cache
    rm -rf /data/data/$i/cache/*
  fi
  if [ -e /data/data/$i/code_cache ]; then
    chmod -R 777 /data/data/$i/code_cache
    rm -rf /data/data/$i/code_cache/*
  fi
  if [ -e /data/data/$i/files/.Fabric ]; then
    chmod -R 777 /data/data/$i/files/.Fabric
    rm -rf /data/data/$i/files/.Fabric/*
  fi
  if [ -e /data/data/$i/files/cache ]; then
    chmod -R 777 /data/data/$i/files/cache
    rm -rf /data/data/$i/files/cache/*
  fi
  if [ -e /data/data/$i/app_webview ]; then
    chmod -R 777 /data/data/$i/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/$i/app_webview/Cookies ]; then
	     mv -f /data/data/$i/app_webview/Cookies /data/local/tmp/$i.Cookies
    fi
    rm -rf /data/data/$i/app_webview/*
    if [ -e /data/local/tmp/$i.Cookies ]; then
      mv -f /data/local/tmp/$i.Cookies /data/data/$i/app_webview/Cookies
    fi
  fi
done

for j in $(ls /data/app/)
do
  if [ -e /data/app/$j/oat/arm ]; then
    chmod -R 777 /data/app/$j/oat/arm
    rm -rf /data/app/$j/oat/arm/*
  fi
  if [ -e /data/app/$j/oat/arm64 ]; then
    chmod -R 777 /data/app/$j/oat/arm64
    rm -rf /data/app/$j/oat/arm64/*
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/$k/cache ]; then
    chmod -R 777 /sdcard/Android/data/$k/cache
    rm -rf /sdcard/Android/data/$k/cache/*
  fi
done

# App specific
rm -rf /data/data/com.abnamro.nl.mobile.payments/app_dex/oat/arm64/*
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging
logcat.live=disable

# Remove fps limit
debug.gr.swapinterval=0

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Disable dithering
persist.sys.use_dithering=0

# Disable scrolling cache
persist.sys.scrollingcache=4

# Optimize Dalvik
dalvik.vm.dexopt-flags=v=n,o=v,m=y

# Disable ring delay
ro.telephony.call_ring.delay=0
ring.delay=0

# Misc power Savings
wifi.supplicant_scan_interval=500
ro.mot.eri.losalert.delay=1000

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Stop perfd - no side effects found
stop perfd

# Switch to noop
for i in /sys/block/mmc*; do
  echo noop > $i/queue/scheduler
  echo 0 > $i/queue/iostats
done

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

# Battery tweaks
chmod 666 /proc/sys/vm/dirty_expire_centisecs
echo 1000 > /proc/sys/vm/dirty_expire_centisecs
chmod 444 /proc/sys/vm/dirty_expire_centisecs
chmod 666 /proc/sys/vm/dirty_writeback_centisecs
echo 2000 > /proc/sys/vm/dirty_writeback_centisecs
chmod 444 /proc/sys/vm/dirty_writeback_centisecs

# Enable power_efficient workqueue
chmod 666 /sys/module/workqueue/parameters/power_efficient
echo 1 > /sys/module/workqueue/parameters/power_efficient
chmod 444 /sys/module/workqueue/parameters/power_efficient

# Disable fsync
chmod 666 /sys/module/sync/parameters/fsync_enabled
echo N > /sys/module/sync/parameters/fsync_enabled
chmod 444 /sys/module/sync/parameters/fsync_enabled

# Disable iostats
chmod 666 /sys/block/sda/queue/iostats
echo 0 > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# Fstrim on boot
if [ -e /storage/emulated/fstrim ]; then
  chmod 777 /storage/emulated/fstrim
  /storage/emulated/fstrim /cache
  /storage/emulated/fstrim /data
  /storage/emulated/fstrim /system
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"

################################################

if [ -e /sdcard/Config/Device/fstrim ]; then
  echo -n "Optimising disks using fstrim......."
  chmod 777 /sdcard/Config/Device/fstrim
  /sdcard/Config/Device/fstrim /cache
  /sdcard/Config/Device/fstrim /data
  /sdcard/Config/Device/fstrim /system
  echo " done!"
fi

echo
Further setup (24-08-2019):
Oxygen 9.05 firmware
TWRP 3.3.1-0
Lineage OS 16
Flashkernel r58 (3.18.140)
No Google stuff, using AuroraStore and AuroraDroid as playstores.
Magisk removed (no root),
Default Trebuchet launcher

Copied fstrim to /sdcard/Config/Device to use it in my script and userinit.sh.
I used trimmer app to get a good working fstrim, but probably also available elsewhere.
The Following 4 Users Say Thank You to For This Useful Post: [ View ] Gift Ad-Free
GuestK00264
1st September 2019, 07:45 AM |#4  
Guest
Thanks Meter: 0
 
More
<removed>
The Following User Says Thank You to For This Useful Post: [ View ] Gift Ad-Free
GuestK00264
4th September 2019, 10:43 PM |#5  
Guest
Thanks Meter: 0
 
More
After some reading and some input from people like @anupritaisno1 I came to the next setup.
I went back to rootless, encrypted my phone and made two scripts instead of one.
The install.sh script is used after installing the firmware, rom and kernel (normal dirty flashes) and is only removing the packages I am not using as some log files, and other useless stuff. Also used to implement some tweaks (userinit.sh, gps.conf, build.prop).
The cleanup.sh script is a script for removing all cache, dalvik-cache, app-caches etc.. and is the part I was only using about once a month to start almost clean without loosing settings.
install.sh, used to remove packages I am not using, some logging and other stuff, implementing some tweaks (userinit.sh):
Code:
#!/sbin/sh
#
# Script by 2Tweak
# Last modified 07-09-2019

################################################

# First setup
clear

echo
echo "##########################################"
echo "#        DEBLOAT AND TWEAK SCRIPT        #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
  AntHalService
  AudioFX
  BasicDreams
  BluetoothMidiService
  BookmarkProvider
  BuiltInPrintService
  Calendar
  CaptivePortalLogin
  CNEService
  CallLogBackup
  CellBroadcastReceiver
  CompanionDeviceManager
  Contacts
  CtsShimPrebuilt
  CtsShimPrivPrebuilt
  DocumentsUI
  EasterEgg
  Eleven
  Email
  ExactCalculator
  Exchange2
  Gallery2
  HTMLViewer
  InputDevices
  Jelly
  LineageSetupWizard
  LiveWallpapersPicker
  LockClock
  ManagedProvisioning
  OneTimeInitializer
  PhotoTable
  PrintRecommendationService
  SharedStorageBackup
  SimAppDialog
  Stk
  Tag
  Terminal
  Traceur
  Updater
  UserDictionaryProvider
  VpnDialogs
  WallpaperBackup
  WfdService
"

for appname in $applist
do
  if [ -e /system/app/$appname ]; then
    chmod -R 777 /system/app/$appname
    rm -rf /system/app/$appname
  fi
  if [ -e /system/priv-app/$appname ]; then
    chmod -R 777 /system/priv-app/$appname
    rm -rf /system/priv-app/$appname
  fi
done

echo " done!"

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
  /cache
  /data/anr
  /data/backup
  /data/lineageos_updates
  /data/local/tmp
  /data/lost+found
  /data/misc/bootstat
  /data/ota
  /data/ota_package
  /data/system/batterystats.bin
  /data/system/dropbox
  /data/system/graphicsstats
  /data/system/install_sessions.xml
  /data/system/last-fstrim
  /data/system/procstats
  /data/system/syncmanager-log
  /data/system/uiderrors.txt
  /data/system/usagestats/0/daily
  /data/system/usagestats/0/monthly
  /data/system/usagestats/0/weekly
  /data/system/usagestats/0/yearly
  /data/tombstones
  /system/bin/bootanimation
  /system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d $filename ]; then
    chmod -R 777 $filename
    rm -rf $filename/*
  fi
  if [ -f $filename ]; then
    chmod 777 $filename
    rm -f $filename
  fi
done

# Remove bak, log, tmp files
find /data -iname "*.bak" -type f -exec rm -f {} +
find /data -iname "*.log" -type f -exec rm -f {} +
find /data -iname "*.tmp" -type f -exec rm -f {} +

find /system -iname "*.bak" -type f -exec rm -f {} +
find /system -iname "*.log" -type f -exec rm -f {} +
find /system -iname "*.tmp" -type f -exec rm -f {} +

echo " done!"

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
  if [ -e /data/data/$i/app_webview ]; then
    chmod -R 777 /data/data/$i/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/$i/app_webview/Cookies ]; then
	     mv -f /data/data/$i/app_webview/Cookies /data/local/tmp/$i.Cookies
    fi
    rm -rf /data/data/$i/app_webview/*
    if [ -e /data/local/tmp/$i.Cookies ]; then
      mv -f /data/local/tmp/$i.Cookies /data/data/$i/app_webview/Cookies
    fi
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/$k/cache ]; then
    chmod -R 777 /sdcard/Android/data/$k/cache
    rm -rf /sdcard/Android/data/$k/cache/*
  fi
done

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging
logcat.live=disable

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Enable VoLTE
persist.dbg.ims_volte_enable=1
persist.dbg.volte_avail_ovr=1
persist.dbg.vt_avail_ovr=1
persist.dbg.wfc_avail_ovr=1
persist.radio.rat_on=combine
persist.radio.data_ltd_sys_ind=1
persist.radio.data_con_rprt=1
persist.radio.calls.on.ims=1

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

# Disable iostats
chmod 666 /sys/block/sda/queue/iostats
echo "0" > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# Disable some wakelocks
if [ -e /sys/devices/virtual/misc/boeffla_wakelock_blocker ]; then
  echo "IPA_WS;NETLINK;bms;netmgr_wl;qcom_rx_wakelock;sensor_SMD;wlan;wlan_extscan_wl;wlan_ipa;wlan_pno_wl;wlan_wow_wl" > /sys/devices/virtual/misc/boeffla_wakelock_blocker/wakelock_blocker
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"

echo
cleanup.sh, used about once a month to have the feeling I start with an almost clean system (probably useless):
Code:
]#!/sbin/sh
#
# Script by 2Tweak
# Last modified 06-09-2019

################################################

# First setup
clear

echo
echo "##########################################"
echo "#            DEEP CLEAN SCRIPT           #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
  /cache
  /data/anr
  /data/backup
  /data/cache
  /data/dalvik-cache
  /data/lineageos_updates
  /data/local/tmp
  /data/lost+found
  /data/misc/bootstat
  /data/ota
  /data/ota_package
  /data/resource-cache
  /data/system/batterystats.bin
  /data/system/dropbox
  /data/system/graphicsstats
  /data/system/install_sessions.xml
  /data/system/last-fstrim
  /data/system/package_cache
  /data/system/procstats
  /data/system/syncmanager-log
  /data/system/uiderrors.txt
  /data/system/usagestats/0/daily
  /data/system/usagestats/0/monthly
  /data/system/usagestats/0/weekly
  /data/system/usagestats/0/yearly
  /data/tombstones
  /system/bin/bootanimation
  /system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d $filename ]; then
    chmod -R 777 $filename
    rm -rf $filename/*
  fi
  if [ -f $filename ]; then
    chmod 777 $filename
    rm -f $filename
  fi
done

# Remove bak, log, tmp and dex files
find /data -iname "*.bak" -type f -exec rm -f {} +
find /data -iname "*.log" -type f -exec rm -f {} +
find /data -iname "*.tmp" -type f -exec rm -f {} +
find /data -iname "*.odex" -type f -exec rm -f {} +
find /data -iname "*.vdex" -type f -exec rm -f {} +

find /system -iname "*.bak" -type f -exec rm -f {} +
find /system -iname "*.log" -type f -exec rm -f {} +
find /system -iname "*.tmp" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz
rm -rf /system/vendor/overlay

echo " done!"

################################################

echo -n "Cleaning app data and caches........"

for i in $(ls /data/data/)
do
  if [ -e /data/data/$i/cache ]; then
    chmod -R 777 /data/data/$i/cache
    rm -rf /data/data/$i/cache/*
  fi
  if [ -e /data/data/$i/code_cache ]; then
    chmod -R 777 /data/data/$i/code_cache
    rm -rf /data/data/$i/code_cache/*
  fi
  if [ -e /data/data/$i/files/.Fabric ]; then
    chmod -R 777 /data/data/$i/files/.Fabric
    rm -rf /data/data/$i/files/.Fabric/*
  fi
  if [ -e /data/data/$i/files/cache ]; then
    chmod -R 777 /data/data/$i/files/cache
    rm -rf /data/data/$i/files/cache/*
  fi
  if [ -e /data/data/$i/app_webview ]; then
    chmod -R 777 /data/data/$i/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/$i/app_webview/Cookies ]; then
         mv -f /data/data/$i/app_webview/Cookies /data/local/tmp/$i.Cookies
    fi
    rm -rf /data/data/$i/app_webview/*
    if [ -e /data/local/tmp/$i.Cookies ]; then
      mv -f /data/local/tmp/$i.Cookies /data/data/$i/app_webview/Cookies
    fi
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/$k/cache ]; then
    chmod -R 777 /sdcard/Android/data/$k/cache
    rm -rf /sdcard/Android/data/$k/cache/*
  fi
done

echo " done!"

################################################

echo -n "Cleaning app oat files.............."

for j in $(ls /data/app/)
do
  if [ -e /data/app/$j/oat/arm ]; then
    chmod -R 777 /data/app/$j/oat/arm
    rm -rf /data/app/$j/oat/arm/*
  fi
  if [ -e /data/app/$j/oat/arm64 ]; then
    chmod -R 777 /data/app/$j/oat/arm64
    rm -rf /data/app/$j/oat/arm64/*
  fi
done

echo " done!"

################################################

echo -n "Remove some app specific files......"

# App specific
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

echo " done!"

################################################

echo -n "Remove empty directories............"

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

echo

My setup now:
Oxygen 9.05 firmware
op3_recovery 3.3.1-0 from @anupritaisno1
Lineage OS 16
Flash kernel 3.18.140
No Google stuff, using FDroid and Aurora Store as playstores.

The idea was to have a topic where also other people would share their scripts, tweaks etc...
Am I really the only one tweaking a little around??
Attached Thumbnails
Click image for larger version

Name:	Screenshot_20190908-100934_Instellingen.png
Views:	214
Size:	47.4 KB
ID:	4816712   Click image for larger version

Name:	Screenshot_20190908-101001_Instellingen.png
Views:	212
Size:	121.9 KB
ID:	4816713   Click image for larger version

Name:	Screenshot_20190908-101120_LineageOS-instellingen.png
Views:	210
Size:	111.5 KB
ID:	4816714  
The Following 3 Users Say Thank You to For This Useful Post: [ View ] Gift Ad-Free
13th September 2019, 10:53 PM |#6  
anupritaisno1's Avatar
Senior Member
Thanks Meter: 1,711
 
More
Quote:
Originally Posted by 2Tweak

Am I really the only one tweaking a little around??

Seems so

Instead of disabling fsync try raising the fsync interval

The default is 5 seconds. Most filesystems will allow up to 300

It can be changed as:
Code:
mount -o commit=300,remount /data
Remember the higher you set it the higher the chance of data loss in case of system failure
Some filesystems will warn you in dmesg if you set the commit interval too high
The Following User Says Thank You to anupritaisno1 For This Useful Post: [ View ] Gift anupritaisno1 Ad-Free
GuestK00264
13th September 2019, 11:38 PM |#7  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by anupritaisno1

Seems so

Instead of disabling fsync try raising the fsync interval

The default is 5 seconds. Most filesystems will allow up to 300

It can be changed as:

Code:
mount -o commit=300,remount /data
Remember the higher you set it the higher the chance of data loss in case of system failure
Some filesystems will warn you in dmesg if you set the commit interval too high

Thanks, will give it a try.
14th September 2019, 02:28 AM |#8  
Member
Thanks Meter: 21
 
More
Quote:
Originally Posted by 2Tweak

Am I really the only one tweaking a little around??

I can think of some reasons:
- many people are over the use of scripts and just flash one of the magic magisk modules (up to debate if they are useful and if at all which of them)
- Lack of understanding which stuff is save to remove and what breaks if you do so (I struggle with this point myself) Maybe there is a neat list what the removed apks do? I mean most are pretty self explaining but not all.

Maybe my response is useless because I might not be part of the target audience but I'm still very grateful that you took your time to set up this thread and that you shared your findings and thoughts with us. I learned some new things by visiting this thread :)
The Following User Says Thank You to SenseSei For This Useful Post: [ View ] Gift SenseSei Ad-Free
GuestK00264
17th September 2019, 01:50 PM |#9  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by SenseSei

I can think of some reasons:
- many people are over the use of scripts and just flash one of the magic magisk modules (up to debate if they are useful and if at all which of them)
- Lack of understanding which stuff is save to remove and what breaks if you do so (I struggle with this point myself) Maybe there is a neat list what the removed apks do? I mean most are pretty self explaining but not all.

Maybe my response is useless because I might not be part of the target audience but I'm still very grateful that you took your time to set up this thread and that you shared your findings and thoughts with us. I learned some new things by visiting this thread

Thanks for your response SenseSei, nice to hear you have learned something!
That is how it works, with sharing information we all benefit!

I understand your comment about some kind of neat list of what apk's are doing.
In fact I have searched the internet a lot, but did not keep a list with explanations...
When I see an apk which is not on my list already and I do not know what it is doing, I simply search on the internet.
Then I can make my decision to remove it or not, test if it is not breaking other parts and add it to my list or not.

I was planning to switch to Glassrom last weekend, but because I am very happy with my Lineage installation at the moment AND Android 10 is on it's way, I have decided to keep using Lineage till the switch to 10.
This also means I switched back to my old behaviour; one script with removal of apk's, some tweaks in build.prop and userinit.sh and the deep clean included.
Keep in mind it is not wise to use this every day, Android need's time to settle and using this script every day will result in higher drain and wearage of your drive.

Some small things added / changed. For example I included the remount with raised fsync interval for /data instead of disabling fsync completely; a tip of @anupritaisno1. Based on some tips from him the script is also changed a little; removed some spaces and added quotes to improve riability. Font removal is back, though more fonts are kept to keep special characters in for example the weather app I am using. I added the removal of the live display stuff again because I am not using it. The 'PIS'-error is solved though, so therefor you do not need the live display removal anymore.

My setup still is:
- Firmware 9.05
- TWRP from anupritaisno1
- Lineage 16 latest nightly
- Flash kernel 3.18.140 latest (hardened kernel; fast, secure and stable)
- No Google stuff, using FDroid and AuroraStore for app installs and updates

Code:
#!/sbin/sh
#
# Script by 2Tweak
# Last modified 17-09-2019

################################################

# First setup
clear

echo
echo "##########################################"
echo "#         LINEAGE CLEANUP SCRIPT         #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
AntHalService
AudioFX
BackupRestoreConfirmation
BasicDreams
BluetoothMidiService
BookmarkProvider
BuiltInPrintService
Calendar
CaptivePortalLogin
CNEService
CallLogBackup
CellBroadcastReceiver
CompanionDeviceManager
com.qualcomm.location
Contacts
CtsShimPrebuilt
CtsShimPrivPrebuilt
Development
DocumentsUI
EasterEgg
Eleven
Email
ExactCalculator
Exchange2
Gallery2
HTMLViewer
InputDevices
Jelly
LineageSetupWizard
LiveWallpapersPicker
LockClock
ManagedProvisioning
OneTimeInitializer
OneplusDoze
OneplusPocketMode
PhotoTable
PrintRecommendationService
SharedStorageBackup
SimAppDialog
Stk
Tag
Terminal
Traceur
Updater
UserDictionaryProvider
VpnDialogs
WallpaperBackup
WallpaperCropper
WeatherProvider
WfdService
"

for appname in $applist
do
  if [ -e /system/app/"$appname" ]; then
    chmod -R 777 /system/app/"$appname"
    rm -rf /system/app/"$appname"
  fi
  if [ -e /system/priv-app/"$appname" ]; then
    chmod -R 777 /system/priv-app/"$appname"
    rm -rf /system/priv-app/"$appname"
  fi
done

echo " done!"

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
/cache
/data/anr
/data/backup
/data/cache
/data/dalvik-cache
/data/lineageos_updates
/data/local/tmp
/data/lost+found
/data/misc/bootstat
/data/ota
/data/ota_package
/data/resource-cache
/data/system/batterystats.bin
/data/system/dropbox
/data/system/graphicsstats
/data/system/install_sessions.xml
/data/system/last-fstrim
/data/system/package_cache
/data/system/procstats
/data/system/syncmanager-log
/data/system/uiderrors.txt
/data/system/usagestats/0/daily
/data/system/usagestats/0/monthly
/data/system/usagestats/0/weekly
/data/system/usagestats/0/yearly
/data/tombstones
/system/bin/bootanimation
/system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d "$filename" ]; then
    chmod -R 777 "$filename"
    rm -rf "${filename:?}"/*
  fi
  if [ -f "$filename" ]; then
    chmod 777 "$filename"
    rm -f "$filename"
  fi
done

# Remove bak, log, tmp files
find /data -iname "*.bak" -iname "*.log" -iname "*.tmp" -iname "*.odex" -iname "*.vdex" -type f -exec rm -f {} +
find /system -iname "*.bak" -iname "*.log" -iname "*.tmp" -type f -exec rm -f {} +

# Reduce fonts to the bare minimum
find /system/fonts ! -iname "*roboto*.*" ! -name "DroidSansMono.ttf" ! -name "NotoColorEmoji.ttf" -name "NotoSansSymbols-Regular-Subsetted*.ttf" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz
rm -rf /system/vendor/overlay

echo " done!"

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
  if [ -e /data/data/"$i"/cache ]; then
    chmod -R 777 /data/data/"$i"/cache
    rm -rf /data/data/"$i"/cache/*
  fi
  if [ -e /data/data/"$i"/code_cache ]; then
    chmod -R 777 /data/data/"$i"/code_cache
    rm -rf /data/data/"$i"/code_cache/*
  fi
  if [ -e /data/data/"$i"/files/.Fabric ]; then
    chmod -R 777 /data/data/"$i"/files/.Fabric
    rm -rf /data/data/"$i"/files/.Fabric/*
  fi
  if [ -e /data/data/"$i"/files/cache ]; then
    chmod -R 777 /data/data/"$i"/files/cache
    rm -rf /data/data/"$i"/files/cache/*
  fi
  if [ -e /data/data/"$i"/app_webview ]; then
    chmod -R 777 /data/data/"$i"/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/"$i"/app_webview/Cookies ]; then
      mv -f /data/data/"$i"/app_webview/Cookies /data/local/tmp/"$i".Cookies
    fi
    rm -rf /data/data/"$i"/app_webview/*
    if [ -e /data/local/tmp/"$i".Cookies ]; then
      mv -f /data/local/tmp/"$i".Cookies /data/data/"$i"/app_webview/Cookies
    fi
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/"$k"/cache ]; then
    chmod -R 777 /sdcard/Android/data/"$k"/cache
    rm -rf /sdcard/Android/data/"$k"/cache/*
  fi
done

echo " done!"

################################################

echo -n "Cleaning app oat files.............."

for j in $(ls /data/app/)
do
  if [ -e /data/app/"$j"/oat/arm ]; then
    chmod -R 777 /data/app/"$j"/oat/arm
    rm -rf /data/app/"$j"/oat/arm/*
  fi
  if [ -e /data/app/"$j"/oat/arm64 ]; then
    chmod -R 777 /data/app/"$j"/oat/arm64
    rm -rf /data/app/"$j"/oat/arm64/*
  fi
done

echo " done!"

################################################

echo -n "Remove some app specific files......"

# App specific
rm -rf /data/data/com.abnamro.nl.mobile.payments/app_dex/oat/arm64/*
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 "$i" "VACUUM;" 2>/dev/null
  sqlite3 "$i" "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 "$i" "VACUUM;" 2>/dev/null
  sqlite3 "$i" "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Remove live display functionality..."

rm -f '/system/vendor/bin/hw/[email protected]'
rm -f '/system/vendor/etc/init/[email protected]'
fname="/system/vendor/etc/vintf/manifest.xml"

found=0
startstop=0
tstr=""
nstr=""
IFS=$'\n'
while read line
do
  if [[ "$line" == *'<hal'* ]]; then
    startstop=1
  elif [[ "$line" == *'</hal'* ]]; then
    startstop=2
  elif [[ "$line" == *'livedisplay'* ]]; then
    found=1
  fi
  if [ $startstop -eq 1 ]; then
    tstr="${tstr}\n${line}"
  elif [ $startstop -eq 2 ]; then
    tstr="${tstr}\n${line}"
    if [ $found -eq 0 ]; then
      nstr="${nstr}${tstr}"
    else
      found=0
    fi
    tstr=""
    startstop=0
  else
    if [ "$nstr" == "" ]; then
      nstr="${line}"
    else
      nstr="${nstr}\n${line}"
    fi
  fi
done <"$fname"

echo $nstr > $fname

echo " done!"

################################################

echo -n "Remove empty directories............"

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging
logcat.live=disable

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Disable ring delay
ro.telephony.call_ring.delay=0
ring.delay=0

# Remove fps limit
debug.gr.swapinterval=0

# Disable dithering
persist.sys.use_dithering=0

# Disable scrolling cache
persist.sys.scrollingcache=4

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

# Instead of disabling fsync remount with higher fsync interval
mount -o remount,rw,commit=300 /data

# Enable power_efficient workqueue
chmod 666 /sys/module/workqueue/parameters/power_efficient
echo 1 > /sys/module/workqueue/parameters/power_efficient
chmod 444 /sys/module/workqueue/parameters/power_efficient

# Disable iostats
chmod 666 /sys/block/sda/queue/iostats
echo "0" > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# When there, use Boeffla to disable some wakelocks
if [ -e /sys/devices/virtual/misc/boeffla_wakelock_blocker ]; then
  echo "IPA_WS;NETLINK;bms;netmgr_wl;qcom_rx_wakelock;sensor_SMD;wlan;wlan_extscan_wl;wlan_ipa;wlan_pno_wl;wlan_wow_wl" > /sys/devices/virtual/misc/boeffla_wakelock_blocker/wakelock_blocker
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"

echo
The Following User Says Thank You to For This Useful Post: [ View ] Gift Ad-Free
17th September 2019, 06:29 PM |#10  
anupritaisno1's Avatar
Senior Member
Thanks Meter: 1,711
 
More
Quote:
Originally Posted by 2Tweak

Thanks for your response SenseSei, nice to hear you have learned something!
That is how it works, with sharing information we all benefit!

I understand your comment about some kind of neat list of what apk's are doing.
In fact I have searched the internet a lot, but did not keep a list with explanations...
When I see an apk which is not on my list already and I do not know what it is doing, I simply search on the internet.
Then I can make my decision to remove it or not, test if it is not breaking other parts and add it to my list or not.

I was planning to switch to Glassrom last weekend, but because I am very happy with my Lineage installation at the moment AND Android 10 is on it's way, I have decided to keep using Lineage till the switch to 10.
This also means I switched back to my old behaviour; one script with removal of apk's, some tweaks in build.prop and userinit.sh and the deep clean included.
Keep in mind it is not wise to use this every day, Android need's time to settle and using this script every day will result in higher drain and wearage of your drive.

Some small things added / changed. For example I included the remount with raised fsync interval for /data instead of disabling fsync completely; a tip of @anupritaisno1. Based on some tips from him the script is also changed a little; removed some spaces and added quotes to improve riability. Font removal is back, though more fonts are kept to keep special characters in for example the weather app I am using. I added the removal of the live display stuff again because I am not using it. The 'PIS'-error is solved though, so therefor you do not need the live display removal anymore.

My setup still is:
- Firmware 9.05
- TWRP from anupritaisno1
- Lineage 16 latest nightly
- Flash kernel 3.18.140 latest (hardened kernel; fast, secure and stable)
- No Google stuff, using FDroid and AuroraStore for app installs and updates

Code:
#!/sbin/sh
#
# Script by 2Tweak
# Last modified 17-09-2019

################################################

# First setup
clear

echo
echo "##########################################"
echo "#         LINEAGE CLEANUP SCRIPT         #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
AntHalService
AudioFX
BackupRestoreConfirmation
BasicDreams
BluetoothMidiService
BookmarkProvider
BuiltInPrintService
Calendar
CaptivePortalLogin
CNEService
CallLogBackup
CellBroadcastReceiver
CompanionDeviceManager
com.qualcomm.location
Contacts
CtsShimPrebuilt
CtsShimPrivPrebuilt
Development
DocumentsUI
EasterEgg
Eleven
Email
ExactCalculator
Exchange2
Gallery2
HTMLViewer
InputDevices
Jelly
LineageSetupWizard
LiveWallpapersPicker
LockClock
ManagedProvisioning
OneTimeInitializer
OneplusDoze
OneplusPocketMode
PhotoTable
PrintRecommendationService
SharedStorageBackup
SimAppDialog
Stk
Tag
Terminal
Traceur
Updater
UserDictionaryProvider
VpnDialogs
WallpaperBackup
WallpaperCropper
WeatherProvider
WfdService
"

for appname in $applist
do
  if [ -e /system/app/"$appname" ]; then
    chmod -R 777 /system/app/"$appname"
    rm -rf /system/app/"$appname"
  fi
  if [ -e /system/priv-app/"$appname" ]; then
    chmod -R 777 /system/priv-app/"$appname"
    rm -rf /system/priv-app/"$appname"
  fi
done

echo " done!"

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
/cache
/data/anr
/data/backup
/data/cache
/data/dalvik-cache
/data/lineageos_updates
/data/local/tmp
/data/lost+found
/data/misc/bootstat
/data/ota
/data/ota_package
/data/resource-cache
/data/system/batterystats.bin
/data/system/dropbox
/data/system/graphicsstats
/data/system/install_sessions.xml
/data/system/last-fstrim
/data/system/package_cache
/data/system/procstats
/data/system/syncmanager-log
/data/system/uiderrors.txt
/data/system/usagestats/0/daily
/data/system/usagestats/0/monthly
/data/system/usagestats/0/weekly
/data/system/usagestats/0/yearly
/data/tombstones
/system/bin/bootanimation
/system/media/bootanimation.zip
"

for filename in $filelist
do
  if [ -d "$filename" ]; then
    chmod -R 777 "$filename"
    rm -rf "${filename:?}"/*
  fi
  if [ -f "$filename" ]; then
    chmod 777 "$filename"
    rm -f "$filename"
  fi
done

# Remove bak, log, tmp files
find /data -iname "*.bak" -iname "*.log" -iname "*.tmp" -iname "*.odex" -iname "*.vdex" -type f -exec rm -f {} +
find /system -iname "*.bak" -iname "*.log" -iname "*.tmp" -type f -exec rm -f {} +

# Reduce fonts to the bare minimum
find /system/fonts ! -iname "*roboto*.*" ! -name "DroidSansMono.ttf" ! -name "NotoColorEmoji.ttf" -name "NotoSansSymbols-Regular-Subsetted*.ttf" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz
rm -rf /system/vendor/overlay

echo " done!"

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
  if [ -e /data/data/"$i"/cache ]; then
    chmod -R 777 /data/data/"$i"/cache
    rm -rf /data/data/"$i"/cache/*
  fi
  if [ -e /data/data/"$i"/code_cache ]; then
    chmod -R 777 /data/data/"$i"/code_cache
    rm -rf /data/data/"$i"/code_cache/*
  fi
  if [ -e /data/data/"$i"/files/.Fabric ]; then
    chmod -R 777 /data/data/"$i"/files/.Fabric
    rm -rf /data/data/"$i"/files/.Fabric/*
  fi
  if [ -e /data/data/"$i"/files/cache ]; then
    chmod -R 777 /data/data/"$i"/files/cache
    rm -rf /data/data/"$i"/files/cache/*
  fi
  if [ -e /data/data/"$i"/app_webview ]; then
    chmod -R 777 /data/data/"$i"/app_webview
    # keep cookies for webapp logins
    if [ -e /data/data/"$i"/app_webview/Cookies ]; then
      mv -f /data/data/"$i"/app_webview/Cookies /data/local/tmp/"$i".Cookies
    fi
    rm -rf /data/data/"$i"/app_webview/*
    if [ -e /data/local/tmp/"$i".Cookies ]; then
      mv -f /data/local/tmp/"$i".Cookies /data/data/"$i"/app_webview/Cookies
    fi
  fi
done

for k in $(ls /sdcard/Android/data/)
do
  if [ -e /sdcard/Android/data/"$k"/cache ]; then
    chmod -R 777 /sdcard/Android/data/"$k"/cache
    rm -rf /sdcard/Android/data/"$k"/cache/*
  fi
done

echo " done!"

################################################

echo -n "Cleaning app oat files.............."

for j in $(ls /data/app/)
do
  if [ -e /data/app/"$j"/oat/arm ]; then
    chmod -R 777 /data/app/"$j"/oat/arm
    rm -rf /data/app/"$j"/oat/arm/*
  fi
  if [ -e /data/app/"$j"/oat/arm64 ]; then
    chmod -R 777 /data/app/"$j"/oat/arm64
    rm -rf /data/app/"$j"/oat/arm64/*
  fi
done

echo " done!"

################################################

echo -n "Remove some app specific files......"

# App specific
rm -rf /data/data/com.abnamro.nl.mobile.payments/app_dex/oat/arm64/*
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 "$i" "VACUUM;" 2>/dev/null
  sqlite3 "$i" "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
  sqlite3 "$i" "VACUUM;" 2>/dev/null
  sqlite3 "$i" "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Remove live display functionality..."

rm -f '/system/vendor/bin/hw/[email protected]'
rm -f '/system/vendor/etc/init/[email protected]'
fname="/system/vendor/etc/vintf/manifest.xml"

found=0
startstop=0
tstr=""
nstr=""
IFS=$'\n'
while read line
do
  if [[ "$line" == *'<hal'* ]]; then
    startstop=1
  elif [[ "$line" == *'</hal'* ]]; then
    startstop=2
  elif [[ "$line" == *'livedisplay'* ]]; then
    found=1
  fi
  if [ $startstop -eq 1 ]; then
    tstr="${tstr}\n${line}"
  elif [ $startstop -eq 2 ]; then
    tstr="${tstr}\n${line}"
    if [ $found -eq 0 ]; then
      nstr="${nstr}${tstr}"
    else
      found=0
    fi
    tstr=""
    startstop=0
  else
    if [ "$nstr" == "" ]; then
      nstr="${line}"
    else
      nstr="${nstr}\n${line}"
    fi
  fi
done <"$fname"

echo $nstr > $fname

echo " done!"

################################################

echo -n "Remove empty directories............"

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging
logcat.live=disable

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Disable ring delay
ro.telephony.call_ring.delay=0
ring.delay=0

# Remove fps limit
debug.gr.swapinterval=0

# Disable dithering
persist.sys.use_dithering=0

# Disable scrolling cache
persist.sys.scrollingcache=4

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
  sqlite3 $i "VACUUM;" 2>/dev/null
  sqlite3 $i "REINDEX;" 2>/dev/null
done

# Instead of disabling fsync remount with higher fsync interval
mount -o remount,rw,commit=300 /data

# Enable power_efficient workqueue
chmod 666 /sys/module/workqueue/parameters/power_efficient
echo 1 > /sys/module/workqueue/parameters/power_efficient
chmod 444 /sys/module/workqueue/parameters/power_efficient

# Disable iostats
chmod 666 /sys/block/sda/queue/iostats
echo "0" > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# When there, use Boeffla to disable some wakelocks
if [ -e /sys/devices/virtual/misc/boeffla_wakelock_blocker ]; then
  echo "IPA_WS;NETLINK;bms;netmgr_wl;qcom_rx_wakelock;sensor_SMD;wlan;wlan_extscan_wl;wlan_ipa;wlan_pno_wl;wlan_wow_wl" > /sys/devices/virtual/misc/boeffla_wakelock_blocker/wakelock_blocker
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"

echo

Fixed it some more

Code:
# Script by 2Tweak
# Last modified 17-09-2019

################################################

# First setup
clear

echo
echo "##########################################"
echo "#         LINEAGE CLEANUP SCRIPT         #"
echo "##########################################"
echo

mount -o remount,rw /cache
mount -o remount,rw /data
mount -o remount,rw /sdcard
mount -o remount,rw /system

################################################

echo -n "Shrinking ROM to the bare minimum..."

# app list to remove
applist="
AntHalService
AudioFX
BackupRestoreConfirmation
BasicDreams
BluetoothMidiService
BookmarkProvider
BuiltInPrintService
Calendar
CaptivePortalLogin
CNEService
CallLogBackup
CellBroadcastReceiver
CompanionDeviceManager
com.qualcomm.location
Contacts
CtsShimPrebuilt
CtsShimPrivPrebuilt
Development
DocumentsUI
EasterEgg
Eleven
Email
ExactCalculator
Exchange2
Gallery2
HTMLViewer
InputDevices
Jelly
LineageSetupWizard
LiveWallpapersPicker
LockClock
ManagedProvisioning
OneTimeInitializer
OneplusDoze
OneplusPocketMode
PhotoTable
PrintRecommendationService
SharedStorageBackup
SimAppDialog
Stk
Tag
Terminal
Traceur
Updater
UserDictionaryProvider
VpnDialogs
WallpaperBackup
WallpaperCropper
WeatherProvider
WfdService
"

for appname in $applist
do
        if [ -e /system/app/"$appname" ]; then
                chmod -R 777 /system/app/"$appname"
                rm -rf /system/app/"$appname"
        fi
        if [ -e /system/priv-app/"$appname" ]; then
                chmod -R 777 /system/priv-app/"$appname"
                rm -rf /system/priv-app/"$appname"
        fi
done

echo " done!"

################################################

echo -n "Removing unneeded and junk files...."

# file list to cleanup
filelist="
/cache
/data/anr
/data/backup
/data/cache
/data/dalvik-cache
/data/lineageos_updates
/data/local/tmp
/data/lost+found
/data/misc/bootstat
/data/ota
/data/ota_package
/data/resource-cache
/data/system/batterystats.bin
/data/system/dropbox
/data/system/graphicsstats
/data/system/install_sessions.xml
/data/system/last-fstrim
/data/system/package_cache
/data/system/procstats
/data/system/syncmanager-log
/data/system/uiderrors.txt
/data/system/usagestats/0/daily
/data/system/usagestats/0/monthly
/data/system/usagestats/0/weekly
/data/system/usagestats/0/yearly
/data/tombstones
/system/bin/bootanimation
/system/media/bootanimation.zip
"

for filename in $filelist
do
        if [ -d "$filename" ]; then
                chmod -R 777 "$filename"
                rm -rf "${filename:?}"/*
        fi
        if [ -f "$filename" ]; then
                chmod 777 "$filename"
                rm -f "$filename"
        fi
done

# Remove bak, log, tmp files
find /data -iname "*.bak" -iname "*.log" -iname "*.tmp" -iname "*.odex" -iname "*.vdex" -type f -exec rm -f {} +
find /system -iname "*.bak" -iname "*.log" -iname "*.tmp" -type f -exec rm -f {} +

# Reduce fonts to the bare minimum
find /system/fonts ! -iname "*roboto*.*" ! -name "DroidSansMono.ttf" ! -name "NotoColorEmoji.ttf" -name "NotoSansSymbols-Regular-Subsetted*.ttf" -type f -exec rm -f {} +

# Some other useless system related files
rm -f /data/stock_boot_*.img.gz
rm -rf /system/vendor/overlay

echo " done!"

################################################

echo -n "Cleaning app data..................."

for i in $(ls /data/data/)
do
        if [ -e /data/data/"$i"/cache ]; then
                chmod -R 777 /data/data/"$i"/cache
                rm -rf /data/data/"$i"/cache/*
        fi
        if [ -e /data/data/"$i"/code_cache ]; then
                chmod -R 777 /data/data/"$i"/code_cache
                rm -rf /data/data/"$i"/code_cache/*
        fi
        if [ -e /data/data/"$i"/files/.Fabric ]; then
                chmod -R 777 /data/data/"$i"/files/.Fabric
                rm -rf /data/data/"$i"/files/.Fabric/*
        fi
        if [ -e /data/data/"$i"/files/cache ]; then
                chmod -R 777 /data/data/"$i"/files/cache
                rm -rf /data/data/"$i"/files/cache/*
        fi
        if [ -e /data/data/"$i"/app_webview ]; then
                chmod -R 777 /data/data/"$i"/app_webview
                # keep cookies for webapp logins
                if [ -e /data/data/"$i"/app_webview/Cookies ]; then
                        mv -f /data/data/"$i"/app_webview/Cookies /data/local/tmp/"$i".Cookies
                fi
                rm -rf /data/data/"$i"/app_webview/*
                if [ -e /data/local/tmp/"$i".Cookies ]; then
                        mv -f /data/local/tmp/"$i".Cookies /data/data/"$i"/app_webview/Cookies
                fi
        fi
done

for k in $(ls /sdcard/Android/data/)
do
        if [ -e /sdcard/Android/data/"$k"/cache ]; then
                chmod -R 777 /sdcard/Android/data/"$k"/cache
                rm -rf /sdcard/Android/data/"$k"/cache/*
        fi
done

echo " done!"

################################################

echo -n "Cleaning app oat files.............."

for j in $(ls /data/app/)
do
        if [ -e /data/app/"$j"/oat/arm ]; then
                chmod -R 777 /data/app/"$j"/oat/arm
                rm -rf /data/app/"$j"/oat/arm/*
        fi
        if [ -e /data/app/"$j"/oat/arm64 ]; then
                chmod -R 777 /data/app/"$j"/oat/arm64
                rm -rf /data/app/"$j"/oat/arm64/*
        fi
done

echo " done!"

################################################

echo -n "Remove some app specific files......"

# App specific
rm -rf /data/data/com.abnamro.nl.mobile.payments/app_dex/oat/arm64/*
rm -rf /data/data/org.fdroid.fdroid/files/*.apk
rm -rf /data/data/org.videolan.vlc/app_vlc/*

echo " done!"

################################################

echo -n "Optimizing app databases............"

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
        sqlite3 "$i" "VACUUM;" 2>/dev/null
        sqlite3 "$i" "REINDEX;" 2>/dev/null
done

for i in $(find /sdcard -iname "*.db" -type f)
do
        sqlite3 "$i" "VACUUM;" 2>/dev/null
        sqlite3 "$i" "REINDEX;" 2>/dev/null
done

echo " done!"

################################################

echo -n "Remove live display functionality..."

rm -f '/system/vendor/bin/hw/[email protected]'
rm -f '/system/vendor/etc/init/[email protected]'
fname="/system/vendor/etc/vintf/manifest.xml"

found=0
startstop=0
tstr=""
nstr=""
IFS=$'\n'
while read line
do
        if [[ "$line" == *'<hal'* ]]; then
                startstop=1
        elif [[ "$line" == *'</hal'* ]]; then
                startstop=2
        elif [[ "$line" == *'livedisplay'* ]]; then
                found=1
        fi
        if [ $startstop -eq 1 ]; then
                tstr="${tstr}\n${line}"
        elif [ $startstop -eq 2 ]; then
                tstr="${tstr}\n${line}"
                if [ $found -eq 0 ]; then
                        nstr="${nstr}${tstr}"
                else
                        found=0
                fi
                tstr=""
                startstop=0
        else
                if [ "$nstr" == "" ]; then
                        nstr="${line}"
                else
                        nstr="${nstr}\n${line}"
                fi
        fi
done <"$fname"

echo "$nstr" > $fname

echo " done!"

################################################

echo -n "Remove empty directories............"

# Remove empty directories
find /data/data -type d -depth -exec rmdir {} + 2>/dev/null
find /sdcard -type d -depth -exec rmdir {} + 2>/dev/null

echo " done!"

################################################

echo -n "Setting log permissions read-only..."

chmod 000 /data/tombstones
chmod 000 /data/system/dropbox
chmod 000 /data/system/graphicsstats
chmod 000 /data/system/procstats
chmod 000 /data/system/usagestats/0/daily
chmod 000 /data/system/usagestats/0/weekly
chmod 000 /data/system/usagestats/0/monthly
chmod 000 /data/system/usagestats/0/yearly

echo " done!"

################################################

echo -n "Adding my build.prop settings......."

fname="/system/build.prop"
tmpvar=$(sed '/.*My settings.*/{s///;q;}' $fname | sed '$d')
echo "$tmpvar" > $fname
echo '
# My settings

# Disable multi user
fw.max_users=1
fw.show_multiuserui=0
fw.show_hidden_users=0
fw.power_user_switcher=0

# Disable logging
logcat.live=disable

# Disable boot animation
debug.sf.nobootanimation=1

# Disable USB debugging notification
persist.adb.notify=0

# Disable ring delay
ro.telephony.call_ring.delay=0
ring.delay=0

# Remove fps limit
debug.gr.swapinterval=0

# Disable dithering
persist.sys.use_dithering=0

# Disable scrolling cache
persist.sys.scrollingcache=4

# End of my settings
' >> $fname
chmod 644 $fname

echo " done!"

################################################

echo -n "Adding my gps.conf settings........."

rm -f /system/vendor/etc/gps.conf
touch /system/vendor/etc/gps.conf
echo '# My settings

# NTP Server - only one allowed!
NTP_SERVER=nl.pool.ntp.org

# Debug level
DEBUG_LEVEL=0

# End of my settings
' > /system/vendor/etc/gps.conf
chmod 644 /system/vendor/etc/gps.conf

echo " done!"

################################################

echo -n "Adding my userinit.sh settings......"

echo '#!/system/bin/sh
# My settings

# Optimize databases
for i in $(find /data -iname "*.db" -type f)
do
        sqlite3 $i "VACUUM;" 2>/dev/null
        sqlite3 $i "REINDEX;" 2>/dev/null
done

for i in $(find /storage/emulated/0 -iname "*.db" -type f)
do
        sqlite3 $i "VACUUM;" 2>/dev/null
        sqlite3 $i "REINDEX;" 2>/dev/null
done

# Instead of disabling fsync remount with higher fsync interval
mount -o remount,rw,commit=300 /data

# Enable power_efficient workqueue
chmod 666 /sys/module/workqueue/parameters/power_efficient
echo 1 > /sys/module/workqueue/parameters/power_efficient
chmod 444 /sys/module/workqueue/parameters/power_efficient

# Disable iostats
chmod 666 /sys/block/sda/queue/iostats
echo "0" > /sys/block/sda/queue/iostats
chmod 444 /sys/block/sda/queue/iostats

# When there, use Boeffla to disable some wakelocks
if [ -e /sys/devices/virtual/misc/boeffla_wakelock_blocker ]; then
        echo "IPA_WS;NETLINK;bms;netmgr_wl;qcom_rx_wakelock;sensor_SMD;wlan;wlan_extscan_wl;wlan_ipa;wlan_pno_wl;wlan_wow_wl" > /sys/devices/virtual/misc/boeffla_wakelock_blocker/wakelock_blocker
fi

# End of my settings
' > /data/local/userinit.sh
chmod 777 /data/local/userinit.sh

echo " done!"

echo
The Following User Says Thank You to anupritaisno1 For This Useful Post: [ View ] Gift anupritaisno1 Ad-Free
GuestK00264
17th September 2019, 07:16 PM |#11  
Guest
Thanks Meter: 0
 
More
Quote:
Originally Posted by anupritaisno1

Fixed it some more

Code:
<cut>

I compared both scripts, but why did you remove the first two lines?
Further you added quotes for the echo command:
Code:
echo "$nstr" > $fname
which is indeed a good one; thanks!
Further any changes?
Post Reply Subscribe to Thread

Tags
build.prop, cleanup, script, tweak, userinit.sh

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes