2020-12-29 01:44:02 -08:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AppComponentFactory;
|
|
|
|
import android.app.Application;
|
|
|
|
import android.app.Service;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.ContentProvider;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
public class DelegateComponentFactory extends AppComponentFactory {
|
|
|
|
|
|
|
|
ClassLoader loader;
|
2021-01-26 03:40:25 -08:00
|
|
|
AppComponentFactory receiver;
|
2020-12-29 01:44:02 -08:00
|
|
|
|
|
|
|
public DelegateComponentFactory() {
|
2021-04-17 22:14:54 -07:00
|
|
|
InjectAPK.componentFactory = this;
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Application instantiateApplication(ClassLoader cl, String className) {
|
|
|
|
if (loader == null) loader = cl;
|
|
|
|
return new DelegateApplication();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Activity instantiateActivity(ClassLoader cl, String className, Intent intent)
|
|
|
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
2021-01-26 03:40:25 -08:00
|
|
|
if (receiver != null)
|
|
|
|
return receiver.instantiateActivity(loader, className, intent);
|
|
|
|
return create(className);
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BroadcastReceiver instantiateReceiver(ClassLoader cl, String className, Intent intent)
|
|
|
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
2021-01-26 03:40:25 -08:00
|
|
|
if (receiver != null)
|
|
|
|
return receiver.instantiateReceiver(loader, className, intent);
|
|
|
|
return create(className);
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Service instantiateService(ClassLoader cl, String className, Intent intent)
|
|
|
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
2021-01-26 03:40:25 -08:00
|
|
|
if (receiver != null)
|
|
|
|
return receiver.instantiateService(loader, className, intent);
|
|
|
|
return create(className);
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ContentProvider instantiateProvider(ClassLoader cl, String className)
|
|
|
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
2021-01-26 03:40:25 -08:00
|
|
|
if (receiver != null)
|
|
|
|
return receiver.instantiateProvider(loader, className);
|
|
|
|
return create(className);
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
|
|
|
|
2021-01-26 03:40:25 -08:00
|
|
|
private <T> T create(String name)
|
|
|
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException{
|
|
|
|
return (T) loader.loadClass(name).newInstance();
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|
2021-01-22 20:45:37 -08:00
|
|
|
|
2020-12-29 01:44:02 -08:00
|
|
|
}
|