[Xposed Framework Modules] Fif_:
So I've been trying to find a solution to the ActivityRecognitionResult.extractResult hook failure with Maps 10.12.1.

See this post for details.

The stock ActivityRecognitionResult.extractResult fails because for some reason, both com.google.android.gms.location.DetectedActivity and com.google.android.gms.location.ActivityRecognitionResult classes are not visible when running inside Maps, and bindClass fails with java.lang.ClassNotFoundException on either class names.

So I started thinking that we may want to modify ActivityRecognitionResult in-place instead of recreating a new one.

Problem #1: GMS is obfucated. The list of recognized activities is help in a java List, inside ActivityRecognitionResult but the member name is "zze" on my device, which is ProGuard-obfuscated and subject to change at any time.

Okay, no problem, I'll enumerate the members and use the only one that's a List. There I hit:

Problem #2: getClass() doesn't work.

In this code:

function after(hook, param)
local result = param:getResult()
if result == nil then
return false
end

local clsResult = result:getClass()
log('clsResult = ' .. tostring(clsResult))
if clsResult == nil then
log('clsResult is nil')
end
log('name = ' .. clsResult:getName())

return false
end

throws this error:

03-19 19:13:25.616 4436 4436 I XLua.Xposed: Log com.mani.activitylogger:10177 Privacy.ActivityRecognitionResult.extractResult clsResult = class com.google.android.gms.location.ActivityRecognitionResult (string)
03-19 19:13:25.616 4436 4436 E XLua.Xposed: Exception:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: org.luaj.vm2.LuaError: script:30 attempt to call nil
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaValue.checkmetatag(SourceFile:3365)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaValue.callmt(SourceFile:1997)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaValue.call(SourceFile:1450)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaClosure.execute(SourceFile:366)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaClosure.onInvoke(SourceFile:183)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaClosure.invoke(SourceFile:176)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at org.luaj.vm2.LuaValue.invoke(SourceFile:1789)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at eu.faircode.xlua.XLua$5.execute(SourceFile:491)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at eu.faircode.xlua.XLua$5.afterHookedMethod(SourceFile:457)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:374)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at com.google.android.gms.location.ActivityRecognitionResult.extractResult(<Xposed>)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at com.mani.activitylogger.service.ActivitiesLoggerService.onStartCommand(ActivitiesLoggerService.java:192)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3462)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at android.app.ActivityThread.-wrap21(ActivityThread.java)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1657)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at android.os.Handler.dispatchMessage(Handler.java:102)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at android.os.Looper.loop(Looper.java:154)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at android.app.ActivityThread.main(ActivityThread.java:6334)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at java.lang.reflect.Method.invoke(Native Method)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:
03-19 19:13:25.616 4436 4436 E XLua.Xposed:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: Package:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: com.mani.activitylogger:10177
03-19 19:13:25.616 4436 4436 E XLua.Xposed:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: Method:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: after public static com.google.android.gms.location.ActivityRecognitionResult com.google.android.gms.location.ActivityRecognitionResult.extractResult(android.content.Intent)
03-19 19:13:25.616 4436 4436 E XLua.Xposed:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: Arguments:
03-19 19:13:25.616 4436 4436 E XLua.Xposed: 0: Intent { cmp=com.mani.activitylogger/.service.ActivitiesLoggerService (has extras) } (android.content.Intent)

The exception is thrown by clsResult:getName().

Yet, clsResult is not nil, as shown by the log statement just before the exception is thrown.

Calling any member function of clsResult fails with the same error, getDeclaredMembers(), newInstance(), etc.

What's happening here? Can't we call getClass() on a java object and get a usable object?