How to flash an Android phone

Albert De La Fuente Vigliotti

Android flashing #

Requirements and assumptions #

Adapted from: https://wiki.lineageos.org/devices/d802/upgrade

  • The phone has already TWRP as bootloader
  • Latest TWRP is already installed
  • ROM in zip file (latest)
  • The memory is already wiped

Flash a new rom #

  # Paths. EDIT THIS
  FILES_PATH=/mnt/afuse/nas/share/os/android/lg-g2

  # Reboot in recovery
  adb reboot recovery
  sleep 60

  # Flash files
  adb push $FILES_PATH/lineage-16.0-*.zip /sdcard/lineage16.zip
  adb push $FILES_PATH/addonsu-16.0-arm64-*.zip /sdcard/addonsu16.zip
  adb push contacts.vcf /sdcard/contacts.vcf

Manually flash both files #

  • DONT allow “automatically” install anything

Enable ADB on device #

  • Security & location / Encryption & credentials / encrypt phone
  • About phone / Build number: Hit 7 times the build number
  • System / Developer options /
    • Debugging / Android Debugging (ADB): enabled
    • root access: Apps and ADB
  • USB preferences: File Transfer
  • Plug the USB cable

Base apps #

Check: https://www.reddit.com/r/fdroid/comments/abvx5i/best%5Fapps%5Fon%5Ffdroid/

wget -P $HOME/dropsync/appdata/android/baseapps/ https://f-droid.org/F-Droid.apk wget -P $HOME/dropsync/appdata/android/baseapps/ https://f-droid.org/repo/org.fdroid.fdroid.privileged%5F2120.apk wget -P $HOME/dropsync/appdata/android/baseapps/ https://f-droid.org/repo/com.aurora.adroid%5F8.apk wget -P $HOME/dropsync/appdata/android/baseapps/ https://f-droid.org/repo/com.aurora.store%5F38.apk

#wget -P $HOME/dropsync/appdata/android/baseapps/ https://f-droid.org/repo/net.sourceforge.opencamera%5F80.apk

wget -P $HOME/dropsync/appdata/android/baseapps/ https://f-droid.org/repo/com.machiav3lli.backup%5F6001.apk

  https://f-droid.org/repo/com.artifex.mupdf.viewer.app_90.apk
  https://f-droid.org/repo/dev.ukanth.ufirewall_20210517.apk
  https://f-droid.org/repo/com.termux_117.apk
  https://f-droid.org/repo/org.galexander.sshd_27.apk
  https://f-droid.org/repo/com.ghostsq.commander_396.apk
  https://f-droid.org/repo/com.ghostsq.commander.samba_73.apk
  https://f-droid.org/repo/com.ghostsq.commander.sftp_37.apk
  https://f-droid.org/repo/net.typeblog.shelter_17.apk
  https://f-droid.org/repo/com.tobykurien.webapps_41.apk
  https://f-droid.org/repo/com.etesync.syncadapter_20204.apk
  https://f-droid.org/repo/com.github.ashutoshgngwr.noice_41.apk
  https://f-droid.org/repo/com.vincent_falzon.discreetlauncher_32.apk

  https://f-droid.org/repo/org.fdroid.fdroid.privileged_2120.apk
  https://f-droid.org/repo/org.videolan.vlc_13030408.apk
  https://f-droid.org/repo/cityfreqs.com.pilfershushjammer_41.apk
  #https://f-droid.org/repo/com.anysoftkeyboard.languagepack.SSH_4.apk
  #https://f-droid.org/repo/com.anysoftkeyboard.languagepack.portuguese_101.apk
  https://f-droid.org/repo/com.tengu.sharetoclipboard_29.apk
  https://f-droid.org/repo/de.ph1b.audiobook_3060342.apk
  https://f-droid.org/repo/dummydomain.yetanothercallblocker_5150.apk
  https://f-droid.org/repo/org.secuso.privacyfriendlyweather_14.apk
  https://f-droid.org/repo/me.austinhuang.instagrabber_64.apk
  wget -i apps.txt
  find $HOME/dropsync/appdata/android/baseapps/ -maxdepth 1 -type f -name "*.apk" -exec adb install {} \;

