1
1
package com .genymobile .scrcpy ;
2
2
3
+ import android .annotation .SuppressLint ;
4
+ import android .content .pm .ApplicationInfo ;
3
5
import android .os .Looper ;
4
6
7
+ import java .lang .reflect .Constructor ;
8
+ import java .lang .reflect .Field ;
9
+
5
10
public final class Workarounds {
6
11
private Workarounds () {
7
12
// not instantiable
@@ -18,4 +23,42 @@ public static void prepareMainLooper() {
18
23
// <https://github.com/Genymobile/scrcpy/issues/921>
19
24
Looper .prepareMainLooper ();
20
25
}
26
+
27
+ @ SuppressLint ("PrivateApi" )
28
+ public static void fillAppInfo () {
29
+ try {
30
+ // ActivityThread activityThread = new ActivityThread();
31
+ Class <?> activityThreadClass = Class .forName ("android.app.ActivityThread" );
32
+ Constructor <?> activityThreadConstructor = activityThreadClass .getDeclaredConstructor ();
33
+ activityThreadConstructor .setAccessible (true );
34
+ Object activityThread = activityThreadConstructor .newInstance ();
35
+
36
+ // ActivityThread.sCurrentActivityThread = activityThread;
37
+ Field sCurrentActivityThreadField = activityThreadClass .getDeclaredField ("sCurrentActivityThread" );
38
+ sCurrentActivityThreadField .setAccessible (true );
39
+ sCurrentActivityThreadField .set (null , activityThread );
40
+
41
+ // ActivityThread.AppBindData appBindData = new ActivityThread.AppBindData();
42
+ Class <?> appBindDataClass = Class .forName ("android.app.ActivityThread$AppBindData" );
43
+ Constructor <?> appBindDataConstructor = appBindDataClass .getDeclaredConstructor ();
44
+ appBindDataConstructor .setAccessible (true );
45
+ Object appBindData = appBindDataConstructor .newInstance ();
46
+
47
+ ApplicationInfo applicationInfo = new ApplicationInfo ();
48
+ applicationInfo .packageName = "com.genymobile.scrcpy" ;
49
+
50
+ // appBindData.appInfo = applicationInfo;
51
+ Field appInfo = appBindDataClass .getDeclaredField ("appInfo" );
52
+ appInfo .setAccessible (true );
53
+ appInfo .set (appBindData , applicationInfo );
54
+
55
+ // activityThread.mBoundApplication = appBindData;
56
+ Field mBoundApplicationField = activityThreadClass .getDeclaredField ("mBoundApplication" );
57
+ mBoundApplicationField .setAccessible (true );
58
+ mBoundApplicationField .set (activityThread , appBindData );
59
+ } catch (Throwable throwable ) {
60
+ // this is a workaround, so failing is not an error
61
+ Ln .w ("Could not fill app info: " + throwable .getMessage ());
62
+ }
63
+ }
21
64
}
0 commit comments