Wednesday, December 31, 2014

... and how to restore it

As noted a couple of days ago, I broke my Nexus 5 and managed to get a backup via adb.

Finally, UPS managed - as usual with their second attempt and one call in between - to deliver the new Nexus 5 yesterday.
So, unbox, switch on, log into Wifi, etc etc... and have the system update to 4.4.3.

What?!?
Say Again!

"... and have the system update to 4.4.3."
No matter how often I repeat this, it's still weird that a brand new Nexus 5, ordered and shipped directly from Google, comes with 4.4.2 the end of 2014.

Anyway, update to 4.4.3, reboot, update to 4.4.4, reboot, update to 5.0....
Nope.
No 5.0. No Lollipop. As we know, rechecking every 5 seconds for an Android over-the-air update is as useful as hitting the elevator call button 10 times.

Well, so enable developer options with the 7x tap on the Build Number. Enable USB debugging.
Connect to PC, authorize, find the device with "adb devices". Voila.

Let's try the "adb restore". Enter the password on the mobile, this time without the help of the "adb shell input" workaround. The restore starts, and ends without any further message after about 2-3 seconds.

Not good.
Lets check the log with "adb logcat". There's something about mismatched header versions, so lets google this.
Well, as can be expected you cannot restore a 5.x backup to a 4.x device.
How silly of me to even consider it.

Recheck the over-the-air upgrade.
Nope, still not 5.0.

So screw it, download the factory image for 5.0.1.
Unlock bootloader, apply image, as described.
Reboot, log into Wifi, ...
Then the new Lollipop Setup Assistant kicks in and allows me to actually place my old phone to he back of the new one to NFC pair them, and transfer the basic settings (mainly account and Google settings) directly.

So I plug in the USB mouse again to the old, broken Nexus 5, and try to find the NFC settings (which are of course in the broken part of the display). Google around a bit to find there in the settings they are, and manage to half blindly enable NFC.
A couple of seconds later I have my account and (Google) launcher settings on the new Nexus 5.
Nice.
A lot of the app icons on the home screen are marked to show that the app itself is (still) missing behind the icon.

So I tried to restore the backup.
Again enable developer options (I just loaded a new system image, so everything I did an hour ago was of course gone) and USB debugging (and sideloading).

And now the "adb restore" really did work. Since there is no proper status on the device itself, I started a "adb shell logcat -s BackupManagerService" in another window to see some progress.

And about half an hour later I was done.
Most apps had their settings again, but not all.

Considering what last-resort hack this was, pretty good.
Considering how easy it is, to upgrade from one iPad to the next (via iTunes) this was pretty ugly.

By the way:
The Setup Assistant from Lollipop now supports a lot of options, even restoring data from a previous backup.
But I was not really inclined to test this right now.
If someone wants to sponsor yet another Nexus device for me, I'd be happy to test this for you.

Sunday, December 28, 2014

How to Backup a Broken Nexus 5 via USB

So, the other day I decided to drop my beloved Nexus 5 - display first - on a concrete (or stone, whatever) floor, right in the middle of Vienna's most busy shopping street. And got a result like this:

Not only was the glass broken, but the display itself was defect in large areas as well. Touch of course did not longer work.

I visited a repair shop just down the road, and guess what, they only have Samsung and Apple spares on stock, and I got the tip to use a cover next time. Yeah right, Thanks a lot.
So with the broken display and all, I decided to purchase a new one (via Play store), which is en-route to Vienna right now.

In the meantime I was trying to save whatever I can from the old device. My Nexus is unrooted without even a hint of Titanium Backup or the likes activated. Luckily I enabled the developer options as a first step after I got it.
So I connected it via USB to my PC and saved whatever as accessible this way.

I have the Android Developer Kit / SDK Tools installed on my PC, so I have adb at hand - the Android Debug Bridge, which is needed for the following steps.

Then I tried an "adb backup", which prompted for a confirmation on my device.
Of course, with no touch and the broken display I could not enter one.

So, the ultimate hack of 2014 to the rescue:

Step 1.
Connect a USB mouse via USB converted to the phone.
Yes, I really wrote that. A regular (PC) USB mouse. And you'll also see a regular mouse pointer on the display then. How cool is that.


Unlock the phone by drawing the swipe pattern with the mouse.

