[Android Apps and Games] gm.outside:
Hello,

I was using lots of hacks/tools/knowledge out of these forums, but didn't have time to contribute back.

I guess, now is the time :). OK, I wanted to make photospheres on my Samsung Galaxy Note 2 (GT-N7102) and I downloaded one of the leaked Cameras for JB 4.3 with the Photosphere support. Everything was good except the limitation of 4000x2000 pixels for the resulting photosphere.

I looked around and found that Google released their Camera on the Play Market. The only problem that their package requires KitKat and I'm running JB 4.3. So, I downloaded the APK, unpacked it with apktool, analysed it a bit (by looking into sources), and realised that the only thing missing is android.hardware.camera2 framework on which the new App relies a lot. This framework appeared in KitKat and surely was not available on my JB 4.3.

So, I needed to add the missing bits to the APK in such a way that it would be still a single installable package. Well, I downloaded an Android emulator with KitKat image, pulled framework.jar out of the system using adb, and processed it with apktool (extracted stuff). Lastly, I copied the whole android.hardware.camera2 tree from framework.jar to the GoogleCamera APK, repacked the APK back, and signed it.

The resulting APK works well on my GT-N7102. I was able to create a high-res photosphere, got blur working (never had it before :) ), got panorama working, and regular camera as well.

The only problem, however, is that if you record a video - once the file is saved the application will start crashing. I suspect that it will also crash if you have H.264 MP4 files in your media directory. So far I narrowed down the issue to Glide and/or thumbnail generation for the video files. But I will really appreciate it if somebody takes a look and help me to narrow it down further, so we could get a fully working Camera App.

UPDATE: I found the culprit - it was a bit of the "material design" embedded into the media viewer (so called elevation), I fixed the layout and now the whole package works exceptionally!

OK. Now, if you are interested, please find the modded APK at drive.google.com/file/d/0B38rMq5uUHl-UnNreWFLQ1hyWTA (sorry, my karma does not allow me to post proper links yet, so I'd appreciate it if a moderator updates the post with the proper https:// link here). Just remember not to record video (it's broken). And if you did: removing/renaming *.mp4 in the /sdcard/DCIM/Camera directory will fix the application.

UPDATE on 2015-06-27: Google released an update for their camera software and people were asking for an updated version. Here it comes: Google Camera 2.5.052 (JellyBean Edition).apk.

If you want to build one yourself or I am not around here is the session transcript on how I did it (The prerequisites are: apktool, keytool, jarsigner, dex2jar and a copy of the framework.jar package processed through dex2jar and unpacked in a directory [in my example it was the framework directory in the working directory]):

