Using ADB in Recovery Mode

I don’t have a specific use case for this, but I thought I’d experiment and see just how this can be done.  I’ve recently changed over to encryption on my smartphone, because it came to my attention that it’s possible to use the Android debugger to get access to an Android device’s flash even if you don’t have the unlock pin.  This of course requires physical access to the phone.

This procedure illustrates why it’s a damned good idea to encrypt your phone.

Step 1 – Install ADB

Go to this link and download the Android SDK and install it.  Install to the default location.  Since there’s a good chance you don’t have a 64-bit JDK installed too, go to this link and download the latest JDK for Windows x64.  Install that too.

You’ll probably also have to create a JAVA_HOME environment variable.  That’s described in the first link.

Step 2 – Install SDK Packages

Run Android Studio as Administrator.  Click Configure.  Click SDK Manager.  Click “Deselect All” then “Select Updates”.  Now, tick “Android SDK Platform-tools” under Tools, and “Google USB Driver” under Extras.  Click Install and follow the wizard.  Close the SDK Manager when done.

Close Android Studio.

Step 3 – Connect your device to ADB

Power off the phone, plug it into your computer and power it up in Recovery mode with (this is for a Samsung Galaxy S3) holding down the power button, volume up and menu at the same time.  Let go of the power button when the screen comes on.

If you don’t have a recovery installed, you’ll have to boot into the bootloader (same buttons as above just use volume down instead), and then use Fastboot to install a custom recovery (like CWM or TWRP).

Once in Recovery, go to Device Manager on your PC, and change the driver for the phone.  I used the SAMSUNG Android ADB Interface driver.

Then, fire up a command prompt in Administrator mode, go to “C:\Program Files (x86)\Android\android-studio\sdk\platform-tools” and run “adb shell”

You’re now in a basic recovery shell on the phone.  From here, you can now do pretty well whatever you want – read data, copy stuff off the phone, rewrite the recovery, change the unlock PIN, whatever.

Have fun.  Use your newfound powers for good, not evil.

cm-10.2-20131022-NIGHTLY issues

Upgraded my GT-i9305T to the latest CyanogenMod nightly, and had quite a few issues. Namely, my phone would no longer connect to 3G/4G, and the APN settings were blank.  Trying to re-enter APN settings didn’t work (nothing would go into the APN list!).  I tried rolling back to a previous nightly, but then the phone just kept rebooting.

The solution was to install the nightly above, and then reboot into ClockwordMod and clear the cache.  After I did that and rebooted, my APN settings were normal and I connected to the data network without issues.

Latest CM Nightly with the i9305T

Went and installed the latest nightly for my i9305T.  What I didn’t notice was the nightly is for CyanogenMod 10.2, which is based on Android 4.3 .  Since the version of Google Apps I had installed was for Android 4.2, it went badly.

Anyway, after a lot of sweating, I got the phone all back and running again with no lost data.  The take-home there is, if you install the recent nightlies (eg ) where they are CM 10.2, you have to also install the latest Google Apps (eg ) as well.

The ‘right’ way to do this now would be to download the CM package and the GApps packages, put them on your external SD card, then boot into ClockworkMod, and install the CM zip, then the GApps zip.  Reboot the phone and you should be golden.

Take a backup first using ClockworkMod.

New radio firmware for GT-i9305T with CM10.1

EDIT:  The new radio firmware didn’t stop my mdm_hsic_pm0 problem, but enabling data roaming has seemed to.  I’m definitely not out-of-country or in a position where data roaming should be a thing, so I’m not too worried about having it on.  However, turning it on seems to have immediately put a stop to the mdm_hsic_pm0 shenannigans.  Very strange, but I’m suspicious that doing so may have gotten around some kind of bug in the radio firmware.  More if I find out more.

There’s a new radio firmware available for the GT-i9305T (Samsung Galaxy S3 International, Telstra Australia variant).  The new firmware is coded UBBMB2, and can be downloaded from this thread at XDA Developers.

I usually avoid updating radio firmware unless there’s an actual need to.  In this case, my phone with the old DVALI5 radio on it was randomly blowing half the battery overnight, with mdm_hsic_pm0 being the top wakelock consumer (and having a wake time of half the time the phone was unplugged!).  This is typically associated with Fast Dormancy issues.  So, I went and updated the radio, and yesterday the phone only used an average of 0.9% battery per hour, with mdm_hsic_pm0 being a lower consumer and with a much, much lower proportion of wake time compared to run time.