Then immediately (with the mouse again), go to settings and change the pattern to a PIN.

The PIN can be easily sent via USB from the PC, the pattern less so. Now we can disconnect the mouse again.

Step 2.
Connect the phone to the PC again.

Run "adb devices" just to be sure you are connected (all adb commands are of course from the windows command line or whatever your "host" operating system is).

If you are stuck with the lock screen, you need to swipe up with the following adb command[1]:
adb shell input swipe 500 1900 500 900

Then you should get the PIN prompt.

Unlock it with a sequence like this:
adb shell input text 1234 
adb shell input keyevent 66

The first line sends the PIN (1234 in this example), the second line sends the ENTER after it.  The event codes can be found in the Android Developer docs or here. The POWER, ENTER, BACK and HOME keys/events are quite useful :)

Step 3.
Start the backup with
adb backup  -apk -obb -shared -system -all

(or whatever options you require)
Then you'll get the full backup confirmation prompt, which needs to be answered again with the help of  adb shell input commands.
You can set a password with
adb shell input text password  [2].

However, it does not accept the keyevent 66 to confirm this dialog; this literally inserts a new line at the end of the password.
We have to tap on the "BACK UP MY DATA" button at the right bottom of the screen. Which leads us to

Step 4.
Luckily you can also emulate touch events via USB. Some research, some guessing, and trial and error showed, that this button is roughly in the area of coordinates 800,1750   (so in the right third and just above the button bar). The display is 1080x1920 in size, so that was easy to guess and test.
So we send a
adb shell input tap 800 1750

And the backup starts.
Magic.

Tomorrow I shall hopefully receive my new Nexus 5 (if the UPS guy for once delivers on the first attempt) and then I can report on how the migration to the new device works.

--

[1] The screen is 1080x1920; so the start position for our swipe is 500/1900 , i.e. quite in the middle, almost on the bottom, the end is 500/900, i.e. quite in the middle, quite in the middle, and almost perfect swipe to unlock.
[2] substitute your real desired password for password here, right after text.

Saturday, December 06, 2014

Wakelock Detector for Nexus 5 non-root, Lollipop

Earlier this week I had a good discussion and exchange with Max  - mainly on the Moto 360 watch, but also on a lot of Android / phone topics.

We were sort of mentally debugging a battery/power problem he had on his device (1+1), while my own Nexus 5 was lying around as idle as possible: I had to put it into power saver mode because my own battery was down to 5% at 7pm already.

So after all this discussion about Android power consumption etc etc, I decided not only to do some cleanup on my own device:

  • delete two of the 3 calendar apps, because Lollipop Calender + widget is quite OK now (I removed Cal and Sunrise)
  • change email sync frequency in Boxer from Automatic(Push) to 15 minutes.
but also to install the Wakelock Detector app (WLD), to check if any app is blocking my phone from going to sleep properly.

Since my phone is not rooted (and I have not intention to root it - for the time being), I needed to provide a little help and trick to WLD: essentially through local tpcip connection to the adb on the device. Very well documented here.

So, let's see what I'll find out.


Thursday, December 04, 2014

BeyondPod - per feed playback speed

I have two podcast devices:
  • an iPod Nano, where I have the less time sensitive podcasts, because I only synch it through iTunes every second week or so
  • and BeyondPod on my Android Phone (Nexus 5 with Lollipop as of this writing), where I listen most podcasts, especially the daily ones.
A couple of months ago I changed the playback speed in BeyondPod to x1.3, i.e. 30% faster. I found this the ideal speed to accommodate all the daily (mostly tech) podcasts into my daily commute schedule, while still being at a good pace for listening.

However, some feeds, I like to keep on regular (=x1.0) speed. I guess, the less techie the podcast is, the more narrative it has, the more I like to listen to it at it's original, intended pace. Take the Serial Podcast, for example.

So I always went into the BeyondPod app, and changed the speed - simple.
I was pretty sure, that there is a better way for this, like setting the speed on a feed level. Today I remembered to look for this.
And - of course - BeyondPod can do that.
In the feed settings ("Edit Feed"), when you open the Advanced Settings you'll find it:




Nice one.

However, sometimes you need to be very confident that a certain feature/option "just must be there" in order to find it (especially outside the Apple environment).