Cyanogen mod 13 on Samsung Galaxy S3

(This contains 2 updates from 22.08.2016)

Up-to-date phone software sounds good

I have an ancient Samsung Galaxy S3 (I9300) smartphone which suits my needs very nicely, especially with the extra large battery. I have been running the Cyanogen Mod 12.1 (cm12.1) ROM after Samsung stopped updating its software. cm12.1 uses Android 5.0, which was less susceptible to the stagefright vulnerabilty which was the current scare at that time. It worked reasonably well, but then the Cyanogen Mod updater taunted, tempted me once per week with announcements of the nighly builds of Cyanogen Mod 13 (cm13): Just tap to download, reboot into recovery, install, enjoy Android 6.0.

INTERESTED? BUT NOT SO FAST! Enable USB debugging now! Download the Google apps for cm13 NOW and put the zip file on your phone’s storage NOW (unless you are going Google-less anyway).

Some background: In order to use your own software on Samsung phones, you have to root them / break them open. This is usually done (for the S3) by connecting the phone to a PC via USB, putting the phone into a special download mode, and have some PC software install a new Recovery ROM on the phone. Once this is done, you can boot the phone into this recovery and make backups, install software, and also install a totally different operating system, e.g. cm13. All this had been taken care of by my brother, and I was just using the recovery to make backups and install different ROMs, the last of which was cm12.1.

Where things first went wrong

So yesterday I did tap the “download” button on the cm updater app and cm-13.0-20160818-NIGHTLY-i9300.zip was duly downloaded and saved on my phone. The next step was to boot into the recovery, check its version, update if necessary, backup the old ROM and user data, then install cm13. That is where things started to go wrong.

The recovery crashed and rebooted infinitely. And since the way to boot the phone normally after being done with the recovery was to tap the “reboot system” button in the recovery, this was bad. (The other way to recovery is to switch off the phone, then press Volume up+Home+Power, then release power. This will only do one attempt at getting into recovery.)

It turns out the cm12.1 by default “updates” your recovery ROM every time it boots. This can be switched off in the developer options. So, I had to learn about flashing my phone really fast (as opposed to slow, because I would have needed to update the recovery ROM anyway before updating to cm13).

On the S3, press Volume down+Home+Power, then release power, then confirm with Volume up to go into download mode. Then, you can use special software on a PC to install a new recovery ROM via USB. You will need:

  • a software called ODIN

  • Samsung USB drivers for Windows (I have Windows 10)

  • a recovery ROM image (I use TWRP twrp-3.0.2-1-i9300.img.tar, which is new enough for cm13)

The process is described here How to Flash TWRP Recovery in Galaxy S3 using ODIN.

When I had my recovery back, I quickly did a system backup onto my SD card. I could also use the phone again. This is the point where you should not follow my foot steps. Instead, download the Google apps for cm13 and copy the zip file to your phone’s internal storage (I take out the SD card when doing major software changes on the phone).

Now do the update by again booting into recovery and tapping “install” and choose first the cm13 zip file (e.g. cm-13.0-20160818-NIGHTLY-i9300.zip) and then add as a second zip file the open_gapps-arm-6.0-nano-20160820.zip or whatever the current version is. You must not reboot between installation of cm13 and Google apps! Wipe the Dalvik / cache.

Reboot system, enjoy cm13 with Android 6.0 and all your user data intact!

…and wrongerer

So, but what if you did what I did, and are now sitting in front of a phone that only good for telling you that a setup wizard is crashing (with a permission problem). You cannot do anything but tap “OK”, which will restart and recrash the setup wizard. No useful work can be done with the phone. The reason for the crashes is stupid (explanation and fix for some lucky cases here) and I do not understand why this has not been fixed / worked-around in the ROM.

The fix in the above link tells you to setup a USB debugging connection from your PC to the phone and to enter a magical command line to change the configuration and repair the problem. However, this only works if USB debugging was already turned on on the phone, which of course was not the case for mine.

If you are fortunate enough to be able to use the fix, then you need to setup ADB or try my method from the next section.

For the ADB method, install this software: 15 seconds ADB Installer v1.4.3. Use it by finding the adb.exe, making a link to it, go to the properties of the link, add " shell” after the adb.exe (note the space between exe and shell), and set it to be run as administrator. Connect phone and PC by USB cable, start adb.exe, then put in the

pm grant com.google.android.setupwizard android.permission.READ_PHONE_STATE

command line. I cannot personally say if it works, because I was NOT fortunate like you.

OK, this is getting ridiculous

So, no USB debugging. What about booting into recovery and doing ADB there? While the ADB connection will work even with the phone in recovery, you cannot do any ADB commands:

/sbin/sh: pm: not found

I later found out why ADB does not work out of recovery: The /system/ partition is not automatically mounted in recovery, and the command is in

/system/bin/pm

Had I known this, I could have mounted /system with a few taps in the recovery menus. TWRP also has a shell right on the phone, so the ADB stuff might not have been necessary after all. However, there might be trouble with root rights etc., but I was spared these. And, with ADB, you could paste the pm command from this webpage directly into adb.exe, instead of typing it on the phone.

My sub-optimal result

Since I thought that ADB was impossible for me, I used a radical hack I found on reddit:

boot into recovery
mount the /system partition read-write in recovery
go to command line in recovery
rm -rf /system/priv-app/SetupWizard

No wizard, phone usable, but all Google apps crash now (they do seem to depend on the setup wizard). But the Play Store still works.

Update 22.08.2016: After applying the ADB fix, I had to uninstall and reinstall GMail and Youtube from the Play Store to stop them crashing.

Hindsight is 20/20

Instead of rm -rf, I should have realised that I now have access to /system/bin/pm and done this

boot into recovery
mount the /system partition read-write in recovery
go to command line in recovery
/system/bin/pm grant com.google.android.setupwizard android.permission.READ_PHONE_STATE

When I win a lot of time in the lottery, I will re-install the Google apps and then do this.

Update 22.08.2016: This did NOT work, the pm command gives an error, maybe you would have to boot the system, have it fail, go back to recovery etc etc. I did not have the patience for that, since I could now do ADB.

In closing…

I hope this can help someone in this situation. The problem with the Google apps was reported already in December 2015, but it continues to trap people. At least I learned a bit about ADB, /system, recovery ROMs etc.

This information was not obviously google-able:

  • ADB for android is like a command line but via USB

  • ADB needs a fully booted system or at least a mounted /system partition (else, you get /sbin/sh: pm: not found etc.)

  • ADB needs USB debugging turned on

  • The recovery ROM TWRP has a command line

  • The recovery ROM TWRP has provisions for mounting the necessary /system partition

  • /system/bin/pm (but see above when using from recovery)

  • This cheers me up