zhuowei / Xenologer

#notglass #untilnow
263 stars 57 forks source link

Questions about porting original apks #33

Closed xingrz closed 10 years ago

xingrz commented 10 years ago

Hi Zhuowei,

I'm trying to port the original GlassHome.apk into my cellphone, these are what I did:

  1. Removed <uses-library> section (com.google.android.glass requirement) in AndroidManifest.xml because original Android does not have glass-core.odex or glass-services.odex
  2. Merged *.smali files of glass-core.odex and glass-services.odex (library com.glass.android.glass) into GlassHome because GlassHome actually need them
  3. Copied fonts from ROM's /system/fonts into assets/fonts
  4. Copied native jni *.so library files needed (grep -r loadLibrary) into lib/armeabi-v7a
  5. apktool b all stuffs above
  6. Signed the apk, and installed it successfully

Everything seems fine, but Glass Home can't run actually.

Is it something I just missed?

zhuowei commented 10 years ago

There's a call to a nonexistant view method that needs to be removed: see the commit logs for the GlassHome repo. https://github.com/zhuowei/Xenologer-src-glasshome/commit/da0ee7936c109ef2a3b1a0fae79e8488eeca6e20

xingrz commented 10 years ago

@zhuowei do you meen getDeviceTapTimeout ? I've grep -r it and it seems gone since XE11.

xingrz commented 10 years ago

@zhuowei The apk crashes repeatly and I've checked adb logcat and I found it's probably due to a permission leak android.permission.WRITE_SECURE_SETTINGS.

Is it due to the signature? What key should I use to sign the apk?

zhuowei commented 10 years ago

Did you remove the turn off screen calls?

xingrz commented 10 years ago

@zhuowei ooops...you meens patching the smali/com/google/glass/util/PowerHelper.smali? not yet. I'll try tomorrow, so late, sleep...

xingrz commented 10 years ago

oops...

E/AndroidRuntime(23529): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(23529): java.lang.RuntimeException: native typeface cannot be made
E/AndroidRuntime(23529):    at android.graphics.Typeface.<init>(Typeface.java:175)
E/AndroidRuntime(23529):    at android.graphics.Typeface.createFromAsset(Typeface.java:149)
E/AndroidRuntime(23529):    at com.google.glass.widget.RobotoTypefaces.loadTypeface(RobotoTypefaces.java:132)
E/AndroidRuntime(23529):    at com.google.glass.widget.RobotoTypefaces.getTypeface(RobotoTypefaces.java:116)
E/AndroidRuntime(23529):    at com.google.glass.widget.RobotoTypefaces.getTypeface(RobotoTypefaces.java:86)
E/AndroidRuntime(23529):    at com.google.glass.widget.RobotoTypefaces$1.run(RobotoTypefaces.java:96)
E/AndroidRuntime(23529):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
E/AndroidRuntime(23529):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
E/AndroidRuntime(23529):    at java.lang.Thread.run(Thread.java:856)
W/ActivityManager(  410):   Force finishing activity com.google.glass.home/.timeline.MainTimelineActivity

