Merge "Unbreak testStartUsingNetworkFeature_enableHipri failure" am: 0b3d643758 am: d53c48616f

Change-Id: I10d2abef918f0f8c6a4fad2297cc4517e10c7d29
This commit is contained in:
Mark Chien
2020-03-27 15:59:05 +00:00
committed by Automerger Merge Worker

View File

@@ -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;
@@ -5396,12 +5397,25 @@ 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()) {
throw new SecurityException("Insufficient permissions to specify legacy type");
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)