2020-12-29 01:44:02 -08:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.ContextWrapper;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
public class DelegateApplication extends Application {
|
|
|
|
|
|
|
|
static boolean dynLoad = false;
|
|
|
|
|
2021-01-26 03:40:25 -08:00
|
|
|
private Application receiver;
|
|
|
|
|
2020-12-29 01:44:02 -08:00
|
|
|
@Override
|
|
|
|
protected void attachBaseContext(Context base) {
|
|
|
|
super.attachBaseContext(base);
|
|
|
|
|
2021-01-26 03:40:25 -08:00
|
|
|
// Only dynamic load full APK if hidden and supported
|
|
|
|
dynLoad = Build.VERSION.SDK_INT >= 21 &&
|
2020-12-29 01:44:02 -08:00
|
|
|
!base.getPackageName().equals(BuildConfig.APPLICATION_ID);
|
|
|
|
|
2021-01-26 03:40:25 -08:00
|
|
|
receiver = InjectAPK.setup(this);
|
|
|
|
if (receiver != null) try {
|
2020-12-29 01:44:02 -08:00
|
|
|
// Call attachBaseContext without ContextImpl to show it is being wrapped
|
|
|
|
Method m = ContextWrapper.class.getDeclaredMethod("attachBaseContext", Context.class);
|
|
|
|
m.setAccessible(true);
|
2021-01-26 03:40:25 -08:00
|
|
|
m.invoke(receiver, this);
|
2020-12-29 01:44:02 -08:00
|
|
|
} catch (Exception ignored) { /* Impossible */ }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2021-01-26 03:40:25 -08:00
|
|
|
if (receiver != null)
|
|
|
|
receiver.onConfigurationChanged(newConfig);
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
|
|
|
}
|