W/Settings(25659): Setting sys_storage_threshold_percentage has moved from android.provider.Settings.System to android.provider.Settings.Global
E/DatabaseUtils(  410): Writing exception to parcel
E/DatabaseUtils(  410): java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
E/DatabaseUtils(  410):     at com.android.providers.settings.SettingsProvider.checkWritePermissions(SettingsProvider.java:275)
E/DatabaseUtils(  410):     at com.android.providers.settings.SettingsProvider.insertForUser(SettingsProvider.java:866)
E/DatabaseUtils(  410):     at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:603)
E/DatabaseUtils(  410):     at android.content.ContentProvider$Transport.call(ContentProvider.java:256)
E/DatabaseUtils(  410):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:256)
E/DatabaseUtils(  410):     at android.os.Binder.execTransact(Binder.java:351)
E/DatabaseUtils(  410):     at dalvik.system.NativeStart.run(Native Method)
E/StorageHelper(25659): Error initializing thresholds
E/StorageHelper(25659): java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
E/StorageHelper(25659):     at android.os.Parcel.readException(Parcel.java:1425)
E/StorageHelper(25659):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
E/StorageHelper(25659):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
E/StorageHelper(25659):     at android.content.ContentProviderProxy.call(ContentProviderNative.java:574)
E/StorageHelper(25659):     at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:779)
E/StorageHelper(25659):     at android.provider.Settings$Global.putStringForUser(Settings.java:6511)
E/StorageHelper(25659):     at android.provider.Settings$Secure.putStringForUser(Settings.java:3732)
E/StorageHelper(25659):     at android.provider.Settings$Secure.putIntForUser(Settings.java:3834)
E/StorageHelper(25659):     at android.provider.Settings$Secure.putInt(Settings.java:3828)
E/StorageHelper(25659):     at com.google.glass.util.StorageHelper.initializeThresholds(StorageHelper.java:63)
E/StorageHelper(25659):     at com.google.glass.home.HomeApplication.onCreate(HomeApplication.java:324)
E/StorageHelper(25659):     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
E/StorageHelper(25659):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4577)
E/StorageHelper(25659):     at android.app.ActivityThread.access$1300(ActivityThread.java:153)
E/StorageHelper(25659):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
E/StorageHelper(25659):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/StorageHelper(25659):     at android.os.Looper.loop(Looper.java:137)
E/StorageHelper(25659):     at android.app.ActivityThread.main(ActivityThread.java:5227)
E/StorageHelper(25659):     at java.lang.reflect.Method.invokeNative(Native Method)
E/StorageHelper(25659):     at java.lang.reflect.Method.invoke(Method.java:511)
E/StorageHelper(25659):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/StorageHelper(25659):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/StorageHelper(25659):     at dalvik.system.NativeStart.main(Native Method)

E/ActivityThread(25659): Failed to inflate
E/ActivityThread(25659): android.view.InflateException: Binary XML file line #2: Error inflating class com.google.glass.widget.TypophileTextView
E/ActivityThread(25659):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
E/ActivityThread(25659):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
E/ActivityThread(25659):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
E/ActivityThread(25659):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/ActivityThread(25659):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/ActivityThread(25659):    at com.google.glass.widget.horizontalscroll.FastScrollOverlay.<init>(FastScrollOverlay.java:97)
E/ActivityThread(25659):    at com.google.glass.home.timeline.TimelineOverlayView.<init>(TimelineOverlayView.java:29)
E/ActivityThread(25659):    at com.google.glass.home.timeline.TimelineOverlayView.<init>(TimelineOverlayView.java:20)
E/ActivityThread(25659):    at com.google.glass.home.timeline.MainTimelineActivity.initTimelineView(MainTimelineActivity.java:261)
E/ActivityThread(25659):    at com.google.glass.home.timeline.MainTimelineActivity.onCreate(MainTimelineActivity.java:212)
E/ActivityThread(25659):    at android.app.Activity.performCreate(Activity.java:5104)
E/ActivityThread(25659):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/ActivityThread(25659):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
E/ActivityThread(25659):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
E/ActivityThread(25659):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
E/ActivityThread(25659):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
E/ActivityThread(25659):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/ActivityThread(25659):    at android.os.Looper.loop(Looper.java:137)
E/ActivityThread(25659):    at android.app.ActivityThread.main(ActivityThread.java:5227)
E/ActivityThread(25659):    at java.lang.reflect.Method.invokeNative(Native Method)
E/ActivityThread(25659):    at java.lang.reflect.Method.invoke(Method.java:511)
E/ActivityThread(25659):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/ActivityThread(25659):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/ActivityThread(25659):    at dalvik.system.NativeStart.main(Native Method)
E/ActivityThread(25659): Caused by: java.lang.reflect.InvocationTargetException
E/ActivityThread(25659):    at java.lang.reflect.Constructor.constructNative(Native Method)
E/ActivityThread(25659):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/ActivityThread(25659):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
E/ActivityThread(25659):    ... 23 more
E/ActivityThread(25659): Caused by: java.lang.RuntimeException: native typeface cannot be made
E/ActivityThread(25659):    at android.graphics.Typeface.<init>(Typeface.java:175)
E/ActivityThread(25659):    at android.graphics.Typeface.createFromAsset(Typeface.java:149)
E/ActivityThread(25659):    at com.google.glass.widget.RobotoTypefaces.loadTypeface(RobotoTypefaces.java:132)
E/ActivityThread(25659):    at com.google.glass.widget.RobotoTypefaces.getTypeface(RobotoTypefaces.java:116)
E/ActivityThread(25659):    at com.google.glass.widget.TypophileTextView.<init>(TypophileTextView.java:95)
E/ActivityThread(25659):    at com.google.glass.widget.TypophileTextView.<init>(TypophileTextView.java:78)
E/ActivityThread(25659):    ... 26 more
D/AndroidRuntime(25659): Shutting down VM
W/dalvikvm(25659): threadid=1: thread exiting with uncaught exception (group=0x40c94930)
I/Process (25659): Sending signal. PID: 25659 SIG: 9
I/ActivityManager(  410): Process com.google.glass.home (pid 25659) has died.
zhuowei commented 10 years ago

