Skip to content

Commit

Permalink
feat(core): 支持新增API33新增的getPackageInfo方法
Browse files Browse the repository at this point in the history
androidx.profileinstaller.ProfileVerifier中有使用。

Tencent#1277
  • Loading branch information
aprz512 authored and shifujun committed Nov 22, 2024
1 parent e74bebc commit eff207e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion buildScripts/gradle/versions.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
COMPILE_SDK_VERSION=31
COMPILE_SDK_VERSION=33
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=28
VERSION_CODE=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
package com.tencent.shadow.core.loader.managers

import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.ComponentName
import android.content.Intent
import android.content.pm.*
import android.content.pm.ActivityInfo
import android.content.pm.ApplicationInfo
import android.content.pm.ComponentInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.ProviderInfo
import android.content.pm.ResolveInfo
import android.content.pm.ServiceInfo
import android.os.Build
import com.tencent.shadow.core.runtime.PluginPackageManager

@SuppressLint("WrongConstant")
Expand All @@ -41,13 +50,28 @@ internal class PluginPackageManagerImpl(
override fun getPackageInfo(packageName: String, flags: Int): PackageInfo? {
val hostPackageInfo = hostPackageManager.getPackageInfo(packageName, flags)
return if (packageName.isPlugin()) {
val packageInfo = hostPackageManager.getPackageArchiveInfo(pluginArchiveFilePath, flags)
if (packageInfo != null) {
packageInfo.applicationInfo = getPluginApplicationInfo(flags)
packageInfo.permissions = hostPackageInfo.permissions
packageInfo.requestedPermissions = hostPackageInfo.requestedPermissions
}
packageInfo
getPluginPackageInfo(flags, hostPackageInfo)
} else {
hostPackageInfo
}
}

private fun getPluginPackageInfo(flags: Int, hostPackageInfo: PackageInfo): PackageInfo? {
return hostPackageManager.getPackageArchiveInfo(pluginArchiveFilePath, flags)?.apply {
applicationInfo = getPluginApplicationInfo(flags)
permissions = hostPackageInfo.permissions
requestedPermissions = hostPackageInfo.requestedPermissions
}
}

@TargetApi(Build.VERSION_CODES.TIRAMISU)
override fun getPackageInfo(
packageName: String,
flags: PackageManager.PackageInfoFlags
): PackageInfo? {
val hostPackageInfo = hostPackageManager.getPackageInfo(packageName, flags)
return if (packageName.isPlugin()) {
getPluginPackageInfo(flags.value.toInt(), hostPackageInfo)
} else {
hostPackageInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public static PackageInfo getPackageInfo(ClassLoader classLoaderOfInvokeCode, Ve
return getPluginPackageManager(classLoaderOfInvokeCode).getPackageInfo(versionedPackage.getPackageName(), flags);
}

@TargetApi(Build.VERSION_CODES.TIRAMISU)
public static PackageInfo getPackageInfo(ClassLoader classLoaderOfInvokeCode, VersionedPackage versionedPackage,
PackageManager.PackageInfoFlags flags) throws PackageManager.NameNotFoundException {
return getPluginPackageManager(classLoaderOfInvokeCode).getPackageInfo(versionedPackage.getPackageName(), flags);
}

public static ProviderInfo resolveContentProvider(ClassLoader classLoaderOfInvokeCode, String name, int flags) {
return getPluginPackageManager(classLoaderOfInvokeCode).resolveContentProvider(name, flags);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.tencent.shadow.core.runtime;

import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Build;

import java.util.List;

Expand All @@ -22,6 +25,9 @@ public interface PluginPackageManager {

PackageInfo getPackageInfo(String packageName, int flags);

@TargetApi(Build.VERSION_CODES.TIRAMISU)
PackageInfo getPackageInfo(String packageName, PackageManager.PackageInfoFlags flags);

ProviderInfo resolveContentProvider(String name, int flags);

List<ProviderInfo> queryContentProviders(String processName, int uid, int flags);
Expand Down

0 comments on commit eff207e

Please sign in to comment.