diff --git a/PlugLoadDemo/libs/pluginmgr-0.1.2.jar b/PlugLoadDemo/libs/pluginmgr-0.1.2.jar deleted file mode 100644 index 469eb51..0000000 Binary files a/PlugLoadDemo/libs/pluginmgr-0.1.2.jar and /dev/null differ diff --git a/PlugLoadDemo/project.properties b/PlugLoadDemo/project.properties index 4ab1256..1de5c72 100644 --- a/PlugLoadDemo/project.properties +++ b/PlugLoadDemo/project.properties @@ -12,3 +12,4 @@ # Project target. target=android-19 +android.library.reference.1=../PlugLoadMgr diff --git a/PlugLoadMgr/.classpath b/PlugLoadMgr/.classpath new file mode 100644 index 0000000..26bdfa6 --- /dev/null +++ b/PlugLoadMgr/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/android-pluginmgr/.project b/PlugLoadMgr/.project similarity index 50% rename from android-pluginmgr/.project rename to PlugLoadMgr/.project index 15c5b51..a954f29 100644 --- a/android-pluginmgr/.project +++ b/PlugLoadMgr/.project @@ -1,23 +1,33 @@ - - - android-pluginmgr - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - + + + PlugLoadMgr + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/android-pluginmgr/.settings/org.eclipse.jdt.core.prefs b/PlugLoadMgr/.settings/org.eclipse.jdt.core.prefs similarity index 71% rename from android-pluginmgr/.settings/org.eclipse.jdt.core.prefs rename to PlugLoadMgr/.settings/org.eclipse.jdt.core.prefs index 14f521d..b080d2d 100644 --- a/android-pluginmgr/.settings/org.eclipse.jdt.core.prefs +++ b/PlugLoadMgr/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/PlugLoadMgr/AndroidManifest.xml b/PlugLoadMgr/AndroidManifest.xml new file mode 100644 index 0000000..9a4342d --- /dev/null +++ b/PlugLoadMgr/AndroidManifest.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/PlugLoadMgr/bin/AndroidManifest.xml b/PlugLoadMgr/bin/AndroidManifest.xml new file mode 100644 index 0000000..9a4342d --- /dev/null +++ b/PlugLoadMgr/bin/AndroidManifest.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/PlugLoadMgr/bin/classes/android/widget/ViewStub$OnInflateListener.class b/PlugLoadMgr/bin/classes/android/widget/ViewStub$OnInflateListener.class new file mode 100644 index 0000000..6605044 Binary files /dev/null and b/PlugLoadMgr/bin/classes/android/widget/ViewStub$OnInflateListener.class differ diff --git a/PlugLoadMgr/bin/classes/android/widget/ViewStub.class b/PlugLoadMgr/bin/classes/android/widget/ViewStub.class new file mode 100644 index 0000000..cd11a9f Binary files /dev/null and b/PlugLoadMgr/bin/classes/android/widget/ViewStub.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/ActivityClassGenerator.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/ActivityClassGenerator.class new file mode 100644 index 0000000..1d051ae Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/ActivityClassGenerator.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/ActivityOverider.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/ActivityOverider.class new file mode 100644 index 0000000..6ca2a9d Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/ActivityOverider.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/BuildConfig.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/BuildConfig.class new file mode 100644 index 0000000..ec6975f Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/BuildConfig.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/CJClassLoader.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/CJClassLoader.class new file mode 100644 index 0000000..3b562ed Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/CJClassLoader.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/FileUtil.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/FileUtil.class new file mode 100644 index 0000000..55c8a48 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/FileUtil.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/IntReader.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/IntReader.class new file mode 100644 index 0000000..3d0ab87 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/IntReader.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/LayoutInflaterWrapper.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/LayoutInflaterWrapper.class new file mode 100644 index 0000000..7b007db Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/LayoutInflaterWrapper.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/NamespaceStack.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/NamespaceStack.class new file mode 100644 index 0000000..3f84612 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/NamespaceStack.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PlugInfo.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PlugInfo.class new file mode 100644 index 0000000..87f9128 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PlugInfo.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginActivityLifeCycleCallback.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginActivityLifeCycleCallback.class new file mode 100644 index 0000000..0087824 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginActivityLifeCycleCallback.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginActivityWrapper.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginActivityWrapper.class new file mode 100644 index 0000000..97f62d7 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginActivityWrapper.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginClassLoader$1.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginClassLoader$1.class new file mode 100644 index 0000000..c8530ef Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginClassLoader$1.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginClassLoader.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginClassLoader.class new file mode 100644 index 0000000..f20f581 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginClassLoader.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginContextWrapper.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginContextWrapper.class new file mode 100644 index 0000000..b3d5b57 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginContextWrapper.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManager$1.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManager$1.class new file mode 100644 index 0000000..ee02731 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManager$1.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManager.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManager.class new file mode 100644 index 0000000..ad8049c Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManager.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManifestUtil.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManifestUtil.class new file mode 100644 index 0000000..1b5561b Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginManifestUtil.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginPackageManager.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginPackageManager.class new file mode 100644 index 0000000..dfbd5f7 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/PluginPackageManager.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/ReflectionUtils.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/ReflectionUtils.class new file mode 100644 index 0000000..19b5b27 Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/ReflectionUtils.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/StringBlock.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/StringBlock.class new file mode 100644 index 0000000..015b3fc Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/StringBlock.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/XmlManifestReader.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/XmlManifestReader.class new file mode 100644 index 0000000..12e763a Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/XmlManifestReader.class differ diff --git a/PlugLoadMgr/bin/classes/androidx/pluginmgr/XmlResourceParser.class b/PlugLoadMgr/bin/classes/androidx/pluginmgr/XmlResourceParser.class new file mode 100644 index 0000000..89c17db Binary files /dev/null and b/PlugLoadMgr/bin/classes/androidx/pluginmgr/XmlResourceParser.class differ diff --git a/PlugLoadMgr/bin/plugloadmgr.jar b/PlugLoadMgr/bin/plugloadmgr.jar new file mode 100644 index 0000000..f4e7da4 Binary files /dev/null and b/PlugLoadMgr/bin/plugloadmgr.jar differ diff --git a/PlugLoadMgr/gen/androidx/pluginmgr/BuildConfig.java b/PlugLoadMgr/gen/androidx/pluginmgr/BuildConfig.java new file mode 100644 index 0000000..ea402c8 --- /dev/null +++ b/PlugLoadMgr/gen/androidx/pluginmgr/BuildConfig.java @@ -0,0 +1,6 @@ +/** Automatically generated file. DO NOT MODIFY */ +package androidx.pluginmgr; + +public final class BuildConfig { + public final static boolean DEBUG = true; +} \ No newline at end of file diff --git a/PlugLoadMgr/ic_launcher-web.png b/PlugLoadMgr/ic_launcher-web.png new file mode 100644 index 0000000..a18cbb4 Binary files /dev/null and b/PlugLoadMgr/ic_launcher-web.png differ diff --git a/PlugLoadDemo/libs/dexmaker-1.1.jar b/PlugLoadMgr/libs/dexmaker-1.1.jar similarity index 100% rename from PlugLoadDemo/libs/dexmaker-1.1.jar rename to PlugLoadMgr/libs/dexmaker-1.1.jar diff --git a/PlugLoadMgr/proguard-project.txt b/PlugLoadMgr/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/PlugLoadMgr/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/PlugLoadMgr/project.properties b/PlugLoadMgr/project.properties new file mode 100644 index 0000000..93c8c3c --- /dev/null +++ b/PlugLoadMgr/project.properties @@ -0,0 +1,15 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-21 +android.library=true diff --git a/android-pluginmgr/src/main/java/android/widget/ViewStub.java b/PlugLoadMgr/src/android/widget/ViewStub.java similarity index 100% rename from android-pluginmgr/src/main/java/android/widget/ViewStub.java rename to PlugLoadMgr/src/android/widget/ViewStub.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/ActivityClassGenerator.java b/PlugLoadMgr/src/androidx/pluginmgr/ActivityClassGenerator.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/ActivityClassGenerator.java rename to PlugLoadMgr/src/androidx/pluginmgr/ActivityClassGenerator.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/ActivityOverider.java b/PlugLoadMgr/src/androidx/pluginmgr/ActivityOverider.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/ActivityOverider.java rename to PlugLoadMgr/src/androidx/pluginmgr/ActivityOverider.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/FrameworkClassLoader.java b/PlugLoadMgr/src/androidx/pluginmgr/CJClassLoader.java similarity index 94% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/FrameworkClassLoader.java rename to PlugLoadMgr/src/androidx/pluginmgr/CJClassLoader.java index 7745e02..4a94e0f 100644 --- a/android-pluginmgr/src/main/java/androidx/pluginmgr/FrameworkClassLoader.java +++ b/PlugLoadMgr/src/androidx/pluginmgr/CJClassLoader.java @@ -23,11 +23,11 @@ * @author HouKangxi * */ -class FrameworkClassLoader extends ClassLoader { +class CJClassLoader extends ClassLoader { private String plugId; private String actName; - public FrameworkClassLoader(ClassLoader parent) { + public CJClassLoader(ClassLoader parent) { super(parent); } diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/FileUtil.java b/PlugLoadMgr/src/androidx/pluginmgr/FileUtil.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/FileUtil.java rename to PlugLoadMgr/src/androidx/pluginmgr/FileUtil.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/LayoutInflaterWrapper.java b/PlugLoadMgr/src/androidx/pluginmgr/LayoutInflaterWrapper.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/LayoutInflaterWrapper.java rename to PlugLoadMgr/src/androidx/pluginmgr/LayoutInflaterWrapper.java diff --git a/PlugLoadMgr/src/androidx/pluginmgr/PlugInfo.java b/PlugLoadMgr/src/androidx/pluginmgr/PlugInfo.java new file mode 100644 index 0000000..6a0231f --- /dev/null +++ b/PlugLoadMgr/src/androidx/pluginmgr/PlugInfo.java @@ -0,0 +1,363 @@ +/* + * Copyright (C) 2015 HouKx + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package androidx.pluginmgr; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import android.app.Application; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; +import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; +import android.content.res.AssetManager; +import android.content.res.Resources; + +/** + * 一个插件的信息 + * + * @author HouKangxi + * + */ +public class PlugInfo { + + private String id; + private String filePath; + private PackageInfo packageInfo; + private ResolveInfo mainActivity; + private Map activities; // 插件的全部Activity + private List services; // 插件的全部services + private List receivers; // 插件的全部receivers + private List providers; // 插件的全部providers + + private transient PluginClassLoader classLoader; + private transient Application application; + private transient AssetManager assetManager; + private transient Resources resources; + /* package */PluginContextWrapper appWrapper; + + // + // private transient volatile String currentActivityClass; + + public String getPackageName() { + return packageInfo.packageName; + } + + // ================== FLAGS STARD ================== + /** + * 按下back键时是否 finish Activity + */ + private static final int FLAG_FinishActivityOnbackPressed = 1; + /** + * 是否调用父类的onBackPressed()方法 + */ + private static final int FLAG_INVOKE_SUPER_ONBACKPRESSED = 2; + + // ================== FLAGS END ================== + /** + * 按Back键时是否销毁Activity + */ + public boolean isFinishActivityOnbackPressed(ActivityInfo act) { + if (act == null) { + return false; + } + int flags = getFlags(act); + return containsFlag(flags, FLAG_FinishActivityOnbackPressed); + } + + public boolean isInvokeSuperOnbackPressed(ActivityInfo act) { + if (act == null) { + return true; + } + int flags = getFlags(act); + if (flags == 0) { + return true;// 默认true + } + return containsFlag(flags, FLAG_INVOKE_SUPER_ONBACKPRESSED); + } + + public void setInvokeSuperOnbackPressed(ActivityInfo act, + boolean invokeSuperOnbackPressed) { + if (act == null) { + return; + } + if (invokeSuperOnbackPressed) { + setFlag(act, FLAG_INVOKE_SUPER_ONBACKPRESSED); + } else { + unsetFlag(act, FLAG_INVOKE_SUPER_ONBACKPRESSED); + } + } + + public void setFinishActivityOnbackPressed(ActivityInfo act, + boolean finishOnbackPressed) { + if (act == null) { + return; + } + if (finishOnbackPressed) { + setFlag(act, FLAG_FinishActivityOnbackPressed); + } else { + unsetFlag(act, FLAG_FinishActivityOnbackPressed); + } + } + + ActivityInfo findActivityByClassNameFromPkg(String actName) { + if (packageInfo.activities == null) { + return null; + } + for (ActivityInfo act : packageInfo.activities) { + if (act.name.equals(actName)) { + return act; + } + } + return null; + } + + public ActivityInfo findActivityByClassName(String actName) { + if (packageInfo.activities == null) { + return null; + } + ResolveInfo act = activities.get(actName); + if (act == null) { + return null; + } + return act.activityInfo; + } + + public ActivityInfo findActivityByAction(String action) { + if (activities == null || activities.isEmpty()) { + return null; + } + for (ResolveInfo act : activities.values()) { + if (act.filter != null && act.filter.hasAction(action)) { + return act.activityInfo; + } + } + return null; + } + + public ActivityInfo findReceiverByClassName(String className) { + if (packageInfo.receivers == null) { + return null; + } + for (ActivityInfo receiver : packageInfo.receivers) { + if (receiver.name.equals(className)) { + return receiver; + } + } + return null; + + } + + public ServiceInfo findServiceByClassName(String className) { + if (packageInfo.services == null) { + return null; + } + for (ServiceInfo service : packageInfo.services) { + if (service.name.equals(className)) { + return service; + } + } + return null; + + } + + public ServiceInfo findServiceByAction(String action) { + if (services == null || services.isEmpty()) { + return null; + } + for (ResolveInfo ser : services) { + if (ser.filter != null && ser.filter.hasAction(action)) { + return ser.serviceInfo; + } + } + return null; + } + + public void addActivity(ResolveInfo activity) { + if (activities == null) { + activities = new HashMap(20); + } + activities.put(activity.activityInfo.name, activity); + if (mainActivity == null + && activity.filter != null + && activity.filter.hasAction("android.intent.action.MAIN") + && activity.filter + .hasCategory("android.intent.category.LAUNCHER")) { + mainActivity = activity; + } + } + + public void addReceiver(ResolveInfo receiver) { + if (receivers == null) { + receivers = new ArrayList(); + } + receivers.add(receiver); + } + + public void addService(ResolveInfo service) { + if (services == null) { + services = new ArrayList(); + } + services.add(service); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public PackageInfo getPackageInfo() { + return packageInfo; + } + + public void setPackageInfo(PackageInfo packageInfo) { + this.packageInfo = packageInfo; + activities = new HashMap( + packageInfo.activities.length); + } + + public PluginClassLoader getClassLoader() { + return classLoader; + } + + public void setClassLoader(PluginClassLoader classLoader) { + this.classLoader = classLoader; + } + + public Application getApplication() { + return application; + } + + public void setApplication(Application application) { + this.application = application; + } + + public AssetManager getAssetManager() { + return assetManager; + } + + public void setAssetManager(AssetManager assetManager) { + this.assetManager = assetManager; + } + + public Resources getResources() { + return resources; + } + + public void setResources(Resources resources) { + this.resources = resources; + } + + // public String getCurrentActivityClass() { + // return currentActivityClass; + // } + // + // public void setCurrentActivityClass(String currentActivityClass) { + // this.currentActivityClass = currentActivityClass; + // } + + public Collection getActivities() { + if (activities == null) { + return null; + } + return activities.values(); + } + + public List getServices() { + return services; + } + + public void setServices(List services) { + this.services = services; + } + + public List getProviders() { + return providers; + } + + public void setProviders(List providers) { + this.providers = providers; + } + + public ResolveInfo getMainActivity() { + return mainActivity; + } + + public List getReceivers() { + return receivers; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PlugInfo other = (PlugInfo) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + @Override + public String toString() { + return super.toString() + "[ id=" + id + ", pkg=" + getPackageName() + + " ]"; + } + + private static synchronized int getFlags(ActivityInfo act) { + return act.logo; + } + + private static synchronized void setFlag(ActivityInfo act, int flag) { + act.logo |= flag; + } + + private static synchronized void unsetFlag(ActivityInfo act, int flag) { + act.logo &= ~flag; + } + + private static boolean containsFlag(int vFlags, int flag) { + return (vFlags & flag) == flag; + } +} diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginActivityLifeCycleCallback.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginActivityLifeCycleCallback.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/PluginActivityLifeCycleCallback.java rename to PlugLoadMgr/src/androidx/pluginmgr/PluginActivityLifeCycleCallback.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginActivityWrapper.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginActivityWrapper.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/PluginActivityWrapper.java rename to PlugLoadMgr/src/androidx/pluginmgr/PluginActivityWrapper.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginClassLoader.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginClassLoader.java similarity index 98% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/PluginClassLoader.java rename to PlugLoadMgr/src/androidx/pluginmgr/PluginClassLoader.java index 76f0605..8669415 100644 --- a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginClassLoader.java +++ b/PlugLoadMgr/src/androidx/pluginmgr/PluginClassLoader.java @@ -87,7 +87,7 @@ private Class findByParent(String name,boolean throwEx)throws ClassNotFound try { ClassLoader parent = getParent(); if (parent != null) { - if (parent.getClass() == FrameworkClassLoader.class) { + if (parent.getClass() == CJClassLoader.class) { parent = parent.getParent(); } if (parent != null) { diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginContextWrapper.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginContextWrapper.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/PluginContextWrapper.java rename to PlugLoadMgr/src/androidx/pluginmgr/PluginContextWrapper.java diff --git a/PlugLoadMgr/src/androidx/pluginmgr/PluginManager.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginManager.java new file mode 100644 index 0000000..4f54595 --- /dev/null +++ b/PlugLoadMgr/src/androidx/pluginmgr/PluginManager.java @@ -0,0 +1,527 @@ +/* + * Copyright (C) 2015 HouKx + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package androidx.pluginmgr; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileNotFoundException; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import android.app.Activity; +import android.app.Application; +import android.app.Service; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.res.AssetManager; +import android.content.res.Resources; +import android.util.Log; + +/** + * The Plug-in Manager
+ * 命名规则:以app开头的,是与宿主app相关变量;以plug开头的,是插件相关变量 + * + * + * @author HouKangxi + * @author kymjs + */ +public class PluginManager implements FileFilter { + private static final String tag = "plugmgr"; + + private static final PluginManager instance = new PluginManager(); + private Context context; + + private final Map pluginIdToInfoMap = new ConcurrentHashMap(); + private final Map pluginPkgToInfoMap = new ConcurrentHashMap(); + private PluginActivityLifeCycleCallback pluginActivityLifeCycleCallback; + + private String dexOutputPath; // DEX输出路径(包内存储) + private File dexInternalStoragePath; + private CJClassLoader classLoader; + + // 定义两个原子变量来保存状态 + private volatile boolean hasInit = false; // 是否已经初始化 + private volatile Activity appAty; // 宿主Activity实例 + + private PluginManager() {} + + public static PluginManager getInstance(Context context) { + if (instance.hasInit || context == null) { + if (instance.appAty == null && context instanceof Activity) { + instance.appAty = (Activity) context; + } + return instance; + } else { + Context ctx = context; + if (context instanceof Activity) { + instance.appAty = (Activity) context; + ctx = ((Activity) context).getApplication(); + } else if (context instanceof Service) { + ctx = ((Service) context).getApplication(); + } else if (context instanceof Application) { + ctx = context; + } else { + ctx = context.getApplicationContext(); + } + synchronized (PluginManager.class) { + instance.init(ctx); + } + return instance; + } + } + + /* package */static PluginManager getInstance() { + return instance; + } + + /** + * 初始化CJClassLoader,替换Application中的classloader + * + * @author kymjs + */ + private void init(Context cxt) { + context = cxt; + + File optimizedDexPath = cxt.getDir("dexPath", Context.MODE_PRIVATE); + if (!optimizedDexPath.exists()) { + optimizedDexPath.mkdirs(); + } + dexOutputPath = optimizedDexPath.getAbsolutePath(); + + dexInternalStoragePath = context + .getDir("plugins", Context.MODE_PRIVATE); + dexInternalStoragePath.mkdirs(); + + try { + Object mPackageInfo = ReflectionUtils.getFieldValue(cxt, + "mBase.mPackageInfo", true); + classLoader = new CJClassLoader(cxt.getClassLoader()); + // 反射修改Application的classloader + ReflectionUtils.setFieldValue(mPackageInfo, "mClassLoader", + classLoader, true); + } catch (Exception e) { + e.printStackTrace(); + } + hasInit = true; + } + + public boolean startMainActivity(Context context, String pkgOrId) { + PlugInfo plug = getPlugActivityInfo(context, pkgOrId); + if (classLoader == null) { + Log.e(tag, "startMainActivity: frameworkClassLoader == null!"); + return false; + } + if (plug.getMainActivity() == null) { + Log.e(tag, "startMainActivity: plug.getMainActivity() == null!"); + return false; + } + if (plug.getMainActivity().activityInfo == null) { + Log.e(tag, + "startMainActivity: plug.getMainActivity().activityInfo == null!"); + return false; + } + String className = classLoader.newActivityClassName(plug.getId(), + plug.getMainActivity().activityInfo.name); + context.startActivity(new Intent().setComponent(new ComponentName( + context, className))); + return true; + } + + public void startActivity(Context context, Intent intent) { + performStartActivity(context, intent); + context.startActivity(intent); + } + + public void startActivityForResult(Activity activity, Intent intent, + int requestCode) { + performStartActivity(context, intent); + activity.startActivityForResult(intent, requestCode); + } + + /** + * + * @param context + * @param plugIdOrPkg + * @return + */ + private PlugInfo getPlugActivityInfo(Context context, String plugIdOrPkg) { + PlugInfo plug = null; + plug = getPluginByPackageName(plugIdOrPkg); + if (plug == null) { + plug = getPluginById(plugIdOrPkg); + } + if (plug == null) { + throw new IllegalArgumentException("plug not found by:" + + plugIdOrPkg); + } + return plug; + } + + private void performStartActivity(Context context, Intent intent) { + checkInit(); + + String plugIdOrPkg; + String actName; + ComponentName origComp = intent.getComponent(); + if (origComp != null) { + plugIdOrPkg = origComp.getPackageName(); + actName = origComp.getClassName(); + } else { + throw new IllegalArgumentException( + "plug intent must set the ComponentName!"); + } + PlugInfo plug = getPlugActivityInfo(context, plugIdOrPkg); + String className = classLoader.newActivityClassName(plug.getId(), + actName); + Log.i(tag, "performStartActivity: " + actName); + ComponentName comp = new ComponentName(context, className); + intent.setAction(null); + intent.setComponent(comp); + } + + private void checkInit() { + if (!hasInit) { + throw new IllegalStateException("PluginManager has not init!"); + } + } + + public PlugInfo getPluginById(String pluginId) { + if (pluginId == null) { + return null; + } + return pluginIdToInfoMap.get(pluginId); + } + + public PlugInfo getPluginByPackageName(String packageName) { + return pluginPkgToInfoMap.get(packageName); + } + + public Collection getPlugins() { + return pluginIdToInfoMap.values(); + } + + public void uninstallPluginById(String pluginId) { + uninstallPlugin(pluginId, true); + } + + public void uninstallPluginByPkg(String pkg) { + uninstallPlugin(pkg, false); + } + + private void uninstallPlugin(String k, boolean isId) { + checkInit(); + PlugInfo pl = isId ? removePlugById(k) : removePlugByPkg(k); + if (pl == null) { + return; + } + if (context instanceof Application) { + if (android.os.Build.VERSION.SDK_INT >= 14) { + try { + Application.class + .getMethod( + "unregisterComponentCallbacks", + Class.forName("android.content.ComponentCallbacks")) + .invoke(context, pl.getApplication()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + private PlugInfo removePlugById(String pluginId) { + PlugInfo pl = null; + synchronized (this) { + pl = pluginIdToInfoMap.remove(pluginId); + if (pl == null) { + return null; + } + pluginPkgToInfoMap.remove(pl.getPackageName()); + } + return pl; + } + + private PlugInfo removePlugByPkg(String pkg) { + PlugInfo pl = null; + synchronized (this) { + pl = pluginPkgToInfoMap.remove(pkg); + if (pl == null) { + return null; + } + pluginIdToInfoMap.remove(pl.getId()); + } + return pl; + } + + /** + * 加载指定插件或指定目录下的所有插件 + *

+ * 都使用文件名作为Id + * + * @param pluginSrcDirFile + * - apk或apk目录 + * @return 插件集合 + * @throws Exception + */ + public Collection loadPlugin(final File pluginSrcDirFile) + throws Exception { + checkInit(); + if (pluginSrcDirFile == null || !pluginSrcDirFile.exists()) { + Log.e(tag, "invalidate plugin file or Directory :" + + pluginSrcDirFile); + return null; + } + if (pluginSrcDirFile.isFile()) { + // 如果是文件则尝试加载单个插件,暂不检查文件类型,除apk外,以后可能支持加载其他类型文件,如jar + PlugInfo one = loadPluginWithId(pluginSrcDirFile, null, null); + return Collections.singletonList(one); + } + // clear all first + synchronized (this) { + pluginPkgToInfoMap.clear(); + pluginIdToInfoMap.clear(); + } + File[] pluginApks = pluginSrcDirFile.listFiles(this); + if (pluginApks == null || pluginApks.length < 1) { + throw new FileNotFoundException("could not find plugins in:" + + pluginSrcDirFile); + } + for (File pluginApk : pluginApks) { + PlugInfo plugInfo = buildPlugInfo(pluginApk, null, null); + if (plugInfo != null) { + savePluginToMap(plugInfo); + } + } + return pluginIdToInfoMap.values(); + } + + private synchronized void savePluginToMap(PlugInfo plugInfo) { + pluginPkgToInfoMap.put(plugInfo.getPackageName(), plugInfo); + pluginIdToInfoMap.put(plugInfo.getId(), plugInfo); + } + + // /** + // * 单独加载一个apk
+ // * 使用文件名作为插件id
+ // * 目标文件也是与源文件同名 + // * + // * @param pluginApk + // * @return + // * @throws Exception + // */ + // public PlugInfo loadPlugin(File pluginApk) throws Exception { + // return loadPluginWithId(pluginApk, null, null); + // } + + /** + * 单独加载一个apk + * + * @param pluginApk + * @param pluginId + * - 如果参数为null,则使用文件名作为插件id + * @return + * @throws Exception + */ + public PlugInfo loadPluginWithId(File pluginApk, String pluginId) + throws Exception { + return loadPluginWithId(pluginApk, pluginId, null); + } + + public PlugInfo loadPluginWithId(File pluginApk, String pluginId, + String targetFileName) throws Exception { + checkInit(); + PlugInfo plugInfo = buildPlugInfo(pluginApk, pluginId, targetFileName); + if (plugInfo != null) { + savePluginToMap(plugInfo); + } + return plugInfo; + } + + private PlugInfo buildPlugInfo(File pluginApk, String pluginId, + String targetFileName) throws Exception { + PlugInfo info = new PlugInfo(); + info.setId(pluginId == null ? pluginApk.getName() : pluginId); + + File privateFile = new File(dexInternalStoragePath, + targetFileName == null ? pluginApk.getName() : targetFileName); + + info.setFilePath(privateFile.getAbsolutePath()); + + if (!pluginApk.getAbsolutePath().equals(privateFile.getAbsolutePath())) { + copyApkToPrivatePath(pluginApk, privateFile); + } + String dexPath = privateFile.getAbsolutePath(); + PluginManifestUtil.setManifestInfo(context, dexPath, info); + + PluginClassLoader loader = new PluginClassLoader(dexPath, + dexOutputPath, classLoader, info); + info.setClassLoader(loader); + + try { + AssetManager am = AssetManager.class.newInstance(); + am.getClass().getMethod("addAssetPath", String.class) + .invoke(am, dexPath); + info.setAssetManager(am); + Resources ctxres = context.getResources(); + Resources res = new Resources(am, ctxres.getDisplayMetrics(), + ctxres.getConfiguration()); + info.setResources(res); + } catch (Exception e) { + e.printStackTrace(); + } + if (appAty != null) { + initPluginApplication(info, appAty, true); + } + // createPluginActivityProxyDexes(info); + Log.i(tag, "buildPlugInfo: " + info); + return info; + } + + // private void createPluginActivityProxyDexes(PlugInfo plugin) { + // { + // ActInfo act = plugin.getApplicationInfo().getMainActivity(); + // if (act != null) { + // ActivityOverider.createProxyDex(plugin, act.name, false); + // } + // } + // if (plugin.getApplicationInfo().getOtherActivities() != null) { + // for (ActInfo act : plugin.getApplicationInfo().getOtherActivities()) + // { + // ActivityOverider.createProxyDex(plugin, act.name, false); + // } + // } + // } + void initPluginApplication(final PlugInfo info, Activity actFrom) + throws Exception { + initPluginApplication(info, actFrom, false); + } + + private void initPluginApplication(final PlugInfo plugin, Activity actFrom, + boolean onLoad) throws Exception { + if (!onLoad && plugin.getApplication() != null) { + return; + } + final String className = plugin.getPackageInfo().applicationInfo.name; + if (className == null) { + if (onLoad) { + return; + } + Application application = new Application(); + setApplicationBase(plugin, application); + return; + } + Log.d(tag, plugin.getId() + ", ApplicationClassName = " + className); + + Runnable setApplicationTask = new Runnable() { + @Override + public void run() { + ClassLoader loader = plugin.getClassLoader(); + try { + Class applicationClass = loader.loadClass(className); + Application application = (Application) applicationClass + .newInstance(); + setApplicationBase(plugin, application); + // invoke plugin application's onCreate() + application.onCreate(); + } catch (Throwable e) { + Log.e(tag, Log.getStackTraceString(e)); + } + } + }; + // create Application instance for plugin + if (actFrom == null) { + if (onLoad) + return; + setApplicationTask.run(); + } else { + actFrom.runOnUiThread(setApplicationTask); + } + } + + private void setApplicationBase(PlugInfo plugin, Application application) + throws Exception { + + synchronized (plugin) { + if (plugin.getApplication() != null) { + // set plugin's Application only once + return; + } + plugin.setApplication(application); + // + PluginContextWrapper ctxWrapper = new PluginContextWrapper(context, + plugin); + plugin.appWrapper = ctxWrapper; + // attach + Method attachMethod = android.app.Application.class + .getDeclaredMethod("attach", Context.class); + attachMethod.setAccessible(true); + attachMethod.invoke(application, ctxWrapper); + if (context instanceof Application) { + if (android.os.Build.VERSION.SDK_INT >= 14) { + Application.class + .getMethod( + "registerComponentCallbacks", + Class.forName("android.content.ComponentCallbacks")) + .invoke(context, application); + } + } + + } + } + + private void copyApkToPrivatePath(File pluginApk, File f) { + // if (f.exists() && pluginApk.length() == f.length()) { + // // 这里只是简单的判断如果两个文件长度相同则不拷贝,严格的做应该比较签名如 md5\sha-1 + // return; + // } + FileUtil.copyFile(pluginApk, f); + } + + File getDexInternalStoragePath() { + return dexInternalStoragePath; + } + + Context getContext() { + return context; + } + + public PluginActivityLifeCycleCallback getPluginActivityLifeCycleCallback() { + return pluginActivityLifeCycleCallback; + } + + public void setPluginActivityLifeCycleCallback( + PluginActivityLifeCycleCallback pluginActivityLifeCycleCallback) { + this.pluginActivityLifeCycleCallback = pluginActivityLifeCycleCallback; + } + + CJClassLoader getFrameworkClassLoader() { + return classLoader; + } + + @Override + public boolean accept(File pathname) { + if (pathname.isDirectory()) { + return false; + } + String fname = pathname.getName(); + return fname.endsWith(".apk"); + } + +} diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginManifestUtil.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginManifestUtil.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/PluginManifestUtil.java rename to PlugLoadMgr/src/androidx/pluginmgr/PluginManifestUtil.java diff --git a/PlugLoadMgr/src/androidx/pluginmgr/PluginPackageManager.java b/PlugLoadMgr/src/androidx/pluginmgr/PluginPackageManager.java new file mode 100644 index 0000000..1368f41 --- /dev/null +++ b/PlugLoadMgr/src/androidx/pluginmgr/PluginPackageManager.java @@ -0,0 +1,784 @@ +/* + * Copyright (C) 2015 HouKx + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package androidx.pluginmgr; + +import java.util.List; + +import android.content.ComponentName; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.FeatureInfo; +import android.content.pm.InstrumentationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageInstaller; +import android.content.pm.PackageManager; +import android.content.pm.PermissionGroupInfo; +import android.content.pm.PermissionInfo; +import android.content.pm.ProviderInfo; +import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; +import android.content.res.Resources; +import android.content.res.XmlResourceParser; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.UserHandle; + +/** + * Customer PackageManager + *

+ * + * TODO unfinished, prepare use in + * {@link PluginContextWrapper#getPackageManager} + * + * @author HouKangxi + * + */ +public class PluginPackageManager extends PackageManager { + private final PackageManager orig; + + public PluginPackageManager(PackageManager wrapper) { + this.orig = wrapper; + } + + @Override + public PackageInfo getPackageInfo(String packageName, int flags) + throws NameNotFoundException { + PlugInfo plugin = PluginManager.getInstance().getPluginByPackageName( + packageName); + if (plugin != null) { + return plugin.getPackageInfo(); + } + return orig.getPackageInfo(packageName, flags); + } + + @Override + public String[] currentToCanonicalPackageNames(String[] names) { + return orig.currentToCanonicalPackageNames(names); + } + + @Override + public String[] canonicalToCurrentPackageNames(String[] names) { + return orig.canonicalToCurrentPackageNames(names); + } + + @Override + public Intent getLaunchIntentForPackage(String packageName) { + // PlugInfo plugin = + // PluginManager.getInstance().getPluginByPackageName(packageName); + // if (plugin != null) { + // //TODO + // } + return orig.getLaunchIntentForPackage(packageName); + } + + @Override + public int[] getPackageGids(String packageName) + throws NameNotFoundException { + PlugInfo plugin = PluginManager.getInstance().getPluginByPackageName( + packageName); + if (plugin != null) { + return plugin.getPackageInfo().gids; + } + return orig.getPackageGids(packageName); + } + + @Override + public PermissionInfo getPermissionInfo(String name, int flags) + throws NameNotFoundException { + // TODO + return orig.getPermissionInfo(name, flags); + } + + @Override + public List queryPermissionsByGroup(String group, int flags) + throws NameNotFoundException { + // TODO + return orig.queryPermissionsByGroup(group, flags); + } + + @Override + public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) + throws NameNotFoundException { + // TODO + return orig.getPermissionGroupInfo(name, flags); + } + + @Override + public List getAllPermissionGroups(int flags) { + // TODO + return orig.getAllPermissionGroups(flags); + } + + @Override + public ApplicationInfo getApplicationInfo(String packageName, int flags) + throws NameNotFoundException { + PlugInfo plugin = PluginManager.getInstance().getPluginByPackageName( + packageName); + if (plugin != null) { + return plugin.getPackageInfo().applicationInfo; + } + return orig.getApplicationInfo(packageName, flags); + } + + @Override + public ActivityInfo getActivityInfo(ComponentName component, int flags) + throws NameNotFoundException { + String packageName = component.getPackageName(); + if (packageName != null) { + PlugInfo plugin = PluginManager.getInstance() + .getPluginByPackageName(packageName); + if (plugin != null) { + String actClassName = component.getClassName(); + if (actClassName != null) { + return plugin.findActivityByClassName(actClassName); + } + } + } + return orig.getActivityInfo(component, flags); + } + + @Override + public ActivityInfo getReceiverInfo(ComponentName component, int flags) + throws NameNotFoundException { + String packageName = component.getPackageName(); + if (packageName != null) { + PlugInfo plugin = PluginManager.getInstance() + .getPluginByPackageName(packageName); + if (plugin != null) { + String className = component.getClassName(); + if (className != null) { + return plugin.findReceiverByClassName(className); + } + } + } + return orig.getReceiverInfo(component, flags); + } + + @Override + public ServiceInfo getServiceInfo(ComponentName component, int flags) + throws NameNotFoundException { + String packageName = component.getPackageName(); + if (packageName != null) { + PlugInfo plugin = PluginManager.getInstance() + .getPluginByPackageName(packageName); + if (plugin != null) { + String className = component.getClassName(); + if (className != null) { + return plugin.findServiceByClassName(className); + } + } + } + return orig.getServiceInfo(component, flags); + } + + @Override + public ProviderInfo getProviderInfo(ComponentName component, int flags) + throws NameNotFoundException { + // TODO getProviderInfo + return orig.getProviderInfo(component, flags); + } + + @Override + public List getInstalledPackages(int flags) { + return orig.getInstalledPackages(flags); + } + + @Override + public int checkPermission(String permName, String pkgName) { + // TODO checkPermission + return orig.checkPermission(permName, pkgName); + } + + @Override + public boolean addPermission(PermissionInfo info) { + // TODO addPermission + return orig.addPermission(info); + } + + @Override + public boolean addPermissionAsync(PermissionInfo info) { + // TODO addPermissionAsync + return orig.addPermission(info); + } + + @Override + public void removePermission(String name) { + // TODO removePermission + orig.removePermission(name); + } + + @Override + public int checkSignatures(String pkg1, String pkg2) { + // TODO checkSignatures + return orig.checkSignatures(pkg1, pkg2); + } + + @Override + public int checkSignatures(int uid1, int uid2) { + // TODO checkSignatures + return orig.checkSignatures(uid1, uid2); + } + + @Override + public String[] getPackagesForUid(int uid) { + // TODO getPackagesForUid + return orig.getPackagesForUid(uid); + } + + @Override + public String getNameForUid(int uid) { + // TODO getNameForUid + return orig.getNameForUid(uid); + } + + @Override + public List getInstalledApplications(int flags) { + return orig.getInstalledApplications(flags); + } + + @Override + public String[] getSystemSharedLibraryNames() { + // TODO getSystemSharedLibraryNames + return orig.getSystemSharedLibraryNames(); + } + + @Override + public FeatureInfo[] getSystemAvailableFeatures() { + // TODO getSystemAvailableFeatures + return orig.getSystemAvailableFeatures(); + } + + @Override + public boolean hasSystemFeature(String name) { + // TODO hasSystemFeature + return orig.hasSystemFeature(name); + } + + @Override + public ResolveInfo resolveActivity(Intent intent, int flags) { + // TODO resolveActivity + // ComponentName compname = intent.getComponent(); + // if(compname!=null){ + // String packageName = compname.getPackageName(); + // if(packageName!=null){ + // PlugInfo plug = + // PluginManager.getInstance().getPluginByPackageName(packageName); + // if (plug != null) { + // String className = compname.getClassName(); + // if(className!=null){ + // return plug.resolveActivity() + // } + // } + // } + // } + return orig.resolveActivity(intent, flags); + } + + @Override + public List queryIntentActivities(Intent intent, int flags) { + // TODO Auto-generated method stub + return orig.queryIntentActivities(intent, flags); + } + + @Override + public List queryIntentActivityOptions(ComponentName caller, + Intent[] specifics, Intent intent, int flags) { + // TODO Auto-generated method stub + return orig + .queryIntentActivityOptions(caller, specifics, intent, flags); + } + + @Override + public List queryBroadcastReceivers(Intent intent, int flags) { + // TODO Auto-generated method stub + return orig.queryBroadcastReceivers(intent, flags); + } + + @Override + public ResolveInfo resolveService(Intent intent, int flags) { + // TODO Auto-generated method stub + return orig.resolveService(intent, flags); + } + + @Override + public List queryIntentServices(Intent intent, int flags) { + // TODO Auto-generated method stub + return orig.queryIntentServices(intent, flags); + } + + @Override + public ProviderInfo resolveContentProvider(String name, int flags) { + // TODO Auto-generated method stub + return orig.resolveContentProvider(name, flags); + } + + @Override + public List queryContentProviders(String processName, + int uid, int flags) { + // TODO Auto-generated method stub + return orig.queryContentProviders(processName, uid, flags); + } + + @Override + public InstrumentationInfo getInstrumentationInfo(ComponentName className, + int flags) throws NameNotFoundException { + // TODO Auto-generated method stub + return orig.getInstrumentationInfo(className, flags); + } + + @Override + public List queryInstrumentation(String targetPackage, + int flags) { + // TODO Auto-generated method stub + return orig.queryInstrumentation(targetPackage, flags); + } + + @Override + public Drawable getDrawable(String packageName, int resid, + ApplicationInfo appInfo) { + // TODO getDrawable + return orig.getDrawable(packageName, resid, appInfo); + } + + @Override + public Drawable getActivityIcon(ComponentName activityName) + throws NameNotFoundException { + // TODO getActivityIcon + PlugInfo plug = PluginManager.getInstance().getPluginByPackageName( + activityName.getPackageName()); + if (plug != null) { + ActivityInfo actInfo = plug.findActivityByClassName(activityName + .getClassName()); + int icon = actInfo.icon; + if (icon != 0) { + return plug.getResources().getDrawable(icon); + } + } + return orig.getActivityIcon(activityName); + } + + @Override + public Drawable getActivityIcon(Intent intent) throws NameNotFoundException { + // TODO getActivityIcon(Intent intent) + return orig.getActivityIcon(intent); + } + + @Override + public Drawable getDefaultActivityIcon() { + // TODO getDefaultActivityIcon + return orig.getDefaultActivityIcon(); + } + + @Override + public Drawable getApplicationIcon(ApplicationInfo info) { + // TODO getApplicationIcon + return orig.getApplicationIcon(info); + } + + @Override + public Drawable getApplicationIcon(String packageName) + throws NameNotFoundException { + // TODO getApplicationIcon + PlugInfo plug = PluginManager.getInstance().getPluginByPackageName( + packageName); + if (plug != null) { + int appIcon = plug.getPackageInfo().applicationInfo.icon; + if (appIcon != 0) { + return plug.getResources().getDrawable(appIcon); + } else { + return null; + } + } + return orig.getApplicationIcon(packageName); + } + + @Override + public Drawable getActivityLogo(ComponentName activityName) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getActivityLogo(android.content.Intent) + */ + @Override + public Drawable getActivityLogo(Intent intent) throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getApplicationLogo(android.content. + * pm.ApplicationInfo) + */ + @Override + public Drawable getApplicationLogo(ApplicationInfo info) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getApplicationLogo(java.lang.String) + */ + @Override + public Drawable getApplicationLogo(String packageName) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see android.content.pm.PackageManager#getText(java.lang.String, int, + * android.content.pm.ApplicationInfo) + */ + @Override + public CharSequence getText(String packageName, int resid, + ApplicationInfo appInfo) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see android.content.pm.PackageManager#getXml(java.lang.String, int, + * android.content.pm.ApplicationInfo) + */ + @Override + public XmlResourceParser getXml(String packageName, int resid, + ApplicationInfo appInfo) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getApplicationLabel(android.content + * .pm.ApplicationInfo) + */ + @Override + public CharSequence getApplicationLabel(ApplicationInfo info) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getResourcesForActivity(android.content + * .ComponentName) + */ + @Override + public Resources getResourcesForActivity(ComponentName activityName) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getResourcesForApplication(android. + * content.pm.ApplicationInfo) + */ + @Override + public Resources getResourcesForApplication(ApplicationInfo app) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getResourcesForApplication(java.lang + * .String) + */ + @Override + public Resources getResourcesForApplication(String appPackageName) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getInstallerPackageName(java.lang.String + * ) + */ + @Override + public String getInstallerPackageName(String packageName) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#addPackageToPreferred(java.lang.String) + */ + @Override + public void addPackageToPreferred(String packageName) { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#removePackageFromPreferred(java.lang + * .String) + */ + @Override + public void removePackageFromPreferred(String packageName) { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see android.content.pm.PackageManager#getPreferredPackages(int) + */ + @Override + public List getPreferredPackages(int flags) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#addPreferredActivity(android.content + * .IntentFilter, int, android.content.ComponentName[], + * android.content.ComponentName) + */ + @Override + public void addPreferredActivity(IntentFilter filter, int match, + ComponentName[] set, ComponentName activity) { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#clearPackagePreferredActivities(java + * .lang.String) + */ + @Override + public void clearPackagePreferredActivities(String packageName) { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getPreferredActivities(java.util.List, + * java.util.List, java.lang.String) + */ + @Override + public int getPreferredActivities(List outFilters, + List outActivities, String packageName) { + // TODO Auto-generated method stub + return 0; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#setComponentEnabledSetting(android. + * content.ComponentName, int, int) + */ + @Override + public void setComponentEnabledSetting(ComponentName componentName, + int newState, int flags) { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getComponentEnabledSetting(android. + * content.ComponentName) + */ + @Override + public int getComponentEnabledSetting(ComponentName componentName) { + // TODO Auto-generated method stub + return 0; + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#setApplicationEnabledSetting(java.lang + * .String, int, int) + */ + @Override + public void setApplicationEnabledSetting(String packageName, int newState, + int flags) { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see + * android.content.pm.PackageManager#getApplicationEnabledSetting(java.lang + * .String) + */ + @Override + public int getApplicationEnabledSetting(String packageName) { + // TODO Auto-generated method stub + return 0; + } + + /* + * (non-Javadoc) + * + * @see android.content.pm.PackageManager#isSafeMode() + */ + @Override + public boolean isSafeMode() { + // TODO Auto-generated method stub + return false; + } + + @Override + public Intent getLeanbackLaunchIntentForPackage(String packageName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getPackagesHoldingPermissions( + String[] permissions, int flags) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List queryIntentContentProviders(Intent intent, + int flags) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Drawable getActivityBanner(ComponentName activityName) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Drawable getActivityBanner(Intent intent) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Drawable getApplicationBanner(ApplicationInfo info) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Drawable getApplicationBanner(String packageName) + throws NameNotFoundException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Drawable getUserBadgedDrawableForDensity(Drawable drawable, + UserHandle user, Rect badgeLocation, int badgeDensity) { + // TODO Auto-generated method stub + return null; + } + + @Override + public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void verifyPendingInstall(int id, int verificationCode) { + // TODO Auto-generated method stub + + } + + @Override + public void extendVerificationTimeout(int id, + int verificationCodeAtTimeout, long millisecondsToDelay) { + // TODO Auto-generated method stub + + } + + @Override + public void setInstallerPackageName(String targetPackage, + String installerPackageName) { + // TODO Auto-generated method stub + + } + + @Override + public PackageInstaller getPackageInstaller() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/ReflectionUtils.java b/PlugLoadMgr/src/androidx/pluginmgr/ReflectionUtils.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/ReflectionUtils.java rename to PlugLoadMgr/src/androidx/pluginmgr/ReflectionUtils.java diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/XmlManifestReader.java b/PlugLoadMgr/src/androidx/pluginmgr/XmlManifestReader.java similarity index 100% rename from android-pluginmgr/src/main/java/androidx/pluginmgr/XmlManifestReader.java rename to PlugLoadMgr/src/androidx/pluginmgr/XmlManifestReader.java diff --git a/android-pluginmgr/.classpath b/android-pluginmgr/.classpath deleted file mode 100644 index 4f18b0d..0000000 --- a/android-pluginmgr/.classpath +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/android-pluginmgr/.gitignore b/android-pluginmgr/.gitignore deleted file mode 100644 index 7f5128b..0000000 --- a/android-pluginmgr/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/* -/.settings/ diff --git a/android-pluginmgr/.settings/org.eclipse.core.resources.prefs b/android-pluginmgr/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 1f887b6..0000000 --- a/android-pluginmgr/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 diff --git a/android-pluginmgr/.settings/org.eclipse.m2e.core.prefs b/android-pluginmgr/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index 14b697b..0000000 --- a/android-pluginmgr/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/android-pluginmgr/TODO b/android-pluginmgr/TODO deleted file mode 100644 index ce74eb2..0000000 --- a/android-pluginmgr/TODO +++ /dev/null @@ -1,6 +0,0 @@ -1 PackageManager , meta-data, provider -2 inner & outer ClassLoader -3 load class with extra parameter such as pluginId, think java.lang.String in android -4 framework with android.support -5 android ui thread init plug application -6 service support diff --git a/android-pluginmgr/pom.xml b/android-pluginmgr/pom.xml deleted file mode 100644 index 5ddb651..0000000 --- a/android-pluginmgr/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - 4.0.0 - com.android - pluginmgr - 0.1.4 - androidx.pluginmgr - dynamic load uninstalled apk - - - com.google.dexmaker - dexmaker - 1.0 - - - com.google.android - android - 2.3.3 - - - junit - junit - 4.11 - - - - - - - - maven-compiler-plugin - 3.1 - - - default-testCompile - test-compile - - testCompile - - - src/test/java - 1.6 - 1.6 - UTF-8 - - - - default-compile - compile - - compile - - - src/test/java - 1.6 - 1.6 - UTF-8 - - - - - src/test/java - 1.6 - 1.6 - UTF-8 - - - - - - - - \ No newline at end of file diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PlugInfo.java b/android-pluginmgr/src/main/java/androidx/pluginmgr/PlugInfo.java deleted file mode 100644 index d69cf68..0000000 --- a/android-pluginmgr/src/main/java/androidx/pluginmgr/PlugInfo.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright (C) 2015 HouKx - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package androidx.pluginmgr; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import android.app.Application; -import android.content.pm.ActivityInfo; -import android.content.pm.PackageInfo; -import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; -import android.content.res.AssetManager; -import android.content.res.Resources; - -/** - * 插件Bean - * - * @author HouKangxi - * - */ -public class PlugInfo { - - // - // ================== FLELDS ================== - private String id; - private String filePath; - private PackageInfo packageInfo; - private Map activities; - private ResolveInfo mainActivity; - private List services; - private List receivers; - private List providers; - // - private transient PluginClassLoader classLoader; - private transient Application application; - private transient AssetManager assetManager; - private transient Resources resources; - PluginContextWrapper appWrapper; - // - // private transient volatile String currentActivityClass; - - public String getPackageName() { - return packageInfo.packageName; - } - - // ================== FLAGS STARD ================== - /** - * 按下back键时是否 finish Activity - */ - private static final int FLAG_FinishActivityOnbackPressed = 1; - /** - * 是否调用父类的onBackPressed()方法 - */ - private static final int FLAG_INVOKE_SUPER_ONBACKPRESSED = 2; - - // ================== FLAGS END ================== - /** - * 按Back键时是否销毁Activity - */ - public boolean isFinishActivityOnbackPressed(ActivityInfo act) { - if (act == null) { - return false; - } - int flags = getFlags(act); - return containsFlag(flags, FLAG_FinishActivityOnbackPressed); - } - - public boolean isInvokeSuperOnbackPressed(ActivityInfo act) { - if (act == null) { - return true; - } - int flags = getFlags(act); - if (flags == 0) { - return true;//默认true - } - return containsFlag(flags, FLAG_INVOKE_SUPER_ONBACKPRESSED); - } - - public void setInvokeSuperOnbackPressed(ActivityInfo act, - boolean invokeSuperOnbackPressed) { - if (act == null) { - return; - } - if (invokeSuperOnbackPressed) { - setFlag(act, FLAG_INVOKE_SUPER_ONBACKPRESSED); - } else { - unsetFlag(act, FLAG_INVOKE_SUPER_ONBACKPRESSED); - } - } - - public void setFinishActivityOnbackPressed(ActivityInfo act, - boolean finishOnbackPressed) { - if (act == null) { - return; - } - if (finishOnbackPressed) { - setFlag(act, FLAG_FinishActivityOnbackPressed); - } else { - unsetFlag(act, FLAG_FinishActivityOnbackPressed); - } - } - - ActivityInfo findActivityByClassNameFromPkg(String actName) { - if (packageInfo.activities == null) { - return null; - } - for (ActivityInfo act : packageInfo.activities) { - if(act.name.equals(actName)){ - return act; - } - } - return null; - } - public ActivityInfo findActivityByClassName(String actName) { - if (packageInfo.activities == null) { - return null; - } - ResolveInfo act = activities.get(actName); - if (act == null) { - return null; - } - return act.activityInfo; - } - - public ActivityInfo findActivityByAction(String action) { - if (activities == null || activities.isEmpty()) { - return null; - } - for (ResolveInfo act : activities.values()) { - if (act.filter != null && act.filter.hasAction(action)) { - return act.activityInfo; - } - } - return null; - } - - public ActivityInfo findReceiverByClassName(String className) { - if (packageInfo.receivers == null) { - return null; - } - for (ActivityInfo receiver : packageInfo.receivers) { - if (receiver.name.equals(className)) { - return receiver; - } - } - return null; - - } - public ServiceInfo findServiceByClassName(String className) { - if (packageInfo.services == null) { - return null; - } - for (ServiceInfo service : packageInfo.services) { - if (service.name.equals(className)) { - return service; - } - } - return null; - - } - public ServiceInfo findServiceByAction(String action) { - if (services == null || services.isEmpty()) { - return null; - } - for (ResolveInfo ser : services) { - if (ser.filter != null && ser.filter.hasAction(action)) { - return ser.serviceInfo; - } - } - return null; - } - public void addActivity(ResolveInfo activity) { - if (activities == null) { - activities = new HashMap(20); - } - activities.put(activity.activityInfo.name,activity); - if (mainActivity == null && activity.filter != null - && activity.filter.hasAction("android.intent.action.MAIN") - && activity.filter.hasCategory("android.intent.category.LAUNCHER") - ) { - mainActivity = activity; - } - } - - public void addReceiver(ResolveInfo receiver) { - if (receivers == null) { - receivers = new ArrayList(); - } - receivers.add(receiver); - } - - public void addService(ResolveInfo service) { - if (services == null) { - services = new ArrayList(); - } - services.add(service); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFilePath() { - return filePath; - } - - public void setFilePath(String filePath) { - this.filePath = filePath; - } - - public PackageInfo getPackageInfo() { - return packageInfo; - } - - public void setPackageInfo(PackageInfo packageInfo) { - this.packageInfo = packageInfo; - activities = new HashMap(packageInfo.activities.length); - } - - public PluginClassLoader getClassLoader() { - return classLoader; - } - - public void setClassLoader(PluginClassLoader classLoader) { - this.classLoader = classLoader; - } - - public Application getApplication() { - return application; - } - - public void setApplication(Application application) { - this.application = application; - } - - public AssetManager getAssetManager() { - return assetManager; - } - - public void setAssetManager(AssetManager assetManager) { - this.assetManager = assetManager; - } - - public Resources getResources() { - return resources; - } - - public void setResources(Resources resources) { - this.resources = resources; - } - - // public String getCurrentActivityClass() { - // return currentActivityClass; - // } - // - // public void setCurrentActivityClass(String currentActivityClass) { - // this.currentActivityClass = currentActivityClass; - // } - - public Collection getActivities() { - if (activities == null) { - return null; - } - return activities.values(); - } - - public List getServices() { - return services; - } - - public void setServices(List services) { - this.services = services; - } - - public List getProviders() { - return providers; - } - - public void setProviders(List providers) { - this.providers = providers; - } - - public ResolveInfo getMainActivity() { - return mainActivity; - } - - public List getReceivers() { - return receivers; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - PlugInfo other = (PlugInfo) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } - - @Override - public String toString() { - return super.toString() + "[ id=" + id + ", pkg=" + getPackageName() - + " ]"; - } - - private static synchronized int getFlags(ActivityInfo act) { - return act.logo; - } - - private static synchronized void setFlag(ActivityInfo act, int flag) { - act.logo |= flag; - } - - private static synchronized void unsetFlag(ActivityInfo act, int flag) { - act.logo &= ~flag; - } - - private static boolean containsFlag(int vFlags, int flag) { - return (vFlags & flag) == flag; - } -} diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginManager.java b/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginManager.java deleted file mode 100644 index bf6a3c8..0000000 --- a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginManager.java +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Copyright (C) 2015 HouKx - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package androidx.pluginmgr; - -import java.io.File; -import java.io.FileFilter; -import java.io.FileNotFoundException; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import android.app.Activity; -import android.app.Application; -import android.app.Service; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.res.AssetManager; -import android.content.res.Resources; -import android.util.Log; - -/** - * The Plug-in Manager - * - * @author HouKangxi - */ -public class PluginManager implements FileFilter { - private static final String tag = "plugmgr"; - - private static final PluginManager instance = new PluginManager(); - - private final Map pluginIdToInfoMap = new ConcurrentHashMap(); - private final Map pluginPkgToInfoMap = new ConcurrentHashMap(); - private Context context; - private String dexOutputPath; - private volatile boolean hasInit = false; - private File dexInternalStoragePath; - private FrameworkClassLoader frameworkClassLoader; - private PluginActivityLifeCycleCallback pluginActivityLifeCycleCallback; - private volatile Activity actFrom; - - private PluginManager() { - } - - - public static PluginManager getInstance(Context context) { - if (instance.hasInit || context == null) { - if (instance.actFrom == null && context instanceof Activity) { - instance.actFrom = (Activity) context; - } - return instance; - } - Context ctx = context; - if (context instanceof Activity) { - instance.actFrom = (Activity) context; - ctx = ((Activity) context).getApplication(); - } else if (context instanceof Service) { - ctx = ((Service) context).getApplication(); - } else if (context instanceof Application) { - ctx = (Application) context; - } else { - ctx = context.getApplicationContext(); - } - synchronized (PluginManager.class) { - instance.init(ctx); - } - return instance; - } - - static PluginManager getInstance() { - return instance; - } - - public boolean startMainActivity(Context context, String pkgOrId) { - Log.d(tag, "startMainActivity by:" + pkgOrId); - PlugInfo plug = preparePlugForStartActivity(context, pkgOrId); - if (frameworkClassLoader == null) { - Log.e(tag, "startMainActivity: frameworkClassLoader == null!"); - return false; - } - if (plug.getMainActivity() == null) { - Log.e(tag, "startMainActivity: plug.getMainActivity() == null!"); - return false; - } - if (plug.getMainActivity().activityInfo == null) { - Log.e(tag, - "startMainActivity: plug.getMainActivity().activityInfo == null!"); - return false; - } - String className = frameworkClassLoader.newActivityClassName( - plug.getId(), plug.getMainActivity().activityInfo.name); - context.startActivity(new Intent().setComponent(new ComponentName( - context, className))); - return true; - } - - public void startActivity(Context context, Intent intent) { - performStartActivity(context, intent); - context.startActivity(intent); - } - - public void startActivityForResult(Activity activity, Intent intent, - int requestCode) { - performStartActivity(context, intent); - activity.startActivityForResult(intent, requestCode); - } - - private PlugInfo preparePlugForStartActivity(Context context, - String plugIdOrPkg) { - PlugInfo plug = null; - plug = getPluginByPackageName(plugIdOrPkg); - if (plug == null) { - plug = getPluginById(plugIdOrPkg); - } - if (plug == null) { - throw new IllegalArgumentException("plug not found by:" - + plugIdOrPkg); - } - return plug; - } - - private void performStartActivity(Context context, Intent intent) { - checkInit(); - - String plugIdOrPkg; - String actName; - ComponentName origComp = intent.getComponent(); - if (origComp != null) { - plugIdOrPkg = origComp.getPackageName(); - actName = origComp.getClassName(); - } else { - throw new IllegalArgumentException( - "plug intent must set the ComponentName!"); - } - PlugInfo plug = preparePlugForStartActivity(context, plugIdOrPkg); - String className = frameworkClassLoader.newActivityClassName( - plug.getId(), actName); - Log.i(tag, "performStartActivity: " + actName); - ComponentName comp = new ComponentName(context, className); - intent.setAction(null); - intent.setComponent(comp); - } - - - private void init(Context ctx) { - Log.i(tag, "init()..."); - context = ctx; - File optimizedDexPath = ctx.getDir("plugsout", Context.MODE_PRIVATE); - if (!optimizedDexPath.exists()) { - optimizedDexPath.mkdirs(); - } - dexOutputPath = optimizedDexPath.getAbsolutePath(); - dexInternalStoragePath = context - .getDir("plugins", Context.MODE_PRIVATE); - dexInternalStoragePath.mkdirs(); - // change ClassLoader - try { - Object mPackageInfo = ReflectionUtils.getFieldValue(ctx, - "mBase.mPackageInfo", true); - frameworkClassLoader = new FrameworkClassLoader( - ctx.getClassLoader()); - // set Application's classLoader to FrameworkClassLoader - ReflectionUtils.setFieldValue(mPackageInfo, "mClassLoader", - frameworkClassLoader, true); - } catch (Exception e) { - e.printStackTrace(); - } - hasInit = true; - } - - private void checkInit() { - if (!hasInit) { - throw new IllegalStateException("PluginManager has not init!"); - } - } - - public PlugInfo getPluginById(String pluginId) { - if (pluginId == null) { - return null; - } - return pluginIdToInfoMap.get(pluginId); - } - - public PlugInfo getPluginByPackageName(String packageName) { - return pluginPkgToInfoMap.get(packageName); - } - - public Collection getPlugins() { - return pluginIdToInfoMap.values(); - } - - public void uninstallPluginById(String pluginId) { - uninstallPlugin(pluginId, true); - } - - public void uninstallPluginByPkg(String pkg) { - uninstallPlugin(pkg, false); - } - - private void uninstallPlugin(String k, boolean isId) { - checkInit(); - PlugInfo pl = isId ? removePlugById(k) : removePlugByPkg(k); - if (pl == null) { - return; - } - if (context instanceof Application) { - if (android.os.Build.VERSION.SDK_INT >= 14) { - try { - Application.class - .getMethod( - "unregisterComponentCallbacks", - Class.forName("android.content.ComponentCallbacks")) - .invoke(context, pl.getApplication()); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - private PlugInfo removePlugById(String pluginId) { - PlugInfo pl = null; - synchronized (this) { - pl = pluginIdToInfoMap.remove(pluginId); - if (pl == null) { - return null; - } - pluginPkgToInfoMap.remove(pl.getPackageName()); - } - return pl; - } - - private PlugInfo removePlugByPkg(String pkg) { - PlugInfo pl = null; - synchronized (this) { - pl = pluginPkgToInfoMap.remove(pkg); - if (pl == null) { - return null; - } - pluginIdToInfoMap.remove(pl.getId()); - } - return pl; - } - - /** - * 加载指定插件或指定目录下的所有插件 - *

- * 都使用文件名作为Id - * - * @param pluginSrcDirFile - * - apk或apk目录 - * @return 插件集合 - * @throws Exception - */ - public Collection loadPlugin(final File pluginSrcDirFile) - throws Exception { - checkInit(); - if (pluginSrcDirFile == null || !pluginSrcDirFile.exists()) { - Log.e(tag, "invalidate plugin file or Directory :" - + pluginSrcDirFile); - return null; - } - if (pluginSrcDirFile.isFile()) { - // 如果是文件则尝试加载单个插件,暂不检查文件类型,除apk外,以后可能支持加载其他类型文件,如jar - PlugInfo one = loadPluginWithId(pluginSrcDirFile, null, null); - return Collections.singletonList(one); - } - // clear all first - synchronized (this) { - pluginPkgToInfoMap.clear(); - pluginIdToInfoMap.clear(); - } - File[] pluginApks = pluginSrcDirFile.listFiles(this); - if (pluginApks == null || pluginApks.length < 1) { - throw new FileNotFoundException("could not find plugins in:" - + pluginSrcDirFile); - } - for (File pluginApk : pluginApks) { - PlugInfo plugInfo = buildPlugInfo(pluginApk, null, null); - if (plugInfo != null) { - savePluginToMap(plugInfo); - } - } - return pluginIdToInfoMap.values(); - } - - private synchronized void savePluginToMap(PlugInfo plugInfo) { - pluginPkgToInfoMap.put(plugInfo.getPackageName(), plugInfo); - pluginIdToInfoMap.put(plugInfo.getId(), plugInfo); - } - - // /** - // * 单独加载一个apk
- // * 使用文件名作为插件id
- // * 目标文件也是与源文件同名 - // * - // * @param pluginApk - // * @return - // * @throws Exception - // */ - // public PlugInfo loadPlugin(File pluginApk) throws Exception { - // return loadPluginWithId(pluginApk, null, null); - // } - - /** - * 单独加载一个apk - * - * @param pluginApk - * @param pluginId - * - 如果参数为null,则使用文件名作为插件id - * @return - * @throws Exception - */ - public PlugInfo loadPluginWithId(File pluginApk, String pluginId) - throws Exception { - return loadPluginWithId(pluginApk, pluginId, null); - } - - public PlugInfo loadPluginWithId(File pluginApk, String pluginId, - String targetFileName) throws Exception { - checkInit(); - PlugInfo plugInfo = buildPlugInfo(pluginApk, pluginId, targetFileName); - if (plugInfo != null) { - savePluginToMap(plugInfo); - } - return plugInfo; - } - - private PlugInfo buildPlugInfo(File pluginApk, String pluginId, - String targetFileName) throws Exception { - PlugInfo info = new PlugInfo(); - info.setId(pluginId == null ? pluginApk.getName() : pluginId); - - File privateFile = new File(dexInternalStoragePath, - targetFileName == null ? pluginApk.getName() : targetFileName); - - info.setFilePath(privateFile.getAbsolutePath()); - - if (!pluginApk.getAbsolutePath().equals(privateFile.getAbsolutePath())) { - copyApkToPrivatePath(pluginApk, privateFile); - } - String dexPath = privateFile.getAbsolutePath(); - PluginManifestUtil.setManifestInfo(context, dexPath, info); - - PluginClassLoader loader = new PluginClassLoader(dexPath, - dexOutputPath, frameworkClassLoader, info); - info.setClassLoader(loader); - - try { - AssetManager am = (AssetManager) AssetManager.class.newInstance(); - am.getClass().getMethod("addAssetPath", String.class) - .invoke(am, dexPath); - info.setAssetManager(am); - Resources ctxres = context.getResources(); - Resources res = new Resources(am, ctxres.getDisplayMetrics(), - ctxres.getConfiguration()); - info.setResources(res); - } catch (Exception e) { - e.printStackTrace(); - } - if (actFrom != null) { - initPluginApplication(info, actFrom, true); - } - // createPluginActivityProxyDexes(info); - Log.i(tag, "buildPlugInfo: " + info); - return info; - } - - // private void createPluginActivityProxyDexes(PlugInfo plugin) { - // { - // ActInfo act = plugin.getApplicationInfo().getMainActivity(); - // if (act != null) { - // ActivityOverider.createProxyDex(plugin, act.name, false); - // } - // } - // if (plugin.getApplicationInfo().getOtherActivities() != null) { - // for (ActInfo act : plugin.getApplicationInfo().getOtherActivities()) - // { - // ActivityOverider.createProxyDex(plugin, act.name, false); - // } - // } - // } - void initPluginApplication(final PlugInfo info, Activity actFrom) - throws Exception { - initPluginApplication(info, actFrom, false); - } - - private void initPluginApplication(final PlugInfo plugin, Activity actFrom, boolean onLoad) throws Exception { - if (!onLoad && plugin.getApplication() != null) { - return; - } - final String className = plugin.getPackageInfo().applicationInfo.name; - if (className == null) { - if (onLoad) { - return; - } - Application application = new Application(); - setApplicationBase(plugin, application); - return; - } - Log.d(tag, plugin.getId() + ", ApplicationClassName = " + className); - - Runnable setApplicationTask = new Runnable() { - public void run() { - ClassLoader loader = plugin.getClassLoader(); - try { - Class applicationClass = loader.loadClass(className); - Application application = (Application) applicationClass - .newInstance(); - setApplicationBase(plugin, application); - // invoke plugin application's onCreate() - application.onCreate(); - } catch (Throwable e) { - Log.e(tag, Log.getStackTraceString(e)); - } - } - }; - // create Application instance for plugin - if (actFrom == null) { - if(onLoad) - return; - setApplicationTask.run(); - }else{ - actFrom.runOnUiThread(setApplicationTask); - } - } - - private void setApplicationBase(PlugInfo plugin, Application application) - throws Exception { - - synchronized (plugin) { - if (plugin.getApplication() != null) { - // set plugin's Application only once - return; - } - plugin.setApplication(application); - // - PluginContextWrapper ctxWrapper = new PluginContextWrapper(context, - plugin); - plugin.appWrapper = ctxWrapper; - // attach - Method attachMethod = android.app.Application.class.getDeclaredMethod( - "attach", Context.class); - attachMethod.setAccessible(true); - attachMethod.invoke(application, ctxWrapper); - if (context instanceof Application) { - if (android.os.Build.VERSION.SDK_INT >= 14) { - Application.class.getMethod("registerComponentCallbacks", - Class.forName("android.content.ComponentCallbacks")) - .invoke(context, application); - } - } - - } - } - - private void copyApkToPrivatePath(File pluginApk, File f) { - // if (f.exists() && pluginApk.length() == f.length()) { - // // 这里只是简单的判断如果两个文件长度相同则不拷贝,严格的做应该比较签名如 md5\sha-1 - // return; - // } - FileUtil.copyFile(pluginApk, f); - } - - File getDexInternalStoragePath() { - return dexInternalStoragePath; - } - - Context getContext() { - return context; - } - - public PluginActivityLifeCycleCallback getPluginActivityLifeCycleCallback() { - return pluginActivityLifeCycleCallback; - } - - public void setPluginActivityLifeCycleCallback( - PluginActivityLifeCycleCallback pluginActivityLifeCycleCallback) { - this.pluginActivityLifeCycleCallback = pluginActivityLifeCycleCallback; - } - - FrameworkClassLoader getFrameworkClassLoader() { - return frameworkClassLoader; - } - - @Override - public boolean accept(File pathname) { - if (pathname.isDirectory()) { - return false; - } - String fname = pathname.getName(); - return fname.endsWith(".apk"); - } - -} diff --git a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginPackageManager.java b/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginPackageManager.java deleted file mode 100644 index 6c49d59..0000000 --- a/android-pluginmgr/src/main/java/androidx/pluginmgr/PluginPackageManager.java +++ /dev/null @@ -1,688 +0,0 @@ -/* - * Copyright (C) 2015 HouKx - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package androidx.pluginmgr; - -import java.util.List; - -import android.content.ComponentName; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.ActivityInfo; -import android.content.pm.ApplicationInfo; -import android.content.pm.FeatureInfo; -import android.content.pm.InstrumentationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PermissionGroupInfo; -import android.content.pm.PermissionInfo; -import android.content.pm.ProviderInfo; -import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; -import android.content.res.Resources; -import android.content.res.XmlResourceParser; -import android.graphics.drawable.Drawable; - -/** - * Customer PackageManager - *

- * - * TODO unfinished, prepare use in {@link PluginContextWrapper#getPackageManager} - * - * @author HouKangxi - * - */ -public class PluginPackageManager extends PackageManager { - private PackageManager orig; - - public PluginPackageManager(PackageManager wrapper) { - this.orig = wrapper; - } - - @Override - public PackageInfo getPackageInfo(String packageName, int flags) - throws NameNotFoundException { - PlugInfo plugin = PluginManager.getInstance().getPluginByPackageName( - packageName); - if (plugin != null) { - return plugin.getPackageInfo(); - } - return orig.getPackageInfo(packageName, flags); - } - - @Override - public String[] currentToCanonicalPackageNames(String[] names) { - return orig.currentToCanonicalPackageNames(names); - } - - @Override - public String[] canonicalToCurrentPackageNames(String[] names) { - return orig.canonicalToCurrentPackageNames(names); - } - - @Override - public Intent getLaunchIntentForPackage(String packageName) { - // PlugInfo plugin = - // PluginManager.getInstance().getPluginByPackageName(packageName); - // if (plugin != null) { - // //TODO - // } - return orig.getLaunchIntentForPackage(packageName); - } - - @Override - public int[] getPackageGids(String packageName) - throws NameNotFoundException { - PlugInfo plugin = PluginManager.getInstance().getPluginByPackageName( - packageName); - if (plugin != null) { - return plugin.getPackageInfo().gids; - } - return orig.getPackageGids(packageName); - } - - @Override - public PermissionInfo getPermissionInfo(String name, int flags) - throws NameNotFoundException { - // TODO - return orig.getPermissionInfo(name, flags); - } - - @Override - public List queryPermissionsByGroup(String group, int flags) - throws NameNotFoundException { - // TODO - return orig.queryPermissionsByGroup(group, flags); - } - - @Override - public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) - throws NameNotFoundException { - // TODO - return orig.getPermissionGroupInfo(name, flags); - } - - @Override - public List getAllPermissionGroups(int flags) { - // TODO - return orig.getAllPermissionGroups(flags); - } - - @Override - public ApplicationInfo getApplicationInfo(String packageName, int flags) - throws NameNotFoundException { - PlugInfo plugin = PluginManager.getInstance().getPluginByPackageName( - packageName); - if (plugin != null) { - return plugin.getPackageInfo().applicationInfo; - } - return orig.getApplicationInfo(packageName, flags); - } - - @Override - public ActivityInfo getActivityInfo(ComponentName component, int flags) - throws NameNotFoundException { - String packageName = component.getPackageName(); - if (packageName != null) { - PlugInfo plugin = PluginManager.getInstance() - .getPluginByPackageName(packageName); - if (plugin != null) { - String actClassName = component.getClassName(); - if (actClassName != null) { - return plugin.findActivityByClassName(actClassName); - } - } - } - return orig.getActivityInfo(component, flags); - } - - @Override - public ActivityInfo getReceiverInfo(ComponentName component, int flags) - throws NameNotFoundException { - String packageName = component.getPackageName(); - if (packageName != null) { - PlugInfo plugin = PluginManager.getInstance() - .getPluginByPackageName(packageName); - if (plugin != null) { - String className = component.getClassName(); - if (className != null) { - return plugin.findReceiverByClassName(className); - } - } - } - return orig.getReceiverInfo(component, flags); - } - - @Override - public ServiceInfo getServiceInfo(ComponentName component, int flags) - throws NameNotFoundException { - String packageName = component.getPackageName(); - if (packageName != null) { - PlugInfo plugin = PluginManager.getInstance() - .getPluginByPackageName(packageName); - if (plugin != null) { - String className = component.getClassName(); - if (className != null) { - return plugin.findServiceByClassName(className); - } - } - } - return orig.getServiceInfo(component, flags); - } - - @Override - public ProviderInfo getProviderInfo(ComponentName component, int flags) - throws NameNotFoundException { - // TODO getProviderInfo - return orig.getProviderInfo(component, flags); - } - - @Override - public List getInstalledPackages(int flags) { - return orig.getInstalledPackages(flags); - } - - @Override - public int checkPermission(String permName, String pkgName) { - // TODO checkPermission - return orig.checkPermission(permName, pkgName); - } - - @Override - public boolean addPermission(PermissionInfo info) { - // TODO addPermission - return orig.addPermission(info); - } - - @Override - public boolean addPermissionAsync(PermissionInfo info) { - // TODO addPermissionAsync - return orig.addPermission(info); - } - - @Override - public void removePermission(String name) { - // TODO removePermission - orig.removePermission(name); - } - - @Override - public int checkSignatures(String pkg1, String pkg2) { - // TODO checkSignatures - return orig.checkSignatures(pkg1, pkg2); - } - - @Override - public int checkSignatures(int uid1, int uid2) { - // TODO checkSignatures - return orig.checkSignatures(uid1, uid2); - } - - @Override - public String[] getPackagesForUid(int uid) { - // TODO getPackagesForUid - return orig.getPackagesForUid(uid); - } - - @Override - public String getNameForUid(int uid) { - // TODO getNameForUid - return orig.getNameForUid(uid); - } - - @Override - public List getInstalledApplications(int flags) { - return orig.getInstalledApplications(flags); - } - - @Override - public String[] getSystemSharedLibraryNames() { - // TODO getSystemSharedLibraryNames - return orig.getSystemSharedLibraryNames(); - } - - @Override - public FeatureInfo[] getSystemAvailableFeatures() { - // TODO getSystemAvailableFeatures - return orig.getSystemAvailableFeatures(); - } - - @Override - public boolean hasSystemFeature(String name) { - // TODO hasSystemFeature - return orig.hasSystemFeature(name); - } - - @Override - public ResolveInfo resolveActivity(Intent intent, int flags) { - // TODO resolveActivity - // ComponentName compname = intent.getComponent(); - // if(compname!=null){ - // String packageName = compname.getPackageName(); - // if(packageName!=null){ - // PlugInfo plug = - // PluginManager.getInstance().getPluginByPackageName(packageName); - // if (plug != null) { - // String className = compname.getClassName(); - // if(className!=null){ - // return plug.resolveActivity() - // } - // } - // } - // } - return orig.resolveActivity(intent, flags); - } - - @Override - public List queryIntentActivities(Intent intent, int flags) { - // TODO Auto-generated method stub - return orig.queryIntentActivities(intent, flags); - } - - @Override - public List queryIntentActivityOptions(ComponentName caller, - Intent[] specifics, Intent intent, int flags) { - // TODO Auto-generated method stub - return orig - .queryIntentActivityOptions(caller, specifics, intent, flags); - } - - @Override - public List queryBroadcastReceivers(Intent intent, int flags) { - // TODO Auto-generated method stub - return orig.queryBroadcastReceivers(intent, flags); - } - - @Override - public ResolveInfo resolveService(Intent intent, int flags) { - // TODO Auto-generated method stub - return orig.resolveService(intent, flags); - } - - @Override - public List queryIntentServices(Intent intent, int flags) { - // TODO Auto-generated method stub - return orig.queryIntentServices(intent, flags); - } - - @Override - public ProviderInfo resolveContentProvider(String name, int flags) { - // TODO Auto-generated method stub - return orig.resolveContentProvider(name, flags); - } - - @Override - public List queryContentProviders(String processName, - int uid, int flags) { - // TODO Auto-generated method stub - return orig.queryContentProviders(processName, uid, flags); - } - - @Override - public InstrumentationInfo getInstrumentationInfo(ComponentName className, - int flags) throws NameNotFoundException { - // TODO Auto-generated method stub - return orig.getInstrumentationInfo(className, flags); - } - - @Override - public List queryInstrumentation(String targetPackage, - int flags) { - // TODO Auto-generated method stub - return orig.queryInstrumentation(targetPackage, flags); - } - - @Override - public Drawable getDrawable(String packageName, int resid, - ApplicationInfo appInfo) { - // TODO getDrawable - return orig.getDrawable(packageName, resid, appInfo); - } - - @Override - public Drawable getActivityIcon(ComponentName activityName) - throws NameNotFoundException { - // TODO getActivityIcon - PlugInfo plug = PluginManager.getInstance().getPluginByPackageName( - activityName.getPackageName()); - if (plug != null) { - ActivityInfo actInfo = plug.findActivityByClassName(activityName - .getClassName()); - int icon = actInfo.icon; - if (icon != 0) { - return plug.getResources().getDrawable(icon); - } - } - return orig.getActivityIcon(activityName); - } - - @Override - public Drawable getActivityIcon(Intent intent) throws NameNotFoundException { - // TODO getActivityIcon(Intent intent) - return orig.getActivityIcon(intent); - } - - @Override - public Drawable getDefaultActivityIcon() { - // TODO getDefaultActivityIcon - return orig.getDefaultActivityIcon(); - } - - @Override - public Drawable getApplicationIcon(ApplicationInfo info) { - // TODO getApplicationIcon - return orig.getApplicationIcon(info); - } - - @Override - public Drawable getApplicationIcon(String packageName) - throws NameNotFoundException { - // TODO getApplicationIcon - PlugInfo plug = PluginManager.getInstance().getPluginByPackageName( - packageName); - if (plug != null) { - int appIcon = plug.getPackageInfo().applicationInfo.icon; - if (appIcon != 0) { - return plug.getResources().getDrawable(appIcon); - } else { - return null; - } - } - return orig.getApplicationIcon(packageName); - } - - @Override - public Drawable getActivityLogo(ComponentName activityName) - throws NameNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getActivityLogo(android.content.Intent) - */ - @Override - public Drawable getActivityLogo(Intent intent) throws NameNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getApplicationLogo(android.content. - * pm.ApplicationInfo) - */ - @Override - public Drawable getApplicationLogo(ApplicationInfo info) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getApplicationLogo(java.lang.String) - */ - @Override - public Drawable getApplicationLogo(String packageName) - throws NameNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see android.content.pm.PackageManager#getText(java.lang.String, int, - * android.content.pm.ApplicationInfo) - */ - @Override - public CharSequence getText(String packageName, int resid, - ApplicationInfo appInfo) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see android.content.pm.PackageManager#getXml(java.lang.String, int, - * android.content.pm.ApplicationInfo) - */ - @Override - public XmlResourceParser getXml(String packageName, int resid, - ApplicationInfo appInfo) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getApplicationLabel(android.content - * .pm.ApplicationInfo) - */ - @Override - public CharSequence getApplicationLabel(ApplicationInfo info) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getResourcesForActivity(android.content - * .ComponentName) - */ - @Override - public Resources getResourcesForActivity(ComponentName activityName) - throws NameNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getResourcesForApplication(android. - * content.pm.ApplicationInfo) - */ - @Override - public Resources getResourcesForApplication(ApplicationInfo app) - throws NameNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getResourcesForApplication(java.lang - * .String) - */ - @Override - public Resources getResourcesForApplication(String appPackageName) - throws NameNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getInstallerPackageName(java.lang.String - * ) - */ - @Override - public String getInstallerPackageName(String packageName) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#addPackageToPreferred(java.lang.String) - */ - @Override - public void addPackageToPreferred(String packageName) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#removePackageFromPreferred(java.lang - * .String) - */ - @Override - public void removePackageFromPreferred(String packageName) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see android.content.pm.PackageManager#getPreferredPackages(int) - */ - @Override - public List getPreferredPackages(int flags) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#addPreferredActivity(android.content - * .IntentFilter, int, android.content.ComponentName[], - * android.content.ComponentName) - */ - @Override - public void addPreferredActivity(IntentFilter filter, int match, - ComponentName[] set, ComponentName activity) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#clearPackagePreferredActivities(java - * .lang.String) - */ - @Override - public void clearPackagePreferredActivities(String packageName) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getPreferredActivities(java.util.List, - * java.util.List, java.lang.String) - */ - @Override - public int getPreferredActivities(List outFilters, - List outActivities, String packageName) { - // TODO Auto-generated method stub - return 0; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#setComponentEnabledSetting(android. - * content.ComponentName, int, int) - */ - @Override - public void setComponentEnabledSetting(ComponentName componentName, - int newState, int flags) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getComponentEnabledSetting(android. - * content.ComponentName) - */ - @Override - public int getComponentEnabledSetting(ComponentName componentName) { - // TODO Auto-generated method stub - return 0; - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#setApplicationEnabledSetting(java.lang - * .String, int, int) - */ - @Override - public void setApplicationEnabledSetting(String packageName, int newState, - int flags) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see - * android.content.pm.PackageManager#getApplicationEnabledSetting(java.lang - * .String) - */ - @Override - public int getApplicationEnabledSetting(String packageName) { - // TODO Auto-generated method stub - return 0; - } - - /* - * (non-Javadoc) - * - * @see android.content.pm.PackageManager#isSafeMode() - */ - @Override - public boolean isSafeMode() { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/android-pluginmgr/target/.gitignore b/android-pluginmgr/target/.gitignore deleted file mode 100644 index 840e7d3..0000000 --- a/android-pluginmgr/target/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/classes/