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

Commit c1307318 authored by markchien's avatar markchien Committed by Mark Chien
Browse files

Unbreak testStartUsingNetworkFeature_enableHipri failure

aosp/1261619 break legacy API that only supported for SDK which is
smaller than android M, caller need to have network stack permission
to request network with legacy type. Fix failure by whitelist permission
check for the caller who built with oder SDK(< M).

Bug: 152229492
Test: atest CtsTetheringTest
      atest ConnectivityManagerLegacyTest# \
      testStartUsingNetworkFeature_enableHipri

Change-Id: I367dff0429f26f266282300edc38637b55eece38
parent 7f26443f
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.net.CaptivePortal;
@@ -5388,13 +5389,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
    }

    private boolean checkUnsupportedStartingFrom(int version, String callingPackageName) {
        final PackageManager pm = mContext.getPackageManager();
        final int userId = UserHandle.getCallingUserId();
        try {
            final int callingVersion = pm.getApplicationInfoAsUser(
                    callingPackageName, 0 /* flags */, userId).targetSdkVersion;
            if (callingVersion < version) return false;
        } catch (PackageManager.NameNotFoundException e) { }
        return true;
    }

    @Override
    public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
            Messenger messenger, int timeoutMs, IBinder binder, int legacyType,
            @NonNull String callingPackageName) {
        if (legacyType != TYPE_NONE && !checkNetworkStackPermission()) {
            if (checkUnsupportedStartingFrom(Build.VERSION_CODES.M, callingPackageName)) {
                throw new SecurityException("Insufficient permissions to specify legacy type");
            }
        }
        final int callingUid = Binder.getCallingUid();
        final NetworkRequest.Type type = (networkCapabilities == null)
                ? NetworkRequest.Type.TRACK_DEFAULT