Config:

  • Tap to wake: true
  • Display size: smallest
  • Time format
    • Use locale default: false
    • Use 24-hour format: true
  • Other sounds and vibrations
    • All disabled
  • Notification vibration
    • Notification vibration: off
  • Charging sounds
    • Disabled
  • Apps & notifications / Notifications on for all apps / Advanced
    • Default notification sound: None
  # Google Android Device Manager (Keep tracks of device)
  # Google Calendar
  # Google Chrome
  adb install $HOME/dropsync/appdata/android/baseapps/org.mozilla.klar_230.apk

  # Google Clock: not needed
  #adb install $HOME/dropsync/appdata/android/baseapps/opencontacts.open.com.opencontacts_17.apk

  # Google Hangouts / Messenger
  #adb install $HOME/dropsync/appdata/android/baseapps/eu.siacs.conversations_362.apk

  # Google Keep
  #adb install $HOME/dropsync/appdata/android/baseapps/com.orgzly_150.apk

  # Google Mail (Gmail)
  # Google Maps
  #adb install $HOME/dropsync/appdata/android/baseapps/net.osmand.plus_355.apk
  adb install $HOME/dropsync/appdata/android/baseapps/net.osmand.srtmPlugin.paid_9.apk

  # Google PDF Viewer
  #adb install $HOME/dropsync/appdata/android/baseapps/com.artifex.mupdf.viewer.app_70.apk

  # Google Photos
  # Google keyboard
  #adb install $HOME/dropsync/appdata/android/baseapps/org.pocketworkstation.pckeyboard_1041001.apk

  # Google Youtube
  #adb install $HOME/dropsync/appdata/android/baseapps/org.schabi.newpipe_840.apk

  # Dropbox replacement
  adb install $HOME/dropsync/appdata/android/baseapps/com.nutomic.syncthingandroid_4208.apk
  #adb install $HOME/dropsync/appdata/android/baseapps/com.nextcloud.client_30100190.apk

  # VoIP
  #adb install $HOME/dropsync/appdata/android/baseapps/org.linphone_4125.apk

  # System
  #adb install $HOME/dropsync/appdata/android/baseapps/dev.ukanth.ufirewall_19450.apk
  adb install $HOME/dropsync/appdata/android/baseapps/orbot-latest.apk
  #adb install $HOME/dropsync/appdata/android/baseapps/com.termux_92.apk
  #adb install $HOME/dropsync/appdata/android/baseapps/org.galexander.sshd_23.apk
  adb install $HOME/dropsync/appdata/android/baseapps/de.blinkt.openvpn_161.apk
  #adb install $HOME/dropsync/appdata/android/baseapps/com.ghostsq.commander_395.apk
  #adb install $HOME/dropsync/appdata/android/baseapps/dk.jens.backup_305.apk
  adb install $HOME/dropsync/appdata/android/baseapps/Signal-website-universal-release-4.55.8.apk
  #adb install $HOME/dropsync/appdata/android/baseapps/net.typeblog.shelter_13.apk

  Voice recording
  adb install $HOME/dropsync/appdata/android/baseapps/
  Phone call recording
  adb install $HOME/dropsync/appdata/android/baseapps/
  # TESTING
  adb install $HOME/dropsync/appdata/android/baseapps/com.tobykurien.webapps_31.apk
  reddit client
  https://island.oasisfeng.com/setup.html

  # Bible
  #adb install $HOME/dropsync/appdata/android/baseapps/mysword4android-11.0.apk

  # ES
  adb install $HOME/dropsync/appdata/android/baseapps/es/es.unicajamovil_3.1.5.apk
  adb install $HOME/dropsync/appdata/android/baseapps/es/migenerali.6.2.5.apk
  Cajamar
  Sabadell

  # BR
  Meu vivo
  SofisaDireto
  Itau
  Santander
  Neon
  Neon pejota
  Inter empresas

Install the automatic updates “privileged extension” for F-Droid #

  • Reboot in TWRP and push the zip file and flash it
  • Remember to keep unselected all the checkboxes at the end (don’t install the APK!)
  adb push $HOME/dropsync/appdata/android/baseapps/org.fdroid.fdroid.privileged.ota_2110.zip /sdcard/

Rsync #

wget -O rsync.bin http://github.com/pts/rsyncbin/raw/master/rsync.rsync4android adb push rsync.bin /data/local/tmp/rsync adb shell chmod 755 /data/local/tmp/rsync adb shell cp /data/local/tmp/rsync /sdcard/rsync.bin adb shell /data/local/tmp/rsync –version adb shell /system/xbin/rsync –version

Base configs #

  # Disable captive portal ("Connected, no internet")
  adb shell settings put global captive_portal_detection_enabled 0
  adb shell settings put global captive_portal_mode 0
  adb shell settings put global captive_portal_server example.com
  adb shell settings put global captive_portal_https_server "https://example.com"
  adb shell settings put global captive_portal_http_server "http://example.com"

  # Disable watchdog
  adb shell settings put global wifi_watchdog_on 0
  adb shell settings put global wifi_watchdog_background_check_enabled 0

  # Checks: Disable captive portal ("Connected, no internet")
  adb shell settings get global captive_portal_detection_enabled
  adb shell settings get global captive_portal_mode
  adb shell settings get global captive_portal_server
  adb shell settings get global captive_portal_https_server
  adb shell settings get global captive_portal_http_server

  # Checks: Disable watchdog
  adb shell settings get global wifi_watchdog_on
  adb shell settings get global wifi_watchdog_background_check_enabled

Base features #

Encryption

  • Enable it manually. Use at least 6 digits pin passwords
  • Set auto destruction on X failed attempts

