├── .gitignore
├── LICENSE
├── MainApp
├── .classpath
├── .project
├── AndroidManifest.xml
├── assets
│ ├── cocos2dx
│ │ └── libs
│ │ │ ├── armeabi-v7a
│ │ │ └── libcpp_empty_test.so
│ │ │ └── armeabi
│ │ │ └── libcpp_empty_test.so
│ └── simpledemo
│ │ └── libs
│ │ ├── armeabi-v7a
│ │ └── libhello-jni.so
│ │ └── armeabi
│ │ └── libhello-jni.so
├── ic_launcher-web.png
├── libs
│ └── android-support-v4.jar
├── pom.xml
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── activity_main.xml
│ │ └── plugin_item.xml
│ ├── values-w820dp
│ │ └── dimens.xml
│ └── values
│ │ ├── dimens.xml
│ │ └── strings.xml
└── src
│ └── com
│ └── example
│ └── mainapp
│ └── MainActivity.java
├── PluginApp
├── .classpath
├── .cproject
├── .project
├── AndroidManifest.xml
├── ic_launcher-web.png
├── jni
│ ├── Android.mk
│ ├── Application.mk
│ ├── com_example_pluginapp_TestNative.c
│ └── com_example_pluginapp_TestNative.h
├── pom.xml
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ ├── a.jpeg
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── activity_main.xml
│ │ ├── second_activity.xml
│ │ └── third_activity.xml
│ ├── values-w820dp
│ │ └── dimens.xml
│ └── values
│ │ ├── dimens.xml
│ │ └── strings.xml
└── src
│ └── com
│ └── example
│ └── pluginapp
│ ├── MainActivity.java
│ ├── MyApplication.java
│ ├── MyService.java
│ ├── MyStaticReceiver.java
│ ├── SecondActivity.java
│ ├── TestNative.java
│ └── ThirdActivity.java
├── README.md
└── koala
├── .classpath
├── .project
├── AndroidManifest.xml
├── android-support-v4.jar
├── frameworks-classes-full-debug.jar
├── ic_launcher-web.png
├── libcore-classes-full-debug.jar
├── pom.xml
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
└── values
│ ├── strings.xml
│ └── styles.xml
└── src
└── android
└── app
├── ActivityIntentResolver.java
├── ApkFile.java
├── CopyPluginListener.java
├── InstallPluginListener.java
├── IntentResolver.java
├── LocalBroadcastManager.java
├── Plugin.java
├── PluginActivity.java
├── PluginApplication.java
├── PluginBlankActivity.java
├── PluginBlankBroadcastReceiver.java
├── PluginBlankService.java
├── PluginContentResolver.java
├── PluginFragmentActivity.java
├── PluginInfo.java
├── PluginManager.java
├── PluginManagerImpl.java
├── PluginService.java
├── ProviderIntentResolver.java
├── ScanPluginListener.java
└── ServiceIntentResolver.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata/
2 | bin/
3 | gen/
4 | .settings/
5 | target/
6 |
7 |
8 | # Mobile Tools for Java (J2ME)
9 | .mtj.tmp/
10 |
11 | # Package Files #
12 | *.war
13 | *.ear
14 | *.log
15 | *.dex
16 | *.apk
17 | *.ap_
18 | *.class
19 | .DS_Store
20 |
21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22 | hs_err_pid*
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/MainApp/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MainApp/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainApp
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/MainApp/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/MainApp/assets/cocos2dx/libs/armeabi-v7a/libcpp_empty_test.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/assets/cocos2dx/libs/armeabi-v7a/libcpp_empty_test.so
--------------------------------------------------------------------------------
/MainApp/assets/cocos2dx/libs/armeabi/libcpp_empty_test.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/assets/cocos2dx/libs/armeabi/libcpp_empty_test.so
--------------------------------------------------------------------------------
/MainApp/assets/simpledemo/libs/armeabi-v7a/libhello-jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/assets/simpledemo/libs/armeabi-v7a/libhello-jni.so
--------------------------------------------------------------------------------
/MainApp/assets/simpledemo/libs/armeabi/libhello-jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/assets/simpledemo/libs/armeabi/libhello-jni.so
--------------------------------------------------------------------------------
/MainApp/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/ic_launcher-web.png
--------------------------------------------------------------------------------
/MainApp/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/MainApp/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example.mainapp
7 | MainApp
8 | 1.0.0
9 | apk
10 |
11 |
12 | UTF-8
13 |
14 |
15 | MainApp
16 |
17 |
18 |
19 | com.google.android
20 | android
21 | 4.1.1.4
22 | provided
23 |
24 |
25 |
26 | koala
27 | koala
28 | 1.0
29 |
30 |
31 |
32 |
35 | com.google.android
36 | support-v4
37 | r6
38 |
39 |
40 |
41 |
42 | src
43 | ${project.artifactId}
44 |
45 |
46 |
47 | com.jayway.maven.plugins.android.generation2
48 | android-maven-plugin
49 | 3.8.2
50 | true
51 |
52 |
53 |
54 |
55 |
56 | com.jayway.maven.plugins.android.generation2
57 | android-maven-plugin
58 |
59 |
60 |
61 | 17
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/MainApp/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/MainApp/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-10
15 | android.library.reference.1=../koala
16 |
--------------------------------------------------------------------------------
/MainApp/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainApp/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainApp/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainApp/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/MainApp/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainApp/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
9 |
--------------------------------------------------------------------------------
/MainApp/res/layout/plugin_item.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
13 |
18 |
--------------------------------------------------------------------------------
/MainApp/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/MainApp/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MainApp/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MainApp
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MainApp/src/com/example/mainapp/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.mainapp;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 |
6 | import android.app.Activity;
7 | import android.app.ApkFile;
8 | import android.app.CopyPluginListener;
9 | import android.app.InstallPluginListener;
10 | import android.app.PluginInfo;
11 | import android.app.PluginManager;
12 | import android.app.ProgressDialog;
13 | import android.app.ScanPluginListener;
14 | import android.content.Context;
15 | import android.os.Bundle;
16 | import android.view.LayoutInflater;
17 | import android.view.Menu;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.AdapterView;
21 | import android.widget.BaseAdapter;
22 | import android.widget.Button;
23 | import android.widget.ListView;
24 | import android.widget.TextView;
25 | import android.widget.AdapterView.OnItemClickListener;
26 |
27 | public class MainActivity extends Activity implements ScanPluginListener, OnItemClickListener, InstallPluginListener, CopyPluginListener{
28 |
29 | private ProgressDialog mDialog;
30 |
31 | private ListView mListView;
32 |
33 | private PluginsAdapter mAdapter;
34 |
35 | private ArrayList apks = new ArrayList();
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_main);
41 | mListView = (ListView) findViewById(R.id.list);
42 | mListView.setOnItemClickListener(this);
43 | mDialog = new ProgressDialog(this);
44 | mDialog.setMessage("scanning");
45 | File dir = getFilesDir();
46 | dir = new File(dir, "koala");
47 | PluginManager.getInstance().init(this, getDir("dexout", Context.MODE_PRIVATE).getAbsolutePath(),
48 | dir.getAbsolutePath());
49 |
50 | ApkFile apk = new ApkFile();
51 | apk.apkName = "CppEmptyTest.apk";
52 | apk.name = "cocos2dx";
53 | apk.nativeLibs.add("libcpp_empty_test.so");
54 | apk.version = 1.0f;
55 | apks.add(apk);
56 |
57 | apk = new ApkFile();
58 | apk.apkName = "PluginApp.apk";
59 | apk.name = "simpledemo";
60 | apk.nativeLibs.add("libhello-jni.so");
61 | apk.version = 1.0f;
62 | apks.add(apk);
63 | PluginManager.getInstance().copyApksFromAsset(apks, getAssets(), this);
64 | }
65 |
66 | @Override
67 | public void onScanEnd(ArrayList arg0) {
68 | mAdapter = new PluginsAdapter(this, arg0);
69 | mListView.setAdapter(mAdapter);
70 | }
71 |
72 | @Override
73 | public void onScanStart() {
74 | }
75 |
76 | @Override
77 | public void onItemClick(AdapterView> parent, View view, int pos, long id) {
78 | PluginManager.getInstance().startPlugin((PluginInfo) mAdapter.getItem(pos));
79 | }
80 |
81 | static class PluginsAdapter extends BaseAdapter {
82 |
83 | private Activity mContext;
84 |
85 | private ArrayList mDatas = new ArrayList();
86 |
87 | private LayoutInflater mInflater;
88 |
89 | public PluginsAdapter(Activity context, ArrayList datas) {
90 | if (datas == null) {
91 | return;
92 | }
93 | this.mContext = context;
94 | this.mDatas = datas;
95 | mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
96 | }
97 |
98 | @Override
99 | public int getCount() {
100 | return mDatas.size();
101 | }
102 |
103 | @Override
104 | public Object getItem(int arg0) {
105 | return mDatas.get(arg0);
106 | }
107 |
108 | @Override
109 | public long getItemId(int arg0) {
110 | return arg0;
111 | }
112 |
113 | @Override
114 | public View getView(int pos, View convertView, ViewGroup parent) {
115 | if (convertView == null) {
116 | convertView = mInflater.inflate(R.layout.plugin_item, parent, false);
117 | }
118 | TextView tv = (TextView) convertView.findViewById(R.id.name);
119 | final PluginInfo info = mDatas.get(pos);
120 | tv.setText(info.applicationName);
121 | Button btn = (Button) convertView.findViewById(R.id.status);
122 | btn.setFocusable(false);
123 | if (info.isInstalled) {
124 | btn.setText("uninstall");
125 | btn.setOnClickListener(new View.OnClickListener() {
126 |
127 | @Override
128 | public void onClick(View arg0) {
129 | PluginManager.getInstance().uninstallPlugin(mContext, info.packageName);
130 | notifyDataSetChanged();
131 | }
132 | });
133 | } else {
134 | btn.setText("install");
135 | btn.setOnClickListener(new View.OnClickListener() {
136 |
137 | @Override
138 | public void onClick(View arg0) {
139 | PluginManager.getInstance().installPlugin(info, (InstallPluginListener) mContext);
140 | ;
141 | }
142 | });
143 | }
144 | return convertView;
145 | }
146 |
147 | }
148 |
149 | @Override
150 | public void onInstallEnd(PluginInfo arg0) {
151 | mAdapter.notifyDataSetChanged();
152 | PluginManager.getInstance().startPlugin(arg0);
153 | }
154 |
155 | @Override
156 | public void onInstallStart(PluginInfo arg0) {
157 |
158 | }
159 |
160 | @Override
161 | public boolean onCreateOptionsMenu(Menu menu) {
162 | return super.onCreateOptionsMenu(menu);
163 | }
164 |
165 | @Override
166 | public boolean onPrepareOptionsMenu(Menu menu) {
167 | menu.add("menu1");
168 | menu.add("menu2");
169 | menu.add("menu3");
170 | return super.onPrepareOptionsMenu(menu);
171 | }
172 |
173 | @Override
174 | public void onCopyStart() {
175 |
176 | }
177 |
178 | @Override
179 | public void onCopyEnd() {
180 | PluginManager.getInstance().scanApks(this);
181 | }
182 |
183 | @Override
184 | protected void onDestroy() {
185 | super.onDestroy();
186 | PluginManager.getInstance().destory();
187 | }
188 |
189 | }
190 |
--------------------------------------------------------------------------------
/PluginApp/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/PluginApp/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
35 |
36 |
37 |
38 |
41 |
42 |
43 |
44 |
47 |
48 |
49 |
50 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/PluginApp/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | PluginApp
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 | ?name?
14 |
15 |
16 |
17 | org.eclipse.cdt.make.core.append_environment
18 | true
19 |
20 |
21 | org.eclipse.cdt.make.core.autoBuildTarget
22 | all
23 |
24 |
25 | org.eclipse.cdt.make.core.buildArguments
26 |
27 |
28 |
29 | org.eclipse.cdt.make.core.buildCommand
30 | /Users/zhaoxuyang/Documents/android-ndk-r9c/ndk-build
31 |
32 |
33 | org.eclipse.cdt.make.core.cleanBuildTarget
34 | clean
35 |
36 |
37 | org.eclipse.cdt.make.core.contents
38 | org.eclipse.cdt.make.core.activeConfigSettings
39 |
40 |
41 | org.eclipse.cdt.make.core.enableAutoBuild
42 | false
43 |
44 |
45 | org.eclipse.cdt.make.core.enableCleanBuild
46 | true
47 |
48 |
49 | org.eclipse.cdt.make.core.enableFullBuild
50 | true
51 |
52 |
53 | org.eclipse.cdt.make.core.fullBuildTarget
54 | all
55 |
56 |
57 | org.eclipse.cdt.make.core.stopOnError
58 | true
59 |
60 |
61 | org.eclipse.cdt.make.core.useDefaultBuildCmd
62 | false
63 |
64 |
65 |
66 |
67 | com.android.ide.eclipse.adt.ResourceManagerBuilder
68 |
69 |
70 |
71 |
72 | com.android.ide.eclipse.adt.PreCompilerBuilder
73 |
74 |
75 |
76 |
77 | org.eclipse.jdt.core.javabuilder
78 |
79 |
80 |
81 |
82 | com.android.ide.eclipse.adt.ApkBuilder
83 |
84 |
85 |
86 |
87 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
88 | full,incremental,
89 |
90 |
91 |
92 |
93 |
94 | com.android.ide.eclipse.adt.AndroidNature
95 | org.eclipse.jdt.core.javanature
96 | org.eclipse.cdt.core.cnature
97 | org.eclipse.cdt.core.ccnature
98 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
99 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
100 |
101 |
102 |
--------------------------------------------------------------------------------
/PluginApp/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
42 |
43 |
44 |
45 |
46 |
47 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/PluginApp/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/PluginApp/ic_launcher-web.png
--------------------------------------------------------------------------------
/PluginApp/jni/Android.mk:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2009 The Android Open Source Project
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | #
15 | LOCAL_PATH := $(call my-dir)
16 |
17 | include $(CLEAR_VARS)
18 |
19 | LOCAL_MODULE := hello-jni
20 | LOCAL_SRC_FILES := com_example_pluginapp_TestNative.c
21 |
22 | include $(BUILD_SHARED_LIBRARY)
23 |
--------------------------------------------------------------------------------
/PluginApp/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_ABI := all
--------------------------------------------------------------------------------
/PluginApp/jni/com_example_pluginapp_TestNative.c:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | #include "com_example_pluginapp_TestNative.h"
4 | /*
5 | * Class: com_example_pluginapp_TestNative
6 | * Method: testNative
7 | * Signature: ()Ljava/lang/String;
8 | */
9 | JNIEXPORT jstring JNICALL Java_com_example_pluginapp_TestNative_testNative
10 | (JNIEnv *env, jclass clazz)
11 | {
12 | return (*env)->NewStringUTF(env,"hello from native");
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/PluginApp/jni/com_example_pluginapp_TestNative.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_example_pluginapp_TestNative */
4 |
5 | #ifndef _Included_com_example_pluginapp_TestNative
6 | #define _Included_com_example_pluginapp_TestNative
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: com_example_pluginapp_TestNative
12 | * Method: testNative
13 | * Signature: ()Ljava/lang/String;
14 | */
15 | JNIEXPORT jstring JNICALL Java_com_example_pluginapp_TestNative_testNative
16 | (JNIEnv *, jclass);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/PluginApp/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example.pluginapp
7 | PluginApp
8 | 1.0.0
9 | apk
10 |
11 |
12 | UTF-8
13 |
14 |
15 | PluginApp
16 |
17 |
18 |
19 | com.google.android
20 | android
21 | 4.1.1.4
22 | provided
23 |
24 |
25 |
26 | koala
27 | koala
28 | 1.0
29 | provided
30 |
31 |
32 |
33 |
34 | src
35 | ${project.artifactId}
36 |
37 |
38 |
39 | com.jayway.maven.plugins.android.generation2
40 | android-maven-plugin
41 | 3.8.2
42 | true
43 |
44 |
45 |
46 |
47 |
48 | com.jayway.maven.plugins.android.generation2
49 | android-maven-plugin
50 |
51 |
52 |
53 | 17
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/PluginApp/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/PluginApp/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-10
15 |
--------------------------------------------------------------------------------
/PluginApp/res/drawable-hdpi/a.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/PluginApp/res/drawable-hdpi/a.jpeg
--------------------------------------------------------------------------------
/PluginApp/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/PluginApp/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PluginApp/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/PluginApp/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PluginApp/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/PluginApp/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PluginApp/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/PluginApp/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PluginApp/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
16 |
17 |
22 |
23 |
28 |
29 |
34 |
35 |
40 |
41 |
46 |
47 |
52 |
53 |
58 |
59 |
64 |
65 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/PluginApp/res/layout/second_activity.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/PluginApp/res/layout/third_activity.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/PluginApp/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/PluginApp/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PluginApp/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PluginApp
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.PluginActivity;
5 | import android.app.PluginManager;
6 | import android.content.BroadcastReceiver;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.IntentFilter;
10 | import android.os.Bundle;
11 | import android.view.View;
12 | import android.view.View.OnClickListener;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | public class MainActivity extends PluginActivity implements OnClickListener{
17 |
18 | static{
19 | System.loadLibrary("hello-jni");
20 | }
21 |
22 | private MyReceiver receiver;
23 |
24 | private boolean hasRegisted;
25 |
26 | private AlertDialog dialog;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 | findViewById(R.id.second_activity).setOnClickListener(this);
33 | findViewById(R.id.third_activity).setOnClickListener(this);
34 | findViewById(R.id.start_service).setOnClickListener(this);
35 | findViewById(R.id.stopservice).setOnClickListener(this);
36 | findViewById(R.id.registreceiver).setOnClickListener(this);
37 | findViewById(R.id.unregistreceiver).setOnClickListener(this);
38 | findViewById(R.id.sendbroadcat).setOnClickListener(this);
39 | findViewById(R.id.showdialog).setOnClickListener(this);
40 | findViewById(R.id.test_native).setOnClickListener(this);
41 | receiver = new MyReceiver();
42 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
43 | builder.setTitle("test").setMessage("dialog").setPositiveButton("ok", null)
44 | .setNegativeButton("cancel", null);
45 | dialog = builder.create();
46 | }
47 |
48 | public void onClick(View view) {
49 |
50 | int id = view.getId();
51 |
52 | switch (id) {
53 | case R.id.second_activity:
54 | Intent intent = new Intent(this, SecondActivity.class);
55 | startActivity(intent);
56 | break;
57 | case R.id.third_activity:
58 | intent = new Intent("com.example.pluginapp.ThirdActivity");
59 | startActivity(intent);
60 | break;
61 | case R.id.start_service:
62 | startService(new Intent(this, MyService.class));
63 | break;
64 | case R.id.stopservice:
65 | stopService(new Intent("com.example.pluginapp.MyService"));
66 | break;
67 | case R.id.registreceiver:
68 | if(hasRegisted){
69 | PluginManager.getInstance().showToast(this, "has registed", Toast.LENGTH_LONG);
70 | return;
71 | }
72 | registerReceiver(receiver, new IntentFilter("com.example.pluginapp.MyReceiver"));
73 | hasRegisted = true;
74 | break;
75 | case R.id.unregistreceiver:
76 | if(!hasRegisted){
77 | PluginManager.getInstance().showToast(this, "not registed", Toast.LENGTH_LONG);
78 | return;
79 | }
80 | unregisterReceiver(receiver);
81 | hasRegisted = false;
82 | break;
83 | case R.id.sendbroadcat:
84 | sendBroadcast(new Intent("com.example.pluginapp.MyReceiver"));
85 | break;
86 | case R.id.showdialog:
87 | if(!dialog.isShowing()){
88 | dialog.show();
89 | }
90 | break;
91 | case R.id.test_native:
92 | TextView tv = (TextView) findViewById(R.id.res);
93 | tv.setText("jnires:"+TestNative.testNative());
94 | break;
95 | }
96 | }
97 |
98 | @Override
99 | protected void onDestroy() {
100 | super.onDestroy();
101 | if(hasRegisted){
102 | unregisterReceiver(receiver);
103 | hasRegisted = false;
104 | }
105 | }
106 |
107 |
108 | public static class MyReceiver extends BroadcastReceiver{
109 |
110 | @Override
111 | public void onReceive(Context arg0, Intent arg1) {
112 | PluginManager.getInstance().showToast(arg0, "动态注册的收到了", Toast.LENGTH_LONG);
113 | }
114 |
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | import android.app.PluginApplication;
4 | import android.app.PluginManager;
5 | import android.util.Log;
6 | import android.widget.Toast;
7 |
8 | public class MyApplication extends PluginApplication{
9 |
10 | @Override
11 | public void onCreate() {
12 | super.onCreate();
13 | Log.e("application", "oncreate");
14 | PluginManager.getInstance().showToast(this, "application oncreate", Toast.LENGTH_LONG);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/MyService.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | import android.app.PluginManager;
4 | import android.app.PluginService;
5 | import android.content.Intent;
6 | import android.os.IBinder;
7 | import android.widget.Toast;
8 |
9 | public class MyService extends PluginService{
10 |
11 |
12 | @Override
13 | public int onStartCommand(Intent intent, int flags, int startId) {
14 | PluginManager.getInstance().showToast(this, "service start", Toast.LENGTH_LONG);
15 | return super.onStartCommand(intent, flags, startId);
16 | }
17 |
18 |
19 | @Override
20 | public void onDestroy() {
21 | PluginManager.getInstance().showToast(this, "service destory", Toast.LENGTH_LONG);
22 | super.onDestroy();
23 | }
24 |
25 | @Override
26 | public IBinder onBind(Intent arg0) {
27 | return null;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/MyStaticReceiver.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | import android.app.PluginManager;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.os.Handler;
8 | import android.os.Looper;
9 | import android.widget.Toast;
10 |
11 | public class MyStaticReceiver extends BroadcastReceiver{
12 |
13 | private Handler handler = new Handler(Looper.getMainLooper());
14 |
15 | @Override
16 | public void onReceive(final Context arg0, Intent arg1) {
17 | handler.postDelayed(new Runnable() {
18 |
19 | @Override
20 | public void run() {
21 | PluginManager.getInstance().showToast(arg0, "静态注册的收到了", Toast.LENGTH_LONG);
22 | }
23 | }, 5000);
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | import android.app.PluginActivity;
4 | import android.os.Bundle;
5 |
6 | public class SecondActivity extends PluginActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.second_activity);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/TestNative.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | public class TestNative {
4 |
5 | public native static String testNative();
6 | }
7 |
--------------------------------------------------------------------------------
/PluginApp/src/com/example/pluginapp/ThirdActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.pluginapp;
2 |
3 | import android.app.PluginActivity;
4 | import android.os.Bundle;
5 |
6 | public class ThirdActivity extends PluginActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.third_activity);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | koala
2 | =====
3 |
4 | Android插件平台 KOALA
5 |
6 | 该平台目前:
7 | 1、支持Activity(显式,隐式启动),Service(显式,隐式启动),BroadcastReceiver(动态注册,静态注册),ContentProvider。
8 | 2、支持插件间互调。
9 | 3、支持本地库。
10 | 4、支持插件包资源访问。
11 | 5、支持插件自己的data目录。
12 |
13 | 一共有3个项目:
14 | 1、koala:是插件的sdk,包含的插件的安装,启动,卸载等功能,该项目是不可运行的Android项目,libs目录下的frameworks-classes-full-debug.jar和libcore-classes-full-debug是基于Android4.4.2源码编译成userdebug版SDK,主要用于访问hide的API
15 | 2、MainApp:使用插件sdk的项目,调用插件的API来管理插件,asset目录下有测试的插件demo,项目运行时会将其拷贝到/sdcard/koala目录下。
16 | 3、PluginApp:上个项目中插件demo的源码,该项目开发时需要把koala SDK作为外部jar包导入。
17 |
18 | 你可以通过运行MainApp,来启动插件demo。
19 |
20 | 注意事项:
21 | 1、插件中弹出Toast必须使用插件SDK中的showToast方法,否则不显示。
22 | 2、插件中有本地库加载的话,由于虚拟机没有提供本地库卸载的功能,所以卸载的时候只能重启应用。
23 | 3、兼容Android2.3到5.0。
24 | 4、因为用了一些反射,不保证兼容所有ROM。
25 |
--------------------------------------------------------------------------------
/koala/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/koala/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | koala
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/koala/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/koala/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/android-support-v4.jar
--------------------------------------------------------------------------------
/koala/frameworks-classes-full-debug.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/frameworks-classes-full-debug.jar
--------------------------------------------------------------------------------
/koala/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/ic_launcher-web.png
--------------------------------------------------------------------------------
/koala/libcore-classes-full-debug.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/libcore-classes-full-debug.jar
--------------------------------------------------------------------------------
/koala/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | koala
7 | koala
8 | 1.0
9 | jar
10 |
11 | UTF-8
12 |
13 |
14 |
15 |
16 | android.support
17 | android.support
18 | 1.0
19 | ${basedir}/libs/android-support-v4.jar
20 |
21 | system
22 |
23 |
24 | android_api
25 | android_api
26 | 1.0
27 | ${basedir}/libs/frameworks-classes-full-debug.jar
28 |
29 | system
30 |
31 |
32 | java_api
33 | java_api
34 | 1.0
35 | system
36 | ${basedir}/libs/libcore-classes-full-debug.jar
37 |
38 |
39 |
40 |
41 |
42 | ${project.artifactId}
43 | src
44 |
45 |
46 |
--------------------------------------------------------------------------------
/koala/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/koala/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-10
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/koala/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/koala/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/koala/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/koala/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaoxuyang/koala--Android-Plugin-Runtime-/e2b2d453d312243920dea09d588012329729638b/koala/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/koala/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | koala
4 |
5 |
6 |
--------------------------------------------------------------------------------
/koala/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/koala/src/android/app/ActivityIntentResolver.java:
--------------------------------------------------------------------------------
1 | package android.app;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.ArrayList;
5 | import java.util.HashMap;
6 | import java.util.List;
7 |
8 | import android.content.ComponentName;
9 | import android.content.Intent;
10 | import android.content.pm.PackageManager;
11 | import android.content.pm.PackageParser;
12 |
13 | /**
14 | * 基于源码做的更改
15 | * @author zhaoxuyang
16 | * @since 2014-11-14
17 | */
18 | final class ActivityIntentResolver extends
19 | IntentResolver {
20 |
21 | public List queryIntent(Intent intent, String resolvedType,
22 | boolean defaultOnly) {
23 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
24 | return super.queryIntent(intent, resolvedType, defaultOnly);
25 | }
26 |
27 | public List queryIntent(Intent intent, String resolvedType, int flags) {
28 | mFlags = flags;
29 | return super.queryIntent(intent, resolvedType,
30 | (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0);
31 | }
32 |
33 | public List queryIntentForPackage(Intent intent, String resolvedType,
34 | int flags, ArrayList packageActivities) {
35 | if (packageActivities == null) {
36 | return null;
37 | }
38 | mFlags = flags;
39 | final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
40 | int N = packageActivities.size();
41 | ArrayList> listCut = new ArrayList>(
42 | N);
43 |
44 | ArrayList intentFilters;
45 | for (int i = 0; i < N; ++i) {
46 | intentFilters = packageActivities.get(i).intents;
47 | if (intentFilters != null && intentFilters.size() > 0) {
48 | listCut.add(intentFilters);
49 | }
50 | }
51 | return super.queryIntentFromList(intent, resolvedType, defaultOnly,
52 | listCut);
53 | }
54 |
55 | public final void addActivity(PackageParser.Activity a) {
56 | mActivities.put(a.getComponentName(), a);
57 | int NI = a.intents.size();
58 | for (int j = 0; j < NI; j++) {
59 | PackageParser.ActivityIntentInfo intent = a.intents.get(j);
60 | addFilter(intent);
61 | }
62 | }
63 |
64 | public final void removeActivity(PackageParser.Activity a) {
65 | mActivities.remove(a.getComponentName());
66 | int NI = a.intents.size();
67 | for (int j = 0; j < NI; j++) {
68 | PackageParser.ActivityIntentInfo intent = a.intents.get(j);
69 | removeFilter(intent);
70 | }
71 | }
72 |
73 | @Override
74 | protected boolean allowFilterResult(
75 | PackageParser.ActivityIntentInfo filter, List dest) {
76 | for (int i = dest.size() - 1; i >= 0; i--) {
77 | PackageParser.Activity destAi = dest.get(i);
78 | if (destAi == filter.activity) {
79 | return false;
80 | }
81 | }
82 | return true;
83 | }
84 |
85 | @Override
86 | protected String packageForFilter(PackageParser.ActivityIntentInfo info) {
87 | return info.activity.owner.packageName;
88 | }
89 |
90 | @Override
91 | protected PackageParser.Activity newResult(PackageParser.ActivityIntentInfo info,
92 | int match) {
93 | return info.activity;
94 | }
95 |
96 | @Override
97 | protected void sortResults(List results) {
98 | }
99 |
100 | @Override
101 | protected void dumpFilter(PrintWriter out, String prefix,
102 | PackageParser.ActivityIntentInfo filter) {
103 | out.print(prefix);
104 | out.print(Integer.toHexString(System.identityHashCode(filter.activity)));
105 | out.print(' ');
106 | out.print(filter.activity.getComponentName());
107 | out.print(" filter ");
108 | out.println(Integer.toHexString(System.identityHashCode(filter)));
109 | }
110 |
111 | // Keys are String (activity class name), values are Activity.
112 | public final HashMap mActivities = new HashMap();
113 | private int mFlags;
114 |
115 |
116 | }
--------------------------------------------------------------------------------
/koala/src/android/app/ApkFile.java:
--------------------------------------------------------------------------------
1 | package android.app;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | * 插件的描述
7 | * @author zhaoxuyang
8 | * @since 2014-11-14
9 | */
10 | public class ApkFile {
11 |
12 | public String name;
13 |
14 | public String apkName;
15 |
16 | public ArrayList nativeLibs = new ArrayList();
17 |
18 | public float version;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/koala/src/android/app/CopyPluginListener.java:
--------------------------------------------------------------------------------
1 | package android.app;
2 |
3 | /**
4 | * 扫描插件的回掉
5 | *
6 | * @author zhaoxuyang
7 | *
8 | */
9 | public interface CopyPluginListener {
10 |
11 | /**
12 | * 扫描开始
13 | */
14 | void onCopyStart();
15 |
16 | /**
17 | * 扫描结束
18 | *
19 | * @param paramArrayList
20 | * 插件列表
21 | */
22 | void onCopyEnd();
23 | }
--------------------------------------------------------------------------------
/koala/src/android/app/InstallPluginListener.java:
--------------------------------------------------------------------------------
1 | package android.app;
2 |
3 | /**
4 | * 插件安装的回掉
5 | *
6 | * @author zhaoxuyang
7 | *
8 | */
9 | public interface InstallPluginListener {
10 |
11 | /**
12 | * 插件开始安装
13 | *
14 | * @param info
15 | * 插件信息
16 | */
17 | void onInstallStart(PluginInfo info);
18 |
19 | /**
20 | * 插件安装完成
21 | *
22 | * @param info
23 | * 插件信息
24 | */
25 | void onInstallEnd(PluginInfo info);
26 | }
--------------------------------------------------------------------------------
/koala/src/android/app/IntentResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2006 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package android.app;
18 |
19 | import java.io.PrintWriter;
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.Comparator;
23 | import java.util.HashMap;
24 | import java.util.HashSet;
25 | import java.util.Iterator;
26 | import java.util.List;
27 | import java.util.Map;
28 | import java.util.Set;
29 |
30 | import android.util.Log;
31 | import android.util.PrintWriterPrinter;
32 | import android.util.Slog;
33 | import android.util.LogPrinter;
34 | import android.util.Printer;
35 |
36 | import android.content.Intent;
37 | import android.content.IntentFilter;
38 |
39 | /**
40 | * 基于源码做的更改
41 | * @author zhaoxuyang
42 | * @since 2014-11-14
43 | * @param
44 | * @param
45 | */
46 | public class IntentResolver {
47 | final private static String TAG = "IntentResolver";
48 | final private static boolean DEBUG = false;
49 | final private static boolean localLOGV = DEBUG;
50 |
51 | public void addFilter(F f) {
52 | if (localLOGV) {
53 | Slog.v(TAG, "Adding filter: " + f);
54 | f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
55 | Slog.v(TAG, " Building Lookup Maps:");
56 | }
57 |
58 | mFilters.add(f);
59 | int numS = register_intent_filter(f, f.schemesIterator(),
60 | mSchemeToFilter, " Scheme: ");
61 | int numT = register_mime_types(f, " Type: ");
62 | if (numS == 0 && numT == 0) {
63 | register_intent_filter(f, f.actionsIterator(),
64 | mActionToFilter, " Action: ");
65 | }
66 | if (numT != 0) {
67 | register_intent_filter(f, f.actionsIterator(),
68 | mTypedActionToFilter, " TypedAction: ");
69 | }
70 | }
71 |
72 | public void removeFilter(F f) {
73 | removeFilterInternal(f);
74 | mFilters.remove(f);
75 | }
76 |
77 | void removeFilterInternal(F f) {
78 | if (localLOGV) {
79 | Slog.v(TAG, "Removing filter: " + f);
80 | f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
81 | Slog.v(TAG, " Cleaning Lookup Maps:");
82 | }
83 |
84 | int numS = unregister_intent_filter(f, f.schemesIterator(),
85 | mSchemeToFilter, " Scheme: ");
86 | int numT = unregister_mime_types(f, " Type: ");
87 | if (numS == 0 && numT == 0) {
88 | unregister_intent_filter(f, f.actionsIterator(),
89 | mActionToFilter, " Action: ");
90 | }
91 | if (numT != 0) {
92 | unregister_intent_filter(f, f.actionsIterator(),
93 | mTypedActionToFilter, " TypedAction: ");
94 | }
95 | }
96 |
97 | boolean dumpMap(PrintWriter out, String titlePrefix, String title,
98 | String prefix, Map> map, String packageName,
99 | boolean printFilter) {
100 | String eprefix = prefix + " ";
101 | String fprefix = prefix + " ";
102 | boolean printedSomething = false;
103 | Printer printer = null;
104 | for (Map.Entry> e : map.entrySet()) {
105 | ArrayList a = e.getValue();
106 | final int N = a.size();
107 | boolean printedHeader = false;
108 | for (int i=0; i {
167 | private final Iterator mI;
168 | private F mCur;
169 |
170 | IteratorWrapper(Iterator it) {
171 | mI = it;
172 | }
173 |
174 | public boolean hasNext() {
175 | return mI.hasNext();
176 | }
177 |
178 | public F next() {
179 | return (mCur = mI.next());
180 | }
181 |
182 | public void remove() {
183 | if (mCur != null) {
184 | removeFilterInternal(mCur);
185 | }
186 | mI.remove();
187 | }
188 |
189 | }
190 |
191 | /**
192 | * Returns an iterator allowing filters to be removed.
193 | */
194 | public Iterator filterIterator() {
195 | return new IteratorWrapper(mFilters.iterator());
196 | }
197 |
198 | /**
199 | * Returns a read-only set of the filters.
200 | */
201 | public Set filterSet() {
202 | return Collections.unmodifiableSet(mFilters);
203 | }
204 |
205 | public List queryIntentFromList(Intent intent, String resolvedType,
206 | boolean defaultOnly, ArrayList> listCut) {
207 | ArrayList resultList = new ArrayList();
208 |
209 | final boolean debug = localLOGV ||
210 | ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);
211 |
212 | final String scheme = intent.getScheme();
213 | int N = listCut.size();
214 | for (int i = 0; i < N; ++i) {
215 | buildResolveList(intent, debug, defaultOnly,
216 | resolvedType, scheme, listCut.get(i), resultList);
217 | }
218 | sortResults(resultList);
219 | return resultList;
220 | }
221 |
222 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) {
223 | String scheme = intent.getScheme();
224 |
225 | ArrayList finalList = new ArrayList();
226 |
227 | final boolean debug = localLOGV ||
228 | ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);
229 |
230 | if (debug) Slog.v(
231 | TAG, "Resolving type " + resolvedType + " scheme " + scheme
232 | + " of intent " + intent);
233 |
234 | ArrayList firstTypeCut = null;
235 | ArrayList secondTypeCut = null;
236 | ArrayList thirdTypeCut = null;
237 | ArrayList schemeCut = null;
238 |
239 | // If the intent includes a MIME type, then we want to collect all of
240 | // the filters that match that MIME type.
241 | if (resolvedType != null) {
242 | int slashpos = resolvedType.indexOf('/');
243 | if (slashpos > 0) {
244 | final String baseType = resolvedType.substring(0, slashpos);
245 | if (!baseType.equals("*")) {
246 | if (resolvedType.length() != slashpos+2
247 | || resolvedType.charAt(slashpos+1) != '*') {
248 | // Not a wild card, so we can just look for all filters that
249 | // completely match or wildcards whose base type matches.
250 | firstTypeCut = mTypeToFilter.get(resolvedType);
251 | if (debug) Slog.v(TAG, "First type cut: " + firstTypeCut);
252 | secondTypeCut = mWildTypeToFilter.get(baseType);
253 | if (debug) Slog.v(TAG, "Second type cut: " + secondTypeCut);
254 | } else {
255 | // We can match anything with our base type.
256 | firstTypeCut = mBaseTypeToFilter.get(baseType);
257 | if (debug) Slog.v(TAG, "First type cut: " + firstTypeCut);
258 | secondTypeCut = mWildTypeToFilter.get(baseType);
259 | if (debug) Slog.v(TAG, "Second type cut: " + secondTypeCut);
260 | }
261 | // Any */* types always apply, but we only need to do this
262 | // if the intent type was not already */*.
263 | thirdTypeCut = mWildTypeToFilter.get("*");
264 | if (debug) Slog.v(TAG, "Third type cut: " + thirdTypeCut);
265 | } else if (intent.getAction() != null) {
266 | // The intent specified any type ({@literal *}/*). This
267 | // can be a whole heck of a lot of things, so as a first
268 | // cut let's use the action instead.
269 | firstTypeCut = mTypedActionToFilter.get(intent.getAction());
270 | if (debug) Slog.v(TAG, "Typed Action list: " + firstTypeCut);
271 | }
272 | }
273 | }
274 |
275 | // If the intent includes a data URI, then we want to collect all of
276 | // the filters that match its scheme (we will further refine matches
277 | // on the authority and path by directly matching each resulting filter).
278 | if (scheme != null) {
279 | schemeCut = mSchemeToFilter.get(scheme);
280 | if (debug) Slog.v(TAG, "Scheme list: " + schemeCut);
281 | }
282 |
283 | // If the intent does not specify any data -- either a MIME type or
284 | // a URI -- then we will only be looking for matches against empty
285 | // data.
286 | if (resolvedType == null && scheme == null && intent.getAction() != null) {
287 | firstTypeCut = mActionToFilter.get(intent.getAction());
288 | if (debug) Slog.v(TAG, "Action list: " + firstTypeCut);
289 | }
290 |
291 | if (firstTypeCut != null) {
292 | buildResolveList(intent, debug, defaultOnly,
293 | resolvedType, scheme, firstTypeCut, finalList);
294 | }
295 | if (secondTypeCut != null) {
296 | buildResolveList(intent, debug, defaultOnly,
297 | resolvedType, scheme, secondTypeCut, finalList);
298 | }
299 | if (thirdTypeCut != null) {
300 | buildResolveList(intent, debug, defaultOnly,
301 | resolvedType, scheme, thirdTypeCut, finalList);
302 | }
303 | if (schemeCut != null) {
304 | buildResolveList(intent, debug, defaultOnly,
305 | resolvedType, scheme, schemeCut, finalList);
306 | }
307 | sortResults(finalList);
308 |
309 | if (debug) {
310 | Slog.v(TAG, "Final result list:");
311 | for (R r : finalList) {
312 | Slog.v(TAG, " " + r);
313 | }
314 | }
315 | return finalList;
316 | }
317 |
318 | /**
319 | * Control whether the given filter is allowed to go into the result
320 | * list. Mainly intended to prevent adding multiple filters for the
321 | * same target object.
322 | */
323 | protected boolean allowFilterResult(F filter, List dest) {
324 | return true;
325 | }
326 |
327 | protected String packageForFilter(F filter) {
328 | return null;
329 | }
330 |
331 | protected R newResult(F filter, int match) {
332 | return (R)filter;
333 | }
334 |
335 | protected void sortResults(List results) {
336 | Collections.sort(results, mResolvePrioritySorter);
337 | }
338 |
339 | protected void dumpFilter(PrintWriter out, String prefix, F filter) {
340 | out.print(prefix); out.println(filter);
341 | }
342 |
343 | private final int register_mime_types(F filter, String prefix) {
344 | final Iterator i = filter.typesIterator();
345 | if (i == null) {
346 | return 0;
347 | }
348 |
349 | int num = 0;
350 | while (i.hasNext()) {
351 | String name = i.next();
352 | num++;
353 | if (localLOGV) Slog.v(TAG, prefix + name);
354 | String baseName = name;
355 | final int slashpos = name.indexOf('/');
356 | if (slashpos > 0) {
357 | baseName = name.substring(0, slashpos).intern();
358 | } else {
359 | name = name + "/*";
360 | }
361 |
362 | ArrayList array = mTypeToFilter.get(name);
363 | if (array == null) {
364 | //Slog.v(TAG, "Creating new array for " + name);
365 | array = new ArrayList();
366 | mTypeToFilter.put(name, array);
367 | }
368 | array.add(filter);
369 |
370 | if (slashpos > 0) {
371 | array = mBaseTypeToFilter.get(baseName);
372 | if (array == null) {
373 | //Slog.v(TAG, "Creating new array for " + name);
374 | array = new ArrayList();
375 | mBaseTypeToFilter.put(baseName, array);
376 | }
377 | array.add(filter);
378 | } else {
379 | array = mWildTypeToFilter.get(baseName);
380 | if (array == null) {
381 | //Slog.v(TAG, "Creating new array for " + name);
382 | array = new ArrayList();
383 | mWildTypeToFilter.put(baseName, array);
384 | }
385 | array.add(filter);
386 | }
387 | }
388 |
389 | return num;
390 | }
391 |
392 | private final int unregister_mime_types(F filter, String prefix) {
393 | final Iterator i = filter.typesIterator();
394 | if (i == null) {
395 | return 0;
396 | }
397 |
398 | int num = 0;
399 | while (i.hasNext()) {
400 | String name = i.next();
401 | num++;
402 | if (localLOGV) Slog.v(TAG, prefix + name);
403 | String baseName = name;
404 | final int slashpos = name.indexOf('/');
405 | if (slashpos > 0) {
406 | baseName = name.substring(0, slashpos).intern();
407 | } else {
408 | name = name + "/*";
409 | }
410 |
411 | if (!remove_all_objects(mTypeToFilter.get(name), filter)) {
412 | mTypeToFilter.remove(name);
413 | }
414 |
415 | if (slashpos > 0) {
416 | if (!remove_all_objects(mBaseTypeToFilter.get(baseName), filter)) {
417 | mBaseTypeToFilter.remove(baseName);
418 | }
419 | } else {
420 | if (!remove_all_objects(mWildTypeToFilter.get(baseName), filter)) {
421 | mWildTypeToFilter.remove(baseName);
422 | }
423 | }
424 | }
425 | return num;
426 | }
427 |
428 | private final int register_intent_filter(F filter, Iterator i,
429 | HashMap> dest, String prefix) {
430 | if (i == null) {
431 | return 0;
432 | }
433 |
434 | int num = 0;
435 | while (i.hasNext()) {
436 | String name = i.next();
437 | num++;
438 | if (localLOGV) Slog.v(TAG, prefix + name);
439 | ArrayList array = dest.get(name);
440 | if (array == null) {
441 | //Slog.v(TAG, "Creating new array for " + name);
442 | array = new ArrayList();
443 | dest.put(name, array);
444 | }
445 | array.add(filter);
446 | }
447 | return num;
448 | }
449 |
450 | private final int unregister_intent_filter(F filter, Iterator i,
451 | HashMap> dest, String prefix) {
452 | if (i == null) {
453 | return 0;
454 | }
455 |
456 | int num = 0;
457 | while (i.hasNext()) {
458 | String name = i.next();
459 | num++;
460 | if (localLOGV) Slog.v(TAG, prefix + name);
461 | if (!remove_all_objects(dest.get(name), filter)) {
462 | dest.remove(name);
463 | }
464 | }
465 | return num;
466 | }
467 |
468 | private final boolean remove_all_objects(List list, Object object) {
469 | if (list != null) {
470 | int N = list.size();
471 | for (int idx=0; idx 0;
479 | }
480 | return false;
481 | }
482 |
483 | private void buildResolveList(Intent intent, boolean debug, boolean defaultOnly,
484 | String resolvedType, String scheme, List src, List dest) {
485 | Set categories = intent.getCategories();
486 |
487 | final int N = src != null ? src.size() : 0;
488 | boolean hasNonDefaults = false;
489 | int i;
490 | for (i=0; i= 0) {
506 | if (debug) Slog.v(TAG, " Filter matched! match=0x" +
507 | Integer.toHexString(match));
508 | if (!defaultOnly || filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
509 | final R oneResult = newResult(filter, match);
510 | if (oneResult != null) {
511 | dest.add(oneResult);
512 | }
513 | } else {
514 | hasNonDefaults = true;
515 | }
516 | } else {
517 | if (debug) {
518 | String reason;
519 | switch (match) {
520 | case IntentFilter.NO_MATCH_ACTION: reason = "action"; break;
521 | case IntentFilter.NO_MATCH_CATEGORY: reason = "category"; break;
522 | case IntentFilter.NO_MATCH_DATA: reason = "data"; break;
523 | case IntentFilter.NO_MATCH_TYPE: reason = "type"; break;
524 | default: reason = "unknown reason"; break;
525 | }
526 | Slog.v(TAG, " Filter did not match: " + reason);
527 | }
528 | }
529 | }
530 |
531 | if (dest.size() == 0 && hasNonDefaults) {
532 | Slog.w(TAG, "resolveIntent failed: found match, but none with Intent.CATEGORY_DEFAULT");
533 | }
534 | }
535 |
536 | // Sorts a List of IntentFilter objects into descending priority order.
537 | private static final Comparator mResolvePrioritySorter = new Comparator() {
538 | public int compare(Object o1, Object o2) {
539 | final int q1 = ((IntentFilter) o1).getPriority();
540 | final int q2 = ((IntentFilter) o2).getPriority();
541 | return (q1 > q2) ? -1 : ((q1 < q2) ? 1 : 0);
542 | }
543 | };
544 |
545 | /**
546 | * All filters that have been registered.
547 | */
548 | private final HashSet mFilters = new HashSet();
549 |
550 | /**
551 | * All of the MIME types that have been registered, such as "image/jpeg",
552 | * "image/*", or "{@literal *}/*".
553 | */
554 | private final HashMap> mTypeToFilter
555 | = new HashMap>();
556 |
557 | /**
558 | * The base names of all of all fully qualified MIME types that have been
559 | * registered, such as "image" or "*". Wild card MIME types such as
560 | * "image/*" will not be here.
561 | */
562 | private final HashMap> mBaseTypeToFilter
563 | = new HashMap>();
564 |
565 | /**
566 | * The base names of all of the MIME types with a sub-type wildcard that
567 | * have been registered. For example, a filter with "image/*" will be
568 | * included here as "image" but one with "image/jpeg" will not be
569 | * included here. This also includes the "*" for the "{@literal *}/*"
570 | * MIME type.
571 | */
572 | private final HashMap> mWildTypeToFilter
573 | = new HashMap>();
574 |
575 | /**
576 | * All of the URI schemes (such as http) that have been registered.
577 | */
578 | private final HashMap> mSchemeToFilter
579 | = new HashMap>();
580 |
581 | /**
582 | * All of the actions that have been registered, but only those that did
583 | * not specify data.
584 | */
585 | private final HashMap> mActionToFilter
586 | = new HashMap>();
587 |
588 | /**
589 | * All of the actions that have been registered and specified a MIME type.
590 | */
591 | private final HashMap> mTypedActionToFilter
592 | = new HashMap>();
593 | }
594 |
595 |
--------------------------------------------------------------------------------
/koala/src/android/app/LocalBroadcastManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package android.app;
18 |
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 | import java.util.Set;
22 |
23 | import android.content.BroadcastReceiver;
24 | import android.content.Context;
25 | import android.content.Intent;
26 | import android.content.IntentFilter;
27 | import android.net.Uri;
28 | import android.os.Handler;
29 | import android.os.Message;
30 | import android.util.Log;
31 |
32 | /**
33 | * Helper to register for and send broadcasts of Intents to local objects within
34 | * your process. This is has a number of advantages over sending global
35 | * broadcasts with {@link android.content.Context#sendBroadcast}:
36 | *
37 | *
You know that the data you are broadcasting won't leave your app, so
38 | * don't need to worry about leaking private data.
39 | *
It is not possible for other applications to send these broadcasts to
40 | * your app, so you don't need to worry about having security holes they can
41 | * exploit.
42 | *
It is more efficient than sending a global broadcast through the system.
43 | *