$ apktool decode -p framework com.google.android.GoogleCamera.apk
I: Using Apktool 2.0.0 on com.google.android.GoogleCamera.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: framework/1.apk
I: Renamed manifest package found! Replacing com.google.android.GoogleCamera with com.android.camera2
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
$ mkdir com.google.android.GoogleCamera/smali/android/hardware
$ cp -a framework/smali/android/hardware/camera2 com.google.android.GoogleCamera/smali/android/hardware/
$ fgrep -lr elevation com.google.android.GoogleCamera/res
com.google.android.GoogleCamera/res/layout/filmstrip_image.xml
com.google.android.GoogleCamera/res/layout/filmstrip_video.xml
$ sed 's,\([[:space:]]\)android:elevation="[0-9.]*dip"[[:space:]]*,\1,g' com.google.android.GoogleCamera/res/layout/filmstrip_image.xml > com.google.android.GoogleCamera/res/layout/filmstrip_image.xml.patched
$ diff -u com.google.android.GoogleCamera/res/layout/filmstrip_image.xml{,.patched}
--- com.google.android.GoogleCamera/res/layout/filmstrip_image.xml	2015-06-27 14:36:21.000000000 +1000
+++ com.google.android.GoogleCamera/res/layout/filmstrip_image.xml.patched	2015-06-27 14:37:02.000000000 +1000
@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
-<ImageView android:background="@drawable/dummy_rect_background" android:layout_width="fill_parent" android:layout_height="fill_parent" android:elevation="10.0dip"
- xmlns:android="http://schemas.android.com/apk/res/android" />
\ No newline at end of file
+<ImageView android:background="@drawable/dummy_rect_background" android:layout_width="fill_parent" android:layout_height="fill_parent"
+ xmlns:android="http://schemas.android.com/apk/res/android" />
$ sed 's,\([[:space:]]\)android:elevation="[0-9.]*dip"[[:space:]]*,\1,g' com.google.android.GoogleCamera/res/layout/filmstrip_video.xml > com.google.android.GoogleCamera/res/layout/filmstrip_video.xml.patched
$ diff -u com.google.android.GoogleCamera/res/layout/filmstrip_video.xml{,.patched}
--- com.google.android.GoogleCamera/res/layout/filmstrip_video.xml	2015-06-27 14:36:21.000000000 +1000
+++ com.google.android.GoogleCamera/res/layout/filmstrip_video.xml.patched	2015-06-27 14:37:36.000000000 +1000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout android:background="@drawable/dummy_rect_background" android:layout_width="fill_parent" android:layout_height="fill_parent" android:elevation="10.0dip"
+<FrameLayout android:background="@drawable/dummy_rect_background" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:layout_gravity="center" android:id="@id/video_view" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<ImageView android:layout_gravity="center" android:id="@id/play_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_control_play" android:contentDescription="@string/video_control_play" />
-</FrameLayout>
\ No newline at end of file
+</FrameLayout>
$ sed "s,\(minSdkVersion:[[:space:]]*'\)19\('\),\116\2,g;s,\(targetSdkVersion:[[:space:]]*'\)21\('\),\116\2,g" com.google.android.GoogleCamera/apktool.yml > com.google.android.GoogleCamera/apktool.yml.patched
$ diff -u com.google.android.GoogleCamera/apktool.yml{,.patched}
--- com.google.android.GoogleCamera/apktool.yml	2015-06-27 14:36:24.000000000 +1000
+++ com.google.android.GoogleCamera/apktool.yml.patched	2015-06-27 14:42:59.000000000 +1000
@@ -5,8 +5,8 @@
ids:
- 1
sdkInfo:
- minSdkVersion: '19'
- targetSdkVersion: '21'
+ minSdkVersion: '16'
+ targetSdkVersion: '16'
packageInfo:
forced-package-id: '127'
rename-manifest-package: com.google.android.GoogleCamera
$ find com.google.android.GoogleCamera -type f -name '*.patched' -exec /bin/bash -c "F='{}'; mv -v \"\$F\" \"\${F%.patched}\"" \;
com.google.android.GoogleCamera/apktool.yml.patched -> com.google.android.GoogleCamera/apktool.yml
com.google.android.GoogleCamera/res/layout/filmstrip_image.xml.patched -> com.google.android.GoogleCamera/res/layout/filmstrip_image.xml
com.google.android.GoogleCamera/res/layout/filmstrip_video.xml.patched -> com.google.android.GoogleCamera/res/layout/filmstrip_video.xml
$ apktool build -p framework com.google.android.GoogleCamera
I: Using Apktool 2.0.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Copying libs...
I: Building apk file...
I: Copying unknown files/dir...
$ cd com.google.android.GoogleCamera/dist
$ ls -l com.google.android.GoogleCamera.apk
-rw-r--r-- 1 galaxy staff 22971563 27 Jun 14:59 com.google.android.GoogleCamera.apk
$ keytool -genkey -v -keystore my-release-key.keystore -alias CERT -keyalg RSA -keysize 2048 -validity 10000
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: (GalaxyMaster)
What is the name of your organizational unit?
[Unknown]: Android Reverse Engineering
What is the name of your organization?
[Unknown]: Demented $oftware Challengerz
What is the name of your City or Locality?
[Unknown]: Deep Space
What is the name of your State or Province?
[Unknown]: Quadrant 66
What is the two-letter country code for this unit?
[Unknown]: XX
Is CN=(GalaxyMaster), OU=Android Reverse Engineering, O=Demented $oftware Challengerz, L=Deep Space, ST=Quadrant 66, C=XX correct?
[no]: yes

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
for: CN=(GalaxyMaster), OU=Android Reverse Engineering, O=Demented $oftware Challengerz, L=Deep Space, ST=Quadrant 66, C=XX
Enter key password for <CERT>
(RETURN if same as keystore password):
[Storing my-release-key.keystore]
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore com.google.android.GoogleCamera.apk CERT
Enter Passphrase for keystore:
adding: META-INF/MANIFEST.MF
adding: META-INF/CERT.SF
adding: META-INF/CERT.RSA
signing: AndroidManifest.xml
signing: assets/wear-remote-shutter-wearable-app.apk
signing: classes.dex
[skipped]
signing: res/xml/wearable_description.xml
signing: resources.arsc
signing: .readme
jar signed.

Warning:
No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2042-11-12) or after any future revocation date.
$ ls -l com.google.android.GoogleCamera.apk
-rw-r--r-- 1 galaxy staff 23070850 27 Jun 15:03 com.google.android.GoogleCamera.apk
$ mv com.google.android.GoogleCamera.apk "Google Camera 2.5.052 (JellyBean Edition).apk"
$

Hope this would help somebody :)