In addition, for anyone using the official CyanogenMod 10.1 nightlies for the GT-i9305T, keep in mind that the nightlies have changed over to CM 10.1.  This means if you’re using them, you should update your Google Apps install to the latest version too.  You can get them from here.

Note, updating both of the above items (gapps update, radio firmware) can be done without a factory reset, so you won’t lose your stuff.  But I still advise doing a nandroid backup anyway.

To update, just drop the ZIPs onto your SD card, boot up into ClockModRecovery, and flash them.

Installing a CyanogenMod ROM onto a GT-i9305

DANGER!  Installing a custom recovery and firmware can void your warranty, and in some rare circumstances render your phone irrevocably bricked (broken).  Be aware of what you’re doing when you do this, and be aware of the consequences of installing third-party firmware.  I can’t be held responsible if your phone is bricked, buggy, or anything bad happens as a result of doing this.  

Notably, any firmware intended for the GT-i9305 will work with a GT-i9305T.  They’re the same phone, although the radio firmware likely differs.  We won’t be messing with radio firmware though.

Getting a custom firmware onto a GT-i9305 comes in a couple of steps;

  • Install a custom recovery.  We’ll use ClockworkMod for this.
  • Take a nandroid backup of the phone using CWM (pre-rooting).
  • Root the phone so that we have superuser access and can install TitaniumBackup
  • Then, we’ll root the phone, which lets you have superuser access.
  • Take backups of everything with TitaniumBackup.
  • Back up the IMEI / NVRAM data (the i9305 stores IMEI data on flash, so it’s possible for a bad firmware flash to wipe your IMEI, which is really really bad).
  • Reboot into CWM and flash the CyanogenMod 10.1 build ZIP.
  • Factory reset the phone.
  • Set it back up again.

Now, a couple of things we need to get out of the way;

Recovery Boot Modes

In order to boot to ClockworkMod Recovery mode, turn off the phone, and hold volume UP + Home + Power.  When you see the Samsung splash screen, let go of the power button, but keep holding down the other two until you see CWM’s boot screen.

In order to boot to Download Mode (used with ODIN), turn off the phone, and hold volume DOWN + Home + Power.  When you see the Samsung splash screen, let go of the power button, but keep holding the other two until you see the big Android warning.  Follow the prompts.

Host OS Choice

I did all this on a Windows 7 x64 box.  You can theoretically do this with Linux, but I haven’t tried.  Your mileage may vary with other OSes.

Let’s get cracking!

Continue reading “Installing a CyanogenMod ROM onto a GT-i9305”

CyanogenMod 10.1 for the GT-i9305 from source

Bit the bullet, and built my own CyanogenMod 10.1 for my GT-i9305T phone from source.  Works great, and that means I now have Android 4.2.2 on it!

Following is a quick piece on how to build your own CM 10.1 from source for the i9305.

First, some info, then we’ll get into it;

Reference Links

Machine Prep

I used an Ubuntu 12.10 x64 virtual machine running under VMware Workstation.  Give the machine a pretty fair amount of CPU and RAM (I went 4Gb ram and 4 vCPU since I have a quad-core box).  Build times are heavily limited by CPU.

You will also need a significant amount of disk space.  The built source tree takes up about 35Gb, so go with a 50Gb VM and you should have enough.

Once done, update the machine entirely, then from a Terminal prompt, run this to download pre-requisites;

  sudo apt-get install git-core gnupg flex bison gperf build-essential \
      zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
      libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
      libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
      python-markdown libxml2-utils schedtool pngcrush xsltproc zlib1g-dev:i386
  sudo ln -s /usr/lib/i386-linux-gnu/mesa/ /usr/lib/i386-linux-gnu/

Repository Synchronization

Download the repo tool and set it up;

    mkdir ~/bin
    cd ~/bin
    curl > ~/bin/repo
    chmod a+x ~/bin/repo

Create source repo for CyanogenMod and then synchronize;

    mkdir ~/cm10.1
    cd ~/cm10.1
    repo init -u git:// -b cm-10.1
    repo sync

Create the file ~/cm10.1/.repo/local_manifests/i9305.xml with this text;

        <project name="CyanogenMod/android_device_samsung_i9305" path="device/samsung/i9305" remote="github" revision="cm-10.1"/>
        <project name="CyanogenMod/android_device_samsung_smdk4412-common" path="device/samsung/smdk4412-common" remote="github" revision="cm-10.1"/>
        <project name="CyanogenMod/android_kernel_samsung_smdk4412" path="kernel/samsung/smdk4412" remote="github" revision="cm-10.1"/>
        <project name="CyanogenMod/android_hardware_samsung" path="hardware/samsung" remote="github" revision="cm-10.1"/>

