Skip to content

Commit 50678f5

Browse files
committed
feat(core.loader): 支持Context.getPackageCodePath
#816
1 parent f2fef8e commit 50678f5

File tree

6 files changed

+86
-1
lines changed

6 files changed

+86
-1
lines changed

projects/sdk/core/loader/src/main/kotlin/com/tencent/shadow/core/loader/managers/PluginPackageManagerImpl.kt

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ internal class PluginPackageManagerImpl(
9595
return hostPackageManager.resolveService(intent, flags)
9696
}
9797

98+
override fun getArchiveFilePath() = pluginArchiveFilePath
99+
98100
private fun <T : ComponentInfo> getComponentInfo(
99101
component: ComponentName,
100102
flags: Int,

projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/PluginPackageManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.content.pm.PackageInfo;
88
import android.content.pm.ProviderInfo;
99
import android.content.pm.ResolveInfo;
10-
1110
import android.content.pm.ServiceInfo;
1211

1312
import java.util.List;
@@ -28,4 +27,6 @@ public interface PluginPackageManager {
2827
ResolveInfo resolveActivity(Intent intent, int flags);
2928

3029
ResolveInfo resolveService(Intent intent, int flags);
30+
31+
String getArchiveFilePath();
3132
}

projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowContext.java

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ public void unregisterReceiver(BroadcastReceiver receiver) {
283283
}
284284
}
285285

286+
@Override
287+
public String getPackageCodePath() {
288+
PluginPartInfo pluginInfo = PluginPartInfoManager.getPluginInfo(getClassLoader());
289+
return pluginInfo.packageManager.getArchiveFilePath();
290+
}
291+
286292
private BroadcastReceiverWapper wrapBroadcastReceiver(BroadcastReceiver receiver) {
287293
if (receiver == null) {
288294
return null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.tencent.shadow.test.cases.plugin_main;
2+
3+
import android.content.Intent;
4+
5+
import androidx.test.core.app.ApplicationProvider;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
import androidx.test.filters.LargeTest;
8+
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
12+
13+
@RunWith(AndroidJUnit4.class)
14+
@LargeTest
15+
public class ContextGetPackageCodePathTest extends PluginMainAppTest {
16+
17+
@Override
18+
protected Intent getLaunchIntent() {
19+
Intent pluginIntent = new Intent();
20+
String packageName = ApplicationProvider.getApplicationContext().getPackageName();
21+
pluginIntent.setClassName(
22+
packageName,
23+
"com.tencent.shadow.test.plugin.general_cases.lib.usecases.context.ContextGetPackageCodePathTestActivity"
24+
);
25+
return pluginIntent;
26+
}
27+
28+
@Test
29+
public void testGetPackageCodePath() {
30+
matchSubstringWithViewTag("PackageCodePath", "/plugin-debug.zip/test-plugin-general-cases-plugin-debug.apk");
31+
}
32+
33+
}

projects/test/plugin/general-cases/test-plugin-general-cases/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<activity android:name=".lib.usecases.application.ActivityLifecycleCallbacksTestActivity" />
9696
<activity android:name=".lib.usecases.classloader.TestBootClassloaderActivity" />
9797
<activity android:name=".lib.usecases.context.TestLayoutInflaterActivity" />
98+
<activity android:name=".lib.usecases.context.ContextGetPackageCodePathTestActivity" />
9899

99100
<provider
100101
android:name=".lib.usecases.provider.TestProvider"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making Tencent Shadow available.
3+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
*
5+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
6+
* this file except in compliance with the License. You may obtain a copy of
7+
* the License at
8+
*
9+
* https://opensource.org/licenses/BSD-3-Clause
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.tencent.shadow.test.plugin.general_cases.lib.usecases.context;
20+
21+
import android.app.Activity;
22+
import android.os.Bundle;
23+
import android.view.ViewGroup;
24+
25+
import com.tencent.shadow.test.plugin.general_cases.lib.gallery.util.UiUtil;
26+
27+
public class ContextGetPackageCodePathTestActivity extends Activity {
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
ViewGroup mItemViewGroup = UiUtil.setActivityContentView(this);
32+
33+
mItemViewGroup.addView(
34+
UiUtil.makeItem(
35+
this,
36+
"PackageCodePath",
37+
"PackageCodePath",
38+
getPackageCodePath()
39+
)
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)