@ -1,11 +1,15 @@
package com.genymobile.scrcpy ;
import android.annotation.SuppressLint ;
import android.app.Application ;
import android.app.Instrumentation ;
import android.content.Context ;
import android.content.pm.ApplicationInfo ;
import android.os.Looper ;
import java.lang.reflect.Constructor ;
import java.lang.reflect.Field ;
import java.lang.reflect.Method ;
public final class Workarounds {
private Workarounds ( ) {
@ -56,6 +60,17 @@ public final class Workarounds {
Field mBoundApplicationField = activityThreadClass . getDeclaredField ( "mBoundApplication" ) ;
mBoundApplicationField . setAccessible ( true ) ;
mBoundApplicationField . set ( activityThread , appBindData ) ;
// Context ctx = activityThread.getSystemContext();
Method getSystemContextMethod = activityThreadClass . getDeclaredMethod ( "getSystemContext" ) ;
Context ctx = ( Context ) getSystemContextMethod . invoke ( activityThread ) ;
Application app = Instrumentation . newApplication ( Application . class , ctx ) ;
// activityThread.mInitialApplication = app;
Field mInitialApplicationField = activityThreadClass . getDeclaredField ( "mInitialApplication" ) ;
mInitialApplicationField . setAccessible ( true ) ;
mInitialApplicationField . set ( activityThread , app ) ;
} catch ( Throwable throwable ) {
// this is a workaround, so failing is not an error
Ln . w ( "Could not fill app info: " + throwable . getMessage ( ) ) ;