Resync the repository to grab the latest sources etc for the i9305;

    repo sync

Note!  This will take a LONG time, and will download a lot of stuff!

At this point you will have an assembled source tree.  Now we need to set up the JDK and Android SDKs before we can build;

Configure Java JDK

It’s possible to build CM with OpenJDK, but it’s recommended that you build with the Sun Java 1.6 JDK instead.  So we’ll discuss how to do that.  NOTE – Doing this will change your default Java version to the Sun one instead of OpenJDK!

Download the latest Sun Java 1.6 JDK x64 ( jdk-6u43-linux-x64.bin ) and install;

    cd ~/Downloads
    chmod +x jdk-6u43-linux-x64.bin
    sudo mv jdk1.6.0_43 /usr/lib/jvm/jdk-6u43-linux-x64.bin

Configure Java alternatives;

    sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/javac 1
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/java 1
    sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/javaws 1
    sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/javadoc 1
    sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/javah 1
    sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/javap 1
    sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-6u43-linux-x64.bin/bin/jar 1

Set the default Java version for your system to that JDK

    sudo update-alternatives --config javac
    sudo update-alternatives --config java
    sudo update-alternatives --config javaws
    sudo update-alternatives --config javadoc
    sudo update-alternatives --config javah
    sudo update-alternatives --config javap
    sudo update-alternatives --config jar

Run ‘java -version’ and check that the version matches what you installed.

Check that all the alternatives symlinks point to the JDK you installed;

    ls -la /etc/alternatives/java* && ls -la /etc/alternatives/jar

Extract proprietary files

Note, your phone will already have to be rooted in order to be able to do this.  This will extract the necessary vendor-specific proprietary files you will need to be able to build a working firmware.  If your phone isn’t rooted, root it now.

Download the Android SDK ( android-sdk_r21.1-linux.tgz ) and install;

    cd ~/Downloads
    mkdir ~/android
    tar -zxvf android-sdk_r21.1-linux.tgz
    mv android-sdk-linux ~/android/sdk

Run the Android SDK Tools with ‘android’, then select both of these components and install them;

+ Android SDK Tools
+ Android SDK Platform-tools
+ Android 4.2.2 (API 17)
– Deselect ‘Intel x86 Atom System Image’
– Deselect ‘MIPS System Image’

Let it download.  This will probably take a while.

Enable USB Debugging mode on your phone, then plug it in. In order to enable this, go to Settings -> About Phone, then tap the Build number field seven times.  This will enable Developer Options.  In Settings, go to Developer Options, and turn on USB Debugging mode.

Now, collect the proprietary files from the phone.

    cd ~/cm10.1
    . build/
    cd ~/cm10.1/device/samsung/i9305

It may be necessary to manually copy out ‘/sbin/cbd’ from your phone.  You can do this by SSH’ing out of your phone by running a terminal emulator (rooted!) on the phone and then running ssh into your Ubuntu VM.  After that’s all done, you can turn USB Debugging back off again.

Now fetch any prebuilts required for CM-10.1;


At this point, you have a completed and ready source tree, and can now build your rom.

Building the ROM

Rebuild like this (you do this the first time, and also do these steps subsequent times you want to update your build);

    cd ~/cm10.1
    repo sync
    . build/
    brunch i9305

At the end, you should find a built ZIP file in ~/cm10.1/out/target/product/i9305 .

What now?

Next up, you’re going to have to get that onto your phone.  I’ll write up soon about how to install ClockworkMod and get that newly compiled ROM into your phone.

Pushover – Easy Notifications

Recently got myself a new work phone – a Galaxy S3 4G.  At the same time, I decided to do some research on what I could do about getting notifications to the phone.  Notifications of things like RAID array problems, stuff going onto UPS power, that sort of thing.

Enter Pushover.  This thing’s pretty awesome.  Basically, you buy the app for whatever device it’s going on, and then you sign into their website and get your user key.  From there, you can create an ‘application’, which is an API key you can use to send notifications from other things.  You can use all sorts of languages to send notifications, and you can even send a special CURL request from a normall shell script to send alerts.  Something like this;

curl -s -k \
 -F "message=Content Here" \
 -F "title=Title Here" \
 -F "priority=0" \

Fire that off, and tada!  You get an alert to your phone!  It’s pretty awesome.  You can also tie it together with IFTTT to receive notifications from all sorts of things (your favourite RSS feed getting updated, email matching specific criteria landing in your inbox etc).

Give it a go.