Fixing the Camera App

At the end of my last post I mentioned that although the root of my Xperia Z5 had gone pretty well, it (or possibly my unmentioned, failed attempt at installing the Xposed Framework) had caused my default camera app to crash after a second every time it was opened. This persisted after a reboot, but wasn't an incredibly serious issue as all the various other camera apps (Snapchat, Instagram, Google Camera, OpenCamera) worked fine. But it was a bit of a bummer, as I'm used to the Sony app's interface, so I decided to fix it.

Luckily, this didn't take nearly as long as rooting my phone. On the forum post for the insecure kernel I'd flashed, there was a link to another post about "camera app crashes after xposed framework install" -- sounded like just my problem. It mentioned a particular class that couldn't be found causing the app to crash, and so out of curiosity I decided to fire up logcat over ADB and check to see if that actually was the problem.

The only issue: I still hadn't set up ADB since last time I tried. I had the binaries in the SDK folder, sure, but the actual USB drivers still didn't seem to be working. It didn't help that pretty much the only solution ever suggested seemed to be "turn on USB debugging", which I'd done even before starting to root my phone.

Last time, I got away with not setting up the ADB USB drivers because I found the same functionality existed inside the recovery image itself, and I could do everything direct on the phone. But this time, I wasn't in the recovery image. I tried some more in vain to set up the USB drivers but my heart really wasn't in it, then finally came across an app called "WiFi ADB". Life: saved. I ran logcat and found just the Java exception I was expecting. I left the app running on my phone, and went back to the forum post.

The instructions told me to download Joel's Lollipop Deodexer, which I did. Then, I was supposed to copy my framework and priv-app directories from my phone over to my PC in order to begin the deodexing process. The only problem: both of those directories are in /system, which means my PC's view of the phone as a media device doesn't show them up. I tried using Droid Explorer, but for some reason - although all the other functions worked - it just wasn't displaying the file system.

I was stuck on a boring problem - how to copy some files from my phone to my PC - and I started feeling lazy. Essentially, what instructions 2-6 were describing was the process of creating a deodexed CameraCommon.apk file. There really shouldn't be anything particularly personalised about that file - the end result should be the same on any Z5...

...so I downloaded someone else's. On page 3 of the thread, someone had uploaded a deodexed CameraCommon.apk, along with some terrifying predictions that other apk's would have to be deodexed as well, and that it wouldn't work on its own. I decided that these were the ravings of a madman, and went onto the interesting bit - actually pushing the APK to my phone and replacing the builtin CameraCommon app.

The instructions given were the following:

adb push CameraCommon.apk /data/local/tmp  
adb shell  
su  
busybox mount -o remount,rw /system  
dd if=/data/local/tmp/CameraCommon.apk of=/system/priv-app/CameraCommon/CameraCommon.apk  
chmod 644 /system/priv-app/CameraCommon/CameraCommon.apk  
rm -rf /system/priv-app/CameraCommon/arm  
rm -rf /system/priv-app/CameraCommon/arm64  

At the first line, I hit a Permission Denied problem. Strange, since if I really did have root permissions, it'd seem odd not to be able to write to /data/local/tmp. To fix this, I went ahead and stepped into the adb shell. My plan was to do a simple chmod +rw /data/local/tmp as root, but I ran into a couple of minor issues: firstly, a "bad mode" message indicated that I'd have to use the octal "777" instead of the much more intuitive "+rw"; and secondly, although the prompt looked like root@E6653:/ #, I wasn't actually root, and had to su in order to run commands as the superuser.

I went ahead. Strangely enough, I didn't seem to have busybox installed, so I took a quick break and installed that via an app from the Play Store. The rest went just as planned, with no errors; I ran a quick reboot in the adb shell, and opened the camera app with bated breath...

...it worked!