You're still missing some fonts - can you check the RobotoTypefaces class and see if font loading was changed?

xingrz commented 10 years ago

oops...my mistake, I shipped /system/fonts rather than /system/glass_fonts.

xingrz commented 10 years ago
E/AndroidRuntime(27666): FATAL EXCEPTION: main
E/AndroidRuntime(27666): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.glass.home/com.google.glass.home.timeline.MainTimelineActivity}: java.lang.NullPointerException
E/AndroidRuntime(27666):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
E/AndroidRuntime(27666):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
E/AndroidRuntime(27666):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
E/AndroidRuntime(27666):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
E/AndroidRuntime(27666):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27666):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(27666):    at android.app.ActivityThread.main(ActivityThread.java:5227)
E/AndroidRuntime(27666):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27666):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(27666):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/AndroidRuntime(27666):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/AndroidRuntime(27666):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(27666): Caused by: java.lang.NullPointerException
E/AndroidRuntime(27666):    at com.google.android.glass.timeline.TimelineHostManager.register(TimelineHostManager.java:183)
E/AndroidRuntime(27666):    at com.google.glass.home.timeline.TimelineApiAdapter.activate(TimelineApiAdapter.java:177)
E/AndroidRuntime(27666):    at com.google.glass.home.timeline.MainTimelineView.init(MainTimelineView.java:135)
E/AndroidRuntime(27666):    at com.google.glass.home.timeline.MainTimelineActivity.initTimelineView(MainTimelineActivity.java:265)
E/AndroidRuntime(27666):    at com.google.glass.home.timeline.MainTimelineActivity.onCreate(MainTimelineActivity.java:212)
E/AndroidRuntime(27666):    at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime(27666):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime(27666):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
E/AndroidRuntime(27666):    ... 11 more
W/ActivityManager(  410):   Force finishing activity com.google.glass.home/.timeline.MainTimelineActivity

mmmmmh....a step closer to success, but still crashes :(

xingrz commented 10 years ago
    public static TimelineHostManager get()
    {
        if(sInstance == null)
            sInstance = new TimelineHostManager(ITimelineManager.Stub.asInterface(ServiceManager.getService("timeline")));
        return sInstance;
    }

after digging into com.google.android.glass.timeline.TimelineHostManager (which is originally /system/framework/glass-core.odex and I merged its smalis into GlassHome's), it seems caused by ServiceManager.getService("timeline") returned null

zhuowei commented 10 years ago

We might have to fix that - we could try running the timeline host as a Service in an APK; I'll try working on that this weekend. Then, you'll probably need to change the calls so they bind to the app instead of checking the context.

That way, though, means that any apps developed with the Glass GDK would crash instantly with Xenologer - any ideas?

xingrz commented 10 years ago

Thanks. I'm not very familiar with system framework. Waiting for your good news :+1:

zhuowei commented 10 years ago

So the code for the glass service is in frameworks/glass-services.odex; if you deodex that and glass-core.odex, build an APK with a Service exposing the timeline manager, and finally modify the code in the Glass APKs to use that instead, it should work without root.

xingrz commented 10 years ago

I checked com.google.android.glass.timeline.TimelineService in frameworks/glass-services.odex, it is extends from ITimelineManager.Stub which is a Binder.

Since I'm not very familiar with system-level stuffs, I have no idea about how to port the TimelineService to a app-level Service. Would you provide some idea?

zhuowei commented 10 years ago

This is beyond my abilities as well, I'm afraid. Maybe just dex2jar the glass-core and glass-services, include them in an APK. and have a Service returning the timeline manager instance as a Binder?

I have no experience with writing Services, so I can't really help you here :(

xingrz commented 10 years ago

Thanks for inspiring me. Since the platform is getting better uncoupled, more features are separated from the GlassHome.apk and leading the porting gets more difficult. But luckily it's more easier to get an actual Glass today.

Anyway, should we close this issue?