Trigger re-evaluation of privileged apps upon app install/uninstall

This change registers listeners for package installs and uninstalls,
ensuring that changes to app install statuses are reflected in the VCN

Bug: 183465258
Test: atest FrameworksVcnTests
Change-Id: I8d2afd351208cac12392bf945439845cc521b7ec
This commit is contained in:
Benedict Wong
2021-03-22 20:07:58 -07:00
parent d68c1f6cb2
commit 62f01dfbd5
2 changed files with 72 additions and 0 deletions

View File

@@ -49,7 +49,9 @@ import static org.mockito.Mockito.when;
import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
@@ -336,6 +338,13 @@ public class VcnManagementServiceTest {
return captor.getValue();
}
private BroadcastReceiver getPackageChangeReceiver() {
final ArgumentCaptor<BroadcastReceiver> captor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
verify(mMockContext).registerReceiver(captor.capture(), any(), any(), any());
return captor.getValue();
}
private Vcn startAndGetVcnInstance(ParcelUuid uuid) {
mVcnMgmtSvc.setVcnConfig(uuid, TEST_VCN_CONFIG, TEST_PACKAGE_NAME);
return mVcnMgmtSvc.getAllVcns().get(uuid);
@@ -411,6 +420,42 @@ public class VcnManagementServiceTest {
verify(newInstance, never()).teardownAsynchronously();
}
@Test
public void testPackageChangeListenerRegistered() throws Exception {
verify(mMockContext).registerReceiver(any(BroadcastReceiver.class), argThat(filter -> {
return filter.hasAction(Intent.ACTION_PACKAGE_ADDED)
&& filter.hasAction(Intent.ACTION_PACKAGE_REPLACED)
&& filter.hasAction(Intent.ACTION_PACKAGE_REMOVED);
}), any(), any());
}
@Test
public void testPackageChangeListener_packageAdded() throws Exception {
final BroadcastReceiver receiver = getPackageChangeReceiver();
verify(mMockContext).registerReceiver(any(), argThat(filter -> {
return filter.hasAction(Intent.ACTION_PACKAGE_ADDED)
&& filter.hasAction(Intent.ACTION_PACKAGE_REPLACED)
&& filter.hasAction(Intent.ACTION_PACKAGE_REMOVED);
}), any(), any());
receiver.onReceive(mMockContext, new Intent(Intent.ACTION_PACKAGE_ADDED));
verify(mSubscriptionTracker).handleSubscriptionsChanged();
}
@Test
public void testPackageChangeListener_packageRemoved() throws Exception {
final BroadcastReceiver receiver = getPackageChangeReceiver();
verify(mMockContext).registerReceiver(any(), argThat(filter -> {
return filter.hasAction(Intent.ACTION_PACKAGE_REMOVED)
&& filter.hasAction(Intent.ACTION_PACKAGE_REMOVED);
}), any(), any());
receiver.onReceive(mMockContext, new Intent(Intent.ACTION_PACKAGE_REMOVED));
verify(mSubscriptionTracker).handleSubscriptionsChanged();
}
@Test
public void testSetVcnConfigRequiresNonSystemServer() throws Exception {
doReturn(Process.SYSTEM_UID).when(mMockDeps).getBinderCallingUid();