Add resolvePkgPrefix() method

This is a no-op refactor change to create resolvePkgPrefix()
helper method to prevent code duplication for the follow up
commit.

Bug: 291870956
Test: atest NetworkStaticLibTests
Change-Id: I8deea97acdb793dfa076ce55f7f2c3eb0b224461
This commit is contained in:
chiachangwang
2023-07-31 14:01:24 +00:00
parent 3416eae310
commit 9835a4eae0

View File

@@ -224,14 +224,7 @@ public final class DeviceConfigUtils {
// If that fails retry by appending "go.tethering" instead
private static long resolveTetheringModuleVersion(@NonNull Context context)
throws PackageManager.NameNotFoundException {
final String connResourcesPackage = getConnectivityResourcesPackageName(context);
final int pkgPrefixLen = connResourcesPackage.indexOf("connectivity");
if (pkgPrefixLen < 0) {
throw new IllegalStateException(
"Invalid connectivity resources package: " + connResourcesPackage);
}
final String pkgPrefix = connResourcesPackage.substring(0, pkgPrefixLen);
final String pkgPrefix = resolvePkgPrefix(context);
final PackageManager packageManager = context.getPackageManager();
try {
return packageManager.getPackageInfo(pkgPrefix + "tethering",
@@ -245,6 +238,17 @@ public final class DeviceConfigUtils {
PackageManager.MATCH_APEX).getLongVersionCode();
}
private static String resolvePkgPrefix(Context context) {
final String connResourcesPackage = getConnectivityResourcesPackageName(context);
final int pkgPrefixLen = connResourcesPackage.indexOf("connectivity");
if (pkgPrefixLen < 0) {
throw new IllegalStateException(
"Invalid connectivity resources package: " + connResourcesPackage);
}
return connResourcesPackage.substring(0, pkgPrefixLen);
}
private static volatile long sModuleVersion = -1;
private static long getTetheringModuleVersion(@NonNull Context context) {
if (sModuleVersion >= 0) return sModuleVersion;