Data sync with Nextcould (orgmode, bbdb)

Data sync with EteSync: Based on django sync for contacts, calendar and tasks (orgmode, bbdb?)

Org mode

Access phone over desktop

  • scrcpy

Phone tracking

Computer apps #

pacaur -S scrcpy

Backup using syncthing (instant replication receive only) #

Item App Phone path Nas path
Photos & videos OpenShot /storage/emulated/0/DCIM /share/MD0_DATA/android/oneplus2/Camera
Recorded audios Simple Voice Recorder /storage/emulated/0/Simple Voice Recorder /share/MD0_DATA/android/oneplus2/Simple Voice Recorder
Recorded calls Call recorder /storage/emulated/0/Call Recorder /share/MD0_DATA/android/oneplus2/Call Recorder
Packages backup oandbackup /storage/emulated/0/oandbackup /share/MD0_DATA/android/oneplus2/oandbackup
Whatsapp databases Whatsapp /storage/emulated/0/Whatsapp/Databases /share/MD0_DATA/android/oneplus2/Whatsapp/Databases
Whatsapp media X Whatsapp /storage/emulated/0/Whatsapp/Media/XXX /share/MD0_DATA/android/oneplus2/Whatsapp/Media/X
Telegram Telegram /storage/emulated/0/Telegram /share/MD0_DATA/android/oneplus2/Telegram
TWRP TWRP /storage/emulated/0/TWRP /share/MD0_DATA/android/oneplus2/TWRP
GPS captures OSMAnd storage/emulated/0

Sync syncthing config #

Item App Phone path Nas path
Syncthing (manual) Syncthing /storage/emulated/0/backups/syncthing /share/MD0_DATA/android/oneplus2/syncthing
  adb pull "/storage/emulated/0/contacts.vcf" /mnt/afuse/nas/share/MD0_DATA/android/oneplus2/contacts/contacts-phone-`date +'%Y-%m-%d'`.vcf

Sync contacts #

Item App Phone path Nas path
Contacts (manuel) Contacts
  mv /mnt/afuse/nas/share/MD0_DATA/android/oneplus2/syncthing/*.* /mnt/afuse/nas/share/MD0_DATA/android/oneplus2/syncthing/old
  adb pull "/storage/emulated/0/backups/syncthing" /mnt/afuse/nas/share/MD0_DATA/android/oneplus2/syncthing

adb pull “/storage/emulated/0/contacts-phone.vcf” .

Backup with adb backup (deprecated in the future) #

See: https://www.reddit.com/r/LineageOS/comments/b7i1zx/twrp%5Fvs%5Fadb%5Fbackup%5Fall%5Fvs%5Foandbackup/ See: https://play.google.com/store/apps/details?id=balti.migrate&hl=en%5FUS

  # Variables:
  #PHONE=lg_g2
  PHONE=oneplus_2
  FILES_PATH=/mnt/afuse/nas/share/os/android/$PHONE/backups

  # Reboot in recovery mode with:
  # adb reboot recovery

  adb backup -f $FILES_PATH/`date +'%Y-%m-%d'`.$PHONE.backup.ab --twrp --compress data system boot

  adb reboot system

Backup manually selected apps copied via adb within TWRP #

Also USE

adb pull /data/data/com.excelliance.multiaccounts.b64

Restore manually selected apps copied via adb within TWRP #

adb root adb push com.whatsapp data/data

Backup using tetherback #

  pipenv --three
  pipenv install https://github.com/dlenski/tetherback/archive/0.9.1.zip
  pipenv shell

  adb reboot recovery

  # Dont backup to usb flashdrive since throughput will be around 600kbps. Backup to local fs
  # tetherback -M -P -o /home/av/backup
  tetherback -t -M -D -R -C

Restore using tetherback #

./adb-sync ../tetherback/twrp-backup-2020-05-08–07-53-02 /sdcard

Apps backup / data export #

Contacts WhatsApp YouTube syncthing

Apps data export #

sai
sai
sai
sai
sai
sai
sai
sai

:ID: 62c4091c-7116-4497-88e8-b3f81d186250

Backup using osmandx #

  • Password: qazxcv

Restore using osmandx #

TODO Restore #

See:

  # Variables:
  #PHONE=lg_g2
  PHONE=oneplus_2
  FILES_PATH=/mnt/afuse/nas/share/os/android/$PHONE/backups

  # Reboot in recovery mode with:
  # adb reboot recovery

  adb restore --twrp

Migration #

See: https://forum.xda-developers.com/android/apps-games/app-migrate-custom-rom-migration-tool-t3862763 See: https://play.google.com/store/apps/details?id=balti.migrate&hl=en%5FUS

One plus 2 backup needed for #

  • NOPE Backup with oandbackup / copy files to notebook

In case of lockout of recovery boot mode #

fastboot reboot fastboot devices fastboot oem unlock fastboot flash recovery Downloads/twrp-3.2.1-0-oneplus2.img