@@ -4,10 +4,16 @@ import android.app.AlarmManager
44import android.app.PendingIntent
55import android.content.Context
66import android.content.Intent
7+ import android.os.Bundle
78import android.os.Handler
89import android.os.Looper
910import android.os.Process
11+ import com.google.gson.Gson
12+ import com.google.gson.JsonArray
13+ import com.google.gson.JsonObject
1014import moe.yuuta.mipushtester.MainActivity
15+ import java.lang.reflect.Field
16+ import java.lang.reflect.Modifier
1117
1218object Utils {
1319 fun restart (context : Context ) {
@@ -23,4 +29,74 @@ object Utils {
2329 Runtime .getRuntime().exit(0 )
2430 }, 100 )
2531 }
32+
33+ fun dumpIntent (intent : Intent ): String {
34+ val trackMs: Long = System .currentTimeMillis()
35+ val rootJson: JsonObject = JsonObject ()
36+ rootJson.addProperty(" action" , intent.action)
37+ val categoriesJson: JsonArray = JsonArray ()
38+ if (intent.categories != null ) {
39+ for (category in intent.categories) {
40+ categoriesJson.add(category)
41+ }
42+ }
43+ rootJson.add(" categories" , categoriesJson)
44+ rootJson.addProperty(" clip_data_has" , intent.clipData != null )
45+ val componentJson: JsonObject = JsonObject ()
46+ componentJson.addProperty(" package_name" , intent.component?.packageName ? : " (Null)" )
47+ componentJson.addProperty(" class_name" , intent.component?.className ? : " (Null)" )
48+ rootJson.add(" component" , componentJson)
49+ rootJson.addProperty(" data_string" , intent.dataString)
50+ rootJson.addProperty(" flag_raw" , intent.flags)
51+ val flagFields: Array <Field >? = Intent ::class .java.declaredFields
52+ val flagsJson: JsonArray = JsonArray ()
53+ if (flagFields != null ) {
54+ for (flag in flagFields) {
55+ if (Modifier .isFinal(flag.modifiers) &&
56+ Modifier .isPublic(flag.modifiers) &&
57+ Modifier .isStatic(flag.modifiers) &&
58+ flag.name.startsWith(" FLAG_" )) {
59+ try {
60+ val value: Int = flag.get(null ) as Int
61+ if ((intent.flags and value) != 0 ) {
62+ flagsJson.add(flag.name)
63+ }
64+ } catch (ignored: Exception ) {}
65+ }
66+ }
67+ }
68+ rootJson.add(" flags" , flagsJson)
69+ rootJson.addProperty(" package" , intent.`package`)
70+ rootJson.addProperty(" scheme" , intent.scheme)
71+ rootJson.addProperty(" selector_has" , intent.selector != null )
72+ rootJson.addProperty(" source_bounds_has" , intent.sourceBounds != null )
73+ rootJson.addProperty(" type" , intent.type)
74+ rootJson.add(" extras" , dumpExtras(intent.extras))
75+ if (intent.hasExtra(" mipush_payload" )) {
76+ val payload: ByteArray = intent.getByteArrayExtra(" mipush_payload" )
77+ // TODO: Deserialize payload
78+ val payloadArray: JsonArray = JsonArray ()
79+ for (byte in payload) {
80+ payloadArray.add(byte)
81+ }
82+ rootJson.add(" payload" , payloadArray)
83+ }
84+ rootJson.addProperty(" took" , System .currentTimeMillis() - trackMs)
85+ return Gson ().toJson(rootJson)
86+ }
87+
88+ fun dumpExtras (bundle : Bundle ? ): JsonArray {
89+ val extrasJson: JsonArray = JsonArray ()
90+ if (bundle != null ) {
91+ for (key in bundle.keySet()) {
92+ val value = bundle.get(key)
93+ val obj: JsonObject = JsonObject ()
94+ obj.addProperty(" value" , value?.toString())
95+ obj.addProperty(" key" , key)
96+ obj.addProperty(" value_type" , value.javaClass.name)
97+ extrasJson.add(obj)
98+ }
99+ }
100+ return extrasJson
101+ }
26102}
0 commit comments