Skip sending VpnManager events for Settings VPNs

This change early-exits from the sendEventToVpnManagerApp()
method if the profile was not a VPN app.

Otherwise the sendEventToVpnManagerApp() will call
getRedactedNetworkCapabilities() which will call
AppOpsManager#checkPackage() eventually.
And AppOpsManager#checkPackage() will check if the given package
is the same as the given uid. In this case, VPN sends
"[Legacy VPN]" as the package and sends 1000 as the uid, but
there is no package named "[Legacy VPN], so the SecurityException
is thrown.

Bug: 236315805
Test: atest FrameworksNetTests:VpnTest
Change-Id: I486398111106b1a9551fb29f92ba7b4fe85f68c1
Merged-In: I228f62a5e09017dbf985a614f2e42434238a220c
This commit is contained in:
lucaslin
2022-07-25 15:07:52 +08:00
committed by Lucas Lin
parent 326af90470
commit 3912b21cbf

View File

@@ -3281,7 +3281,7 @@ public class Vpn {
// All the above failures are configuration errors, and are terminal // All the above failures are configuration errors, and are terminal
// TODO(b/230548427): Remove SDK check once VPN related stuff are // TODO(b/230548427): Remove SDK check once VPN related stuff are
// decoupled from ConnectivityServiceTest. // decoupled from ConnectivityServiceTest.
if (SdkLevel.isAtLeastT()) { if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_IKE_ERROR, sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_IKE_ERROR,
VpnManager.ERROR_CLASS_NOT_RECOVERABLE, VpnManager.ERROR_CLASS_NOT_RECOVERABLE,
ikeException.getErrorType(), ikeException.getErrorType(),
@@ -3299,7 +3299,7 @@ public class Vpn {
// All the above failures are configuration errors, and are terminal // All the above failures are configuration errors, and are terminal
// TODO(b/230548427): Remove SDK check once VPN related stuff are // TODO(b/230548427): Remove SDK check once VPN related stuff are
// decoupled from ConnectivityServiceTest. // decoupled from ConnectivityServiceTest.
if (SdkLevel.isAtLeastT()) { if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_IKE_ERROR, sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_IKE_ERROR,
VpnManager.ERROR_CLASS_RECOVERABLE, VpnManager.ERROR_CLASS_RECOVERABLE,
ikeException.getErrorType(), ikeException.getErrorType(),
@@ -3318,7 +3318,7 @@ public class Vpn {
} else if (exception instanceof IkeNetworkLostException) { } else if (exception instanceof IkeNetworkLostException) {
// TODO(b/230548427): Remove SDK check once VPN related stuff are // TODO(b/230548427): Remove SDK check once VPN related stuff are
// decoupled from ConnectivityServiceTest. // decoupled from ConnectivityServiceTest.
if (SdkLevel.isAtLeastT()) { if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
VpnManager.ERROR_CLASS_RECOVERABLE, VpnManager.ERROR_CLASS_RECOVERABLE,
VpnManager.ERROR_CODE_NETWORK_LOST, VpnManager.ERROR_CODE_NETWORK_LOST,
@@ -3333,7 +3333,7 @@ public class Vpn {
if (exception.getCause() instanceof UnknownHostException) { if (exception.getCause() instanceof UnknownHostException) {
// TODO(b/230548427): Remove SDK check once VPN related stuff are // TODO(b/230548427): Remove SDK check once VPN related stuff are
// decoupled from ConnectivityServiceTest. // decoupled from ConnectivityServiceTest.
if (SdkLevel.isAtLeastT()) { if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
VpnManager.ERROR_CLASS_RECOVERABLE, VpnManager.ERROR_CLASS_RECOVERABLE,
VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST, VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST,
@@ -3347,7 +3347,7 @@ public class Vpn {
} else if (exception.getCause() instanceof IkeTimeoutException) { } else if (exception.getCause() instanceof IkeTimeoutException) {
// TODO(b/230548427): Remove SDK check once VPN related stuff are // TODO(b/230548427): Remove SDK check once VPN related stuff are
// decoupled from ConnectivityServiceTest. // decoupled from ConnectivityServiceTest.
if (SdkLevel.isAtLeastT()) { if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
VpnManager.ERROR_CLASS_RECOVERABLE, VpnManager.ERROR_CLASS_RECOVERABLE,
VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT, VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT,
@@ -3361,7 +3361,7 @@ public class Vpn {
} else if (exception.getCause() instanceof IOException) { } else if (exception.getCause() instanceof IOException) {
// TODO(b/230548427): Remove SDK check once VPN related stuff are // TODO(b/230548427): Remove SDK check once VPN related stuff are
// decoupled from ConnectivityServiceTest. // decoupled from ConnectivityServiceTest.
if (SdkLevel.isAtLeastT()) { if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) {
sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
VpnManager.ERROR_CLASS_RECOVERABLE, VpnManager.ERROR_CLASS_RECOVERABLE,
VpnManager.ERROR_CODE_NETWORK_IO, VpnManager.ERROR_CODE_NETWORK_IO,