use of com.didi.virtualapk.internal.LoadedPlugin in project AndroidLife by CaMnter.
the class PluginUtil method hookActivityResources.
public static void hookActivityResources(Activity activity, String packageName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && isVivo(activity.getResources())) {
// for 5.0+ vivo
return;
}
// designed for 5.0 - only, but some bad phones not work, eg:letv
try {
Context base = activity.getBaseContext();
final LoadedPlugin plugin = PluginManager.getInstance(activity).getLoadedPlugin(packageName);
final Resources resources = plugin.getResources();
if (resources != null) {
ReflectUtil.setField(base.getClass(), base, "mResources", resources);
// copy theme
Resources.Theme theme = resources.newTheme();
theme.setTo(activity.getTheme());
int themeResource = (int) ReflectUtil.getField(ContextThemeWrapper.class, activity, "mThemeResource");
theme.applyStyle(themeResource, true);
ReflectUtil.setField(ContextThemeWrapper.class, activity, "mTheme", theme);
ReflectUtil.setField(ContextThemeWrapper.class, activity, "mResources", resources);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.didi.virtualapk.internal.LoadedPlugin in project VirtualAPK by didi.
the class IContentProviderProxy method wrapperUri.
private void wrapperUri(Method method, Object[] args) {
Uri uri = null;
int index = 0;
if (args != null) {
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Uri) {
uri = (Uri) args[i];
index = i;
break;
}
}
}
Bundle bundleInCallMethod = null;
if (method.getName().equals("call")) {
bundleInCallMethod = getBundleParameter(args);
if (bundleInCallMethod != null) {
String uriString = bundleInCallMethod.getString(KEY_WRAPPER_URI);
if (uriString != null) {
uri = Uri.parse(uriString);
}
}
}
if (uri == null) {
return;
}
PluginManager pluginManager = PluginManager.getInstance(mContext);
ProviderInfo info = pluginManager.resolveContentProvider(uri.getAuthority(), 0);
if (info != null) {
String pkg = info.packageName;
LoadedPlugin plugin = pluginManager.getLoadedPlugin(pkg);
String pluginUri = Uri.encode(uri.toString());
StringBuilder builder = new StringBuilder(PluginContentResolver.getUri(mContext));
builder.append("/?plugin=" + plugin.getLocation());
builder.append("&pkg=" + pkg);
builder.append("&uri=" + pluginUri);
Uri wrapperUri = Uri.parse(builder.toString());
if (method.getName().equals("call")) {
bundleInCallMethod.putString(KEY_WRAPPER_URI, wrapperUri.toString());
} else {
args[index] = wrapperUri;
}
}
}
use of com.didi.virtualapk.internal.LoadedPlugin in project VirtualAPK by didi.
the class LocalService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (null == intent || !intent.hasExtra(EXTRA_TARGET) || !intent.hasExtra(EXTRA_COMMAND)) {
return START_STICKY;
}
Intent target = intent.getParcelableExtra(EXTRA_TARGET);
int command = intent.getIntExtra(EXTRA_COMMAND, 0);
if (null == target || command <= 0) {
return START_STICKY;
}
ComponentName component = target.getComponent();
LoadedPlugin plugin = mPluginManager.getLoadedPlugin(component);
// ClassNotFoundException when unmarshalling in Android 5.1
target.setExtrasClassLoader(plugin.getClassLoader());
switch(command) {
case EXTRA_COMMAND_START_SERVICE:
{
ActivityThread mainThread = (ActivityThread) ReflectUtil.getActivityThread(getBaseContext());
IApplicationThread appThread = mainThread.getApplicationThread();
Service service;
if (this.mPluginManager.getComponentsHandler().isServiceAvailable(component)) {
service = this.mPluginManager.getComponentsHandler().getService(component);
} else {
try {
service = (Service) plugin.getClassLoader().loadClass(component.getClassName()).newInstance();
Application app = plugin.getApplication();
IBinder token = appThread.asBinder();
Method attach = service.getClass().getMethod("attach", Context.class, ActivityThread.class, String.class, IBinder.class, Application.class, Object.class);
IActivityManager am = mPluginManager.getActivityManager();
attach.invoke(service, plugin.getPluginContext(), mainThread, component.getClassName(), token, app, am);
service.onCreate();
this.mPluginManager.getComponentsHandler().rememberService(component, service);
} catch (Throwable t) {
return START_STICKY;
}
}
service.onStartCommand(target, 0, this.mPluginManager.getComponentsHandler().getServiceCounter(service).getAndIncrement());
break;
}
case EXTRA_COMMAND_BIND_SERVICE:
{
ActivityThread mainThread = (ActivityThread) ReflectUtil.getActivityThread(getBaseContext());
IApplicationThread appThread = mainThread.getApplicationThread();
Service service = null;
if (this.mPluginManager.getComponentsHandler().isServiceAvailable(component)) {
service = this.mPluginManager.getComponentsHandler().getService(component);
} else {
try {
service = (Service) plugin.getClassLoader().loadClass(component.getClassName()).newInstance();
Application app = plugin.getApplication();
IBinder token = appThread.asBinder();
Method attach = service.getClass().getMethod("attach", Context.class, ActivityThread.class, String.class, IBinder.class, Application.class, Object.class);
IActivityManager am = mPluginManager.getActivityManager();
attach.invoke(service, plugin.getPluginContext(), mainThread, component.getClassName(), token, app, am);
service.onCreate();
this.mPluginManager.getComponentsHandler().rememberService(component, service);
} catch (Throwable t) {
t.printStackTrace();
}
}
try {
IBinder binder = service.onBind(target);
IBinder serviceConnection = PluginUtil.getBinder(intent.getExtras(), "sc");
IServiceConnection iServiceConnection = IServiceConnection.Stub.asInterface(serviceConnection);
if (Build.VERSION.SDK_INT >= 26) {
ReflectUtil.invokeNoException(IServiceConnection.class, iServiceConnection, "connected", new Class[] { ComponentName.class, IBinder.class, boolean.class }, new Object[] { component, binder, false });
} else {
iServiceConnection.connected(component, binder);
}
} catch (Exception e) {
e.printStackTrace();
}
break;
}
case EXTRA_COMMAND_STOP_SERVICE:
{
Service service = this.mPluginManager.getComponentsHandler().forgetService(component);
if (null != service) {
try {
service.onDestroy();
} catch (Exception e) {
Log.e(TAG, "Unable to stop service " + service + ": " + e.toString());
}
} else {
Log.i(TAG, component + " not found");
}
break;
}
case EXTRA_COMMAND_UNBIND_SERVICE:
{
Service service = this.mPluginManager.getComponentsHandler().forgetService(component);
if (null != service) {
try {
service.onUnbind(target);
service.onDestroy();
} catch (Exception e) {
Log.e(TAG, "Unable to unbind service " + service + ": " + e.toString());
}
} else {
Log.i(TAG, component + " not found");
}
break;
}
}
return START_STICKY;
}
use of com.didi.virtualapk.internal.LoadedPlugin in project VirtualAPK by didi.
the class PluginUtil method hookActivityResources.
public static void hookActivityResources(Activity activity, String packageName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && isVivo(activity.getResources())) {
// for 5.0+ vivo
return;
}
// designed for 5.0 - only, but some bad phones not work, eg:letv
try {
Context base = activity.getBaseContext();
final LoadedPlugin plugin = PluginManager.getInstance(activity).getLoadedPlugin(packageName);
final Resources resources = plugin.getResources();
if (resources != null) {
ReflectUtil.setField(base.getClass(), base, "mResources", resources);
// copy theme
Resources.Theme theme = resources.newTheme();
theme.setTo(activity.getTheme());
int themeResource = (int) ReflectUtil.getField(ContextThemeWrapper.class, activity, "mThemeResource");
theme.applyStyle(themeResource, true);
ReflectUtil.setField(ContextThemeWrapper.class, activity, "mTheme", theme);
ReflectUtil.setField(ContextThemeWrapper.class, activity, "mResources", resources);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.didi.virtualapk.internal.LoadedPlugin in project VirtualAPK by didi.
the class PluginUtil method getTheme.
public static int getTheme(Context context, ComponentName component) {
LoadedPlugin loadedPlugin = PluginManager.getInstance(context).getLoadedPlugin(component);
if (null == loadedPlugin) {
return 0;
}
ActivityInfo info = loadedPlugin.getActivityInfo(component);
if (null == info) {
return 0;
}
if (0 != info.theme) {
return info.theme;
}
ApplicationInfo appInfo = info.applicationInfo;
if (null != appInfo && appInfo.theme != 0) {
return appInfo.theme;
}
return PluginUtil.selectDefaultTheme(0, Build.VERSION.SDK_INT);
}
Aggregations