Update checkLocationPermissionInternal not to throw
Currently, checkLocationPermissionInternal throws if the package does not exist or package name and uid doest not match. This caused system server crash in ConnectivityService. ConnectivityService is an only caller of checkLocationPermissionInternal and ConnectivityService should consider uid does not have location permission in this case. So this CL updates checkLocationPermissionInternal return ERROR_LOCATION_PERMISSION_MISSING instead of throwing exception. Bug: 337473824 Test: LocationPermissionCheckerTest Change-Id: Ic42d6203bafa95aea7e5428c490b0a298e3bd260
This commit is contained in:
parent
3625bf6fae
commit
d55bdd26e2
2 changed files with 8 additions and 16 deletions
|
|
@ -117,7 +117,11 @@ public class LocationPermissionChecker {
|
|||
@VisibleForTesting(visibility = PRIVATE)
|
||||
public @LocationPermissionCheckStatus int checkLocationPermissionInternal(
|
||||
String pkgName, @Nullable String featureId, int uid, @Nullable String message) {
|
||||
checkPackage(uid, pkgName);
|
||||
try {
|
||||
checkPackage(uid, pkgName);
|
||||
} catch (SecurityException e) {
|
||||
return ERROR_LOCATION_PERMISSION_MISSING;
|
||||
}
|
||||
|
||||
// Apps with NETWORK_SETTINGS, NETWORK_SETUP_WIZARD, NETWORK_STACK & MAINLINE_NETWORK_STACK
|
||||
// are granted a bypass.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package com.android.net.module.util;
|
|||
import static android.Manifest.permission.NETWORK_SETTINGS;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
|
@ -47,7 +46,6 @@ import androidx.annotation.RequiresApi;
|
|||
|
||||
import com.android.testutils.DevSdkIgnoreRule;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -242,9 +240,9 @@ public class LocationPermissionCheckerTest {
|
|||
mWifiScanAllowApps = AppOpsManager.MODE_ALLOWED;
|
||||
setupTestCase();
|
||||
|
||||
assertThrows(SecurityException.class,
|
||||
() -> mChecker.checkLocationPermissionInternal(
|
||||
TEST_PKG_NAME, TEST_FEATURE_ID, mUid, null));
|
||||
final int result = mChecker.checkLocationPermissionInternal(
|
||||
TEST_PKG_NAME, TEST_FEATURE_ID, mUid, null);
|
||||
assertEquals(LocationPermissionChecker.ERROR_LOCATION_PERMISSION_MISSING, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -305,14 +303,4 @@ public class LocationPermissionCheckerTest {
|
|||
TEST_PKG_NAME, TEST_FEATURE_ID, mUid, null);
|
||||
assertEquals(LocationPermissionChecker.SUCCEEDED, result);
|
||||
}
|
||||
|
||||
|
||||
private static void assertThrows(Class<? extends Exception> exceptionClass, Runnable r) {
|
||||
try {
|
||||
r.run();
|
||||
Assert.fail("Expected " + exceptionClass + " to be thrown.");
|
||||
} catch (Exception exception) {
|
||||
assertTrue(exceptionClass.isInstance(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue