Merge "Remove automotive restriction from enable/disableInterface" am: 345655f7bc am: 1d0e33db3a

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2103746

Change-Id: Iaa4e13f6babe0074c7123c6a8728102b9d29b8a3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Patrick Rohr
2022-05-25 02:51:26 +00:00
committed by Automerger Merge Worker
6 changed files with 48 additions and 69 deletions

View File

@@ -22,13 +22,11 @@ import android.annotation.CallbackExecutor;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission; import android.annotation.RequiresPermission;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.SystemService; import android.annotation.SystemService;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.OutcomeReceiver; import android.os.OutcomeReceiver;
import android.os.RemoteException; import android.os.RemoteException;
@@ -573,7 +571,6 @@ public class EthernetManager {
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_STACK,
android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}) android.Manifest.permission.MANAGE_ETHERNET_NETWORKS})
@RequiresFeature(PackageManager.FEATURE_AUTOMOTIVE)
public void enableInterface( public void enableInterface(
@NonNull String iface, @NonNull String iface,
@Nullable @CallbackExecutor Executor executor, @Nullable @CallbackExecutor Executor executor,
@@ -582,7 +579,7 @@ public class EthernetManager {
final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver( final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver(
executor, callback); executor, callback);
try { try {
mService.connectNetwork(iface, proxy); mService.enableInterface(iface, proxy);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -610,7 +607,6 @@ public class EthernetManager {
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_STACK,
android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}) android.Manifest.permission.MANAGE_ETHERNET_NETWORKS})
@RequiresFeature(PackageManager.FEATURE_AUTOMOTIVE)
public void disableInterface( public void disableInterface(
@NonNull String iface, @NonNull String iface,
@Nullable @CallbackExecutor Executor executor, @Nullable @CallbackExecutor Executor executor,
@@ -619,7 +615,7 @@ public class EthernetManager {
final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver( final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver(
executor, callback); executor, callback);
try { try {
mService.disconnectNetwork(iface, proxy); mService.disableInterface(iface, proxy);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }

View File

@@ -43,8 +43,8 @@ interface IEthernetManager
void releaseTetheredInterface(in ITetheredInterfaceCallback callback); void releaseTetheredInterface(in ITetheredInterfaceCallback callback);
void updateConfiguration(String iface, in EthernetNetworkUpdateRequest request, void updateConfiguration(String iface, in EthernetNetworkUpdateRequest request,
in INetworkInterfaceOutcomeReceiver listener); in INetworkInterfaceOutcomeReceiver listener);
void connectNetwork(String iface, in INetworkInterfaceOutcomeReceiver listener); void enableInterface(String iface, in INetworkInterfaceOutcomeReceiver listener);
void disconnectNetwork(String iface, in INetworkInterfaceOutcomeReceiver listener); void disableInterface(String iface, in INetworkInterfaceOutcomeReceiver listener);
void setEthernetEnabled(boolean enabled); void setEthernetEnabled(boolean enabled);
List<String> getInterfaceList(); List<String> getInterfaceList();
} }

View File

@@ -22,11 +22,11 @@ import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.EthernetNetworkUpdateRequest;
import android.net.IEthernetManager; import android.net.IEthernetManager;
import android.net.IEthernetServiceListener; import android.net.IEthernetServiceListener;
import android.net.INetworkInterfaceOutcomeReceiver; import android.net.INetworkInterfaceOutcomeReceiver;
import android.net.ITetheredInterfaceCallback; import android.net.ITetheredInterfaceCallback;
import android.net.EthernetNetworkUpdateRequest;
import android.net.IpConfiguration; import android.net.IpConfiguration;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.os.Binder; import android.os.Binder;
@@ -260,27 +260,27 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
} }
@Override @Override
public void connectNetwork(@NonNull final String iface, public void enableInterface(@NonNull final String iface,
@Nullable final INetworkInterfaceOutcomeReceiver listener) { @Nullable final INetworkInterfaceOutcomeReceiver listener) {
Log.i(TAG, "connectNetwork called with: iface=" + iface + ", listener=" + listener); Log.i(TAG, "enableInterface called with: iface=" + iface + ", listener=" + listener);
Objects.requireNonNull(iface); Objects.requireNonNull(iface);
throwIfEthernetNotStarted(); throwIfEthernetNotStarted();
enforceAdminPermission(iface, true, "connectNetwork()"); enforceAdminPermission(iface, false, "enableInterface()");
mTracker.connectNetwork(iface, listener); mTracker.enableInterface(iface, listener);
} }
@Override @Override
public void disconnectNetwork(@NonNull final String iface, public void disableInterface(@NonNull final String iface,
@Nullable final INetworkInterfaceOutcomeReceiver listener) { @Nullable final INetworkInterfaceOutcomeReceiver listener) {
Log.i(TAG, "disconnectNetwork called with: iface=" + iface + ", listener=" + listener); Log.i(TAG, "disableInterface called with: iface=" + iface + ", listener=" + listener);
Objects.requireNonNull(iface); Objects.requireNonNull(iface);
throwIfEthernetNotStarted(); throwIfEthernetNotStarted();
enforceAdminPermission(iface, true, "connectNetwork()"); enforceAdminPermission(iface, false, "disableInterface()");
mTracker.disconnectNetwork(iface, listener); mTracker.disableInterface(iface, listener);
} }
@Override @Override

View File

@@ -286,13 +286,13 @@ public class EthernetTracker {
} }
@VisibleForTesting(visibility = PACKAGE) @VisibleForTesting(visibility = PACKAGE)
protected void connectNetwork(@NonNull final String iface, protected void enableInterface(@NonNull final String iface,
@Nullable final INetworkInterfaceOutcomeReceiver listener) { @Nullable final INetworkInterfaceOutcomeReceiver listener) {
mHandler.post(() -> updateInterfaceState(iface, true, listener)); mHandler.post(() -> updateInterfaceState(iface, true, listener));
} }
@VisibleForTesting(visibility = PACKAGE) @VisibleForTesting(visibility = PACKAGE)
protected void disconnectNetwork(@NonNull final String iface, protected void disableInterface(@NonNull final String iface,
@Nullable final INetworkInterfaceOutcomeReceiver listener) { @Nullable final INetworkInterfaceOutcomeReceiver listener) {
mHandler.post(() -> updateInterfaceState(iface, false, listener)); mHandler.post(() -> updateInterfaceState(iface, false, listener));
} }

View File

@@ -20,7 +20,6 @@ import static android.net.NetworkCapabilities.TRANSPORT_TEST;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.isNull;
@@ -35,8 +34,8 @@ import android.Manifest;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.INetworkInterfaceOutcomeReceiver;
import android.net.EthernetNetworkUpdateRequest; import android.net.EthernetNetworkUpdateRequest;
import android.net.INetworkInterfaceOutcomeReceiver;
import android.net.IpConfiguration; import android.net.IpConfiguration;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.os.Handler; import android.os.Handler;
@@ -111,18 +110,18 @@ public class EthernetServiceImplTest {
} }
@Test @Test
public void testConnectNetworkRejectsWhenEthNotStarted() { public void testEnableInterfaceRejectsWhenEthNotStarted() {
mEthernetServiceImpl.mStarted.set(false); mEthernetServiceImpl.mStarted.set(false);
assertThrows(IllegalStateException.class, () -> { assertThrows(IllegalStateException.class, () -> {
mEthernetServiceImpl.connectNetwork("" /* iface */, null /* listener */); mEthernetServiceImpl.enableInterface("" /* iface */, null /* listener */);
}); });
} }
@Test @Test
public void testDisconnectNetworkRejectsWhenEthNotStarted() { public void testDisableInterfaceRejectsWhenEthNotStarted() {
mEthernetServiceImpl.mStarted.set(false); mEthernetServiceImpl.mStarted.set(false);
assertThrows(IllegalStateException.class, () -> { assertThrows(IllegalStateException.class, () -> {
mEthernetServiceImpl.disconnectNetwork("" /* iface */, null /* listener */); mEthernetServiceImpl.disableInterface("" /* iface */, null /* listener */);
}); });
} }
@@ -134,16 +133,16 @@ public class EthernetServiceImplTest {
} }
@Test @Test
public void testConnectNetworkRejectsNullIface() { public void testEnableInterfaceRejectsNullIface() {
assertThrows(NullPointerException.class, () -> { assertThrows(NullPointerException.class, () -> {
mEthernetServiceImpl.connectNetwork(null /* iface */, NULL_LISTENER); mEthernetServiceImpl.enableInterface(null /* iface */, NULL_LISTENER);
}); });
} }
@Test @Test
public void testDisconnectNetworkRejectsNullIface() { public void testDisableInterfaceRejectsNullIface() {
assertThrows(NullPointerException.class, () -> { assertThrows(NullPointerException.class, () -> {
mEthernetServiceImpl.disconnectNetwork(null /* iface */, NULL_LISTENER); mEthernetServiceImpl.disableInterface(null /* iface */, NULL_LISTENER);
}); });
} }
@@ -165,22 +164,6 @@ public class EthernetServiceImplTest {
eq(UPDATE_REQUEST_WITHOUT_CAPABILITIES.getNetworkCapabilities()), isNull()); eq(UPDATE_REQUEST_WITHOUT_CAPABILITIES.getNetworkCapabilities()), isNull());
} }
@Test
public void testConnectNetworkRejectsWithoutAutomotiveFeature() {
toggleAutomotiveFeature(false);
assertThrows(UnsupportedOperationException.class, () -> {
mEthernetServiceImpl.connectNetwork("" /* iface */, NULL_LISTENER);
});
}
@Test
public void testDisconnectNetworkRejectsWithoutAutomotiveFeature() {
toggleAutomotiveFeature(false);
assertThrows(UnsupportedOperationException.class, () -> {
mEthernetServiceImpl.disconnectNetwork("" /* iface */, NULL_LISTENER);
});
}
private void denyManageEthPermission() { private void denyManageEthPermission() {
doThrow(new SecurityException("")).when(mContext) doThrow(new SecurityException("")).when(mContext)
.enforceCallingOrSelfPermission( .enforceCallingOrSelfPermission(
@@ -202,18 +185,18 @@ public class EthernetServiceImplTest {
} }
@Test @Test
public void testConnectNetworkRejectsWithoutManageEthPermission() { public void testEnableInterfaceRejectsWithoutManageEthPermission() {
denyManageEthPermission(); denyManageEthPermission();
assertThrows(SecurityException.class, () -> { assertThrows(SecurityException.class, () -> {
mEthernetServiceImpl.connectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.enableInterface(TEST_IFACE, NULL_LISTENER);
}); });
} }
@Test @Test
public void testDisconnectNetworkRejectsWithoutManageEthPermission() { public void testDisableInterfaceRejectsWithoutManageEthPermission() {
denyManageEthPermission(); denyManageEthPermission();
assertThrows(SecurityException.class, () -> { assertThrows(SecurityException.class, () -> {
mEthernetServiceImpl.disconnectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.disableInterface(TEST_IFACE, NULL_LISTENER);
}); });
} }
@@ -231,20 +214,20 @@ public class EthernetServiceImplTest {
} }
@Test @Test
public void testConnectNetworkRejectsTestRequestWithoutTestPermission() { public void testEnableInterfaceRejectsTestRequestWithoutTestPermission() {
enableTestInterface(); enableTestInterface();
denyManageTestNetworksPermission(); denyManageTestNetworksPermission();
assertThrows(SecurityException.class, () -> { assertThrows(SecurityException.class, () -> {
mEthernetServiceImpl.connectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.enableInterface(TEST_IFACE, NULL_LISTENER);
}); });
} }
@Test @Test
public void testDisconnectNetworkRejectsTestRequestWithoutTestPermission() { public void testDisableInterfaceRejectsTestRequestWithoutTestPermission() {
enableTestInterface(); enableTestInterface();
denyManageTestNetworksPermission(); denyManageTestNetworksPermission();
assertThrows(SecurityException.class, () -> { assertThrows(SecurityException.class, () -> {
mEthernetServiceImpl.disconnectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.disableInterface(TEST_IFACE, NULL_LISTENER);
}); });
} }
@@ -258,15 +241,15 @@ public class EthernetServiceImplTest {
} }
@Test @Test
public void testConnectNetwork() { public void testEnableInterface() {
mEthernetServiceImpl.connectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.enableInterface(TEST_IFACE, NULL_LISTENER);
verify(mEthernetTracker).connectNetwork(eq(TEST_IFACE), eq(NULL_LISTENER)); verify(mEthernetTracker).enableInterface(eq(TEST_IFACE), eq(NULL_LISTENER));
} }
@Test @Test
public void testDisconnectNetwork() { public void testDisableInterface() {
mEthernetServiceImpl.disconnectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.disableInterface(TEST_IFACE, NULL_LISTENER);
verify(mEthernetTracker).disconnectNetwork(eq(TEST_IFACE), eq(NULL_LISTENER)); verify(mEthernetTracker).disableInterface(eq(TEST_IFACE), eq(NULL_LISTENER));
} }
@Test @Test
@@ -324,23 +307,23 @@ public class EthernetServiceImplTest {
} }
@Test @Test
public void testConnectNetworkForTestRequestDoesNotRequireAutoOrNetPermission() { public void testEnableInterfaceForTestRequestDoesNotRequireNetPermission() {
enableTestInterface(); enableTestInterface();
toggleAutomotiveFeature(false); toggleAutomotiveFeature(false);
denyManageEthPermission(); denyManageEthPermission();
mEthernetServiceImpl.connectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.enableInterface(TEST_IFACE, NULL_LISTENER);
verify(mEthernetTracker).connectNetwork(eq(TEST_IFACE), eq(NULL_LISTENER)); verify(mEthernetTracker).enableInterface(eq(TEST_IFACE), eq(NULL_LISTENER));
} }
@Test @Test
public void testDisconnectNetworkForTestRequestDoesNotRequireAutoOrNetPermission() { public void testDisableInterfaceForTestRequestDoesNotRequireAutoOrNetPermission() {
enableTestInterface(); enableTestInterface();
toggleAutomotiveFeature(false); toggleAutomotiveFeature(false);
denyManageEthPermission(); denyManageEthPermission();
mEthernetServiceImpl.disconnectNetwork(TEST_IFACE, NULL_LISTENER); mEthernetServiceImpl.disableInterface(TEST_IFACE, NULL_LISTENER);
verify(mEthernetTracker).disconnectNetwork(eq(TEST_IFACE), eq(NULL_LISTENER)); verify(mEthernetTracker).disableInterface(eq(TEST_IFACE), eq(NULL_LISTENER));
} }
private void denyPermissions(String... permissions) { private void denyPermissions(String... permissions) {

View File

@@ -352,8 +352,8 @@ public class EthernetTrackerTest {
} }
@Test @Test
public void testConnectNetworkCorrectlyCallsFactory() { public void testEnableInterfaceCorrectlyCallsFactory() {
tracker.connectNetwork(TEST_IFACE, NULL_LISTENER); tracker.enableInterface(TEST_IFACE, NULL_LISTENER);
waitForIdle(); waitForIdle();
verify(mFactory).updateInterfaceLinkState(eq(TEST_IFACE), eq(true /* up */), verify(mFactory).updateInterfaceLinkState(eq(TEST_IFACE), eq(true /* up */),
@@ -361,8 +361,8 @@ public class EthernetTrackerTest {
} }
@Test @Test
public void testDisconnectNetworkCorrectlyCallsFactory() { public void testDisableInterfaceCorrectlyCallsFactory() {
tracker.disconnectNetwork(TEST_IFACE, NULL_LISTENER); tracker.disableInterface(TEST_IFACE, NULL_LISTENER);
waitForIdle(); waitForIdle();
verify(mFactory).updateInterfaceLinkState(eq(TEST_IFACE), eq(false /* up */), verify(mFactory).updateInterfaceLinkState(eq(TEST_IFACE), eq(false /* up */),