From 9835a4eae0e37be4e11a8bb9b18286879f58d37c Mon Sep 17 00:00:00 2001 From: chiachangwang Date: Mon, 31 Jul 2023 14:01:24 +0000 Subject: [PATCH] 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 --- .../net/module/util/DeviceConfigUtils.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java b/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java index 138c1e5419..e5c5d0d587 100644 --- a/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java +++ b/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java @@ -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;