Replace PackageManager @hide APIs

ConnectivityService is using
PackageManager#getApplicationInfoAsUser() to get application
info but this API is not able to call after CS becomes a
mainline module. Thus, replace it with formal API.

Bug: 170593746
Test: atest FrameworksNetTests
Test: atest CtsNetTestCasesLegacyApi22
Change-Id: Idd1269aa50e234801583097bb6f40b099bab8fba
This commit is contained in:
paulhu
2020-12-10 23:32:32 +08:00
parent 0da448710c
commit 667972157f

View File

@@ -5566,11 +5566,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
private boolean checkUnsupportedStartingFrom(int version, String callingPackageName) {
final PackageManager pm = mContext.getPackageManager();
final int userId = UserHandle.getCallingUserId();
final UserHandle user = UserHandle.getUserHandleForUid(Binder.getCallingUid());
final PackageManager pm =
mContext.createContextAsUser(user, 0 /* flags */).getPackageManager();
try {
final int callingVersion = pm.getApplicationInfoAsUser(
callingPackageName, 0 /* flags */, userId).targetSdkVersion;
final int callingVersion = pm.getApplicationInfo(
callingPackageName, 0 /* flags */).targetSdkVersion;
if (callingVersion < version) return false;
} catch (PackageManager.NameNotFoundException e) { }
return true;