Skip to content

Commit

Permalink
feat(core): 支持PackageManager#getProviderInfo方法
Browse files Browse the repository at this point in the history
  • Loading branch information
shifujun committed Apr 7, 2022
1 parent ba40721 commit fa0ef16
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ abstract class ComponentManager : PluginComponentLauncher {
fun getArchiveFilePathForService(className: String) =
getArchiveFilePath(className, PluginManifest::getServices)

fun getArchiveFilePathForProvider(action: String?): kotlin.Pair<String?, String?> {
fun getArchiveFilePathForProviderByAction(action: String?): kotlin.Pair<String?, String?> {
for ((pluginManifest, archiveFilePath) in allLoadedPlugin) {
val providers = pluginManifest.providers
if (providers != null) {
Expand All @@ -320,6 +320,20 @@ abstract class ComponentManager : PluginComponentLauncher {
return null to null
}

fun getArchiveFilePathForProviderByClassName(className: String): kotlin.Pair<String?, String?> {
for ((pluginManifest, archiveFilePath) in allLoadedPlugin) {
val providers = pluginManifest.providers
if (providers != null) {
for (provider in providers) {
if (className == provider.className) {
return provider.className to archiveFilePath
}
}
}
}
return null to null
}

fun getAllArchiveFilePaths() = allLoadedPlugin.map { it.second }.toList()

private fun getArchiveFilePath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ internal class PluginPackageManagerImpl(
PackageManager::getServiceInfo
)

override fun getProviderInfo(component: ComponentName, flags: Int): ProviderInfo {
val (className, archiveFilePath)
= componentManager.getArchiveFilePathForProviderByClassName(component.className)
if (archiveFilePath != null) {
val packageInfo = hostPackageManager.getPackageArchiveInfo(
archiveFilePath, PackageManager.GET_PROVIDERS or flags
)
val componentInfo = packageInfo?.providers?.find {
it.name == className
}
if (componentInfo != null) {
return componentInfo
}
}
return hostPackageManager.getProviderInfo(component, flags)
}

override fun resolveActivity(intent: Intent, flags: Int): ResolveInfo? {
val component = intent.component
if (component != null) {
Expand Down Expand Up @@ -127,7 +144,9 @@ internal class PluginPackageManagerImpl(
}

override fun resolveContentProvider(name: String, flags: Int): ProviderInfo? {
val (className, archiveFilePath) = componentManager.getArchiveFilePathForProvider(name)
val (className, archiveFilePath) = componentManager.getArchiveFilePathForProviderByAction(
name
)
if (archiveFilePath != null) {
val packageInfo = hostPackageManager.getPackageArchiveInfo(
archiveFilePath, PackageManager.GET_PROVIDERS or flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public static ServiceInfo getServiceInfo(ClassLoader classLoaderOfInvokeCode, Co
return getPluginPackageManager(classLoaderOfInvokeCode).getServiceInfo(component, flags);
}

public static ProviderInfo getProviderInfo(ClassLoader classLoaderOfInvokeCode, ComponentName component, int flags) throws PackageManager.NameNotFoundException {
return getPluginPackageManager(classLoaderOfInvokeCode).getProviderInfo(component, flags);
}

public static PackageInfo getPackageInfo(ClassLoader classLoaderOfInvokeCode, String packageName, int flags) throws PackageManager.NameNotFoundException {
return getPluginPackageManager(classLoaderOfInvokeCode).getPackageInfo(packageName, flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface PluginPackageManager {

ServiceInfo getServiceInfo(ComponentName component, int flags);

ProviderInfo getProviderInfo(ComponentName component, int flags);

PackageInfo getPackageInfo(String packageName, int flags);

ProviderInfo resolveContentProvider(String name, int flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.tencent.shadow.core.transform.ShadowTransform.Companion.SelfClassName
import com.tencent.shadow.core.transform_kit.SpecificTransform
import com.tencent.shadow.core.transform_kit.TransformStep
import javassist.*
import java.util.*

class PackageManagerTransform : SpecificTransform() {
companion object {
Expand Down Expand Up @@ -102,6 +101,7 @@ class PackageManagerTransform : SpecificTransform() {
"getApplicationInfo",
"getActivityInfo",
"getServiceInfo",
"getProviderInfo",
"getPackageInfo",
"resolveContentProvider",
"queryContentProviders",
Expand Down

0 comments on commit fa0ef16

Please sign in to comment.