Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c981adb authored by paulhu's avatar paulhu
Browse files

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
parent 435d5803
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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;