Move user intent reception out of SatelliteAccessController
This is a no-op refactoring that moves the reception of user-related intents in SatelliteAccessController to ConnectivityService. It then dispatches these events to the SatelliteAccessController. Flag: EXEMPT refactor Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \ ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest Bug: 410731080 Change-Id: I9ace3ed09a161446dc92d40bc0d400e32051de32
This commit is contained in:
parent
8b1fe1976b
commit
b14633ea2f
4 changed files with 24 additions and 56 deletions
|
|
@ -7731,6 +7731,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
handleSetOemNetworkPreference(mOemNetworkPreferences, null);
|
||||
}
|
||||
mPermissionMonitor.onUserRemoved(user);
|
||||
if (mSatelliteAccessController != null) {
|
||||
mSatelliteAccessController.onUserRemoved(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -87,8 +87,6 @@ import java.util.Set;
|
|||
/**
|
||||
* A utility class to inform Netd of UID permissions.
|
||||
* Does a mass update at boot and then monitors for app install/remove.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class PermissionMonitor {
|
||||
private static final String TAG = "PermissionMonitor";
|
||||
|
|
@ -553,9 +551,7 @@ public class PermissionMonitor {
|
|||
/**
|
||||
* Called when a user is added. See {link #ACTION_USER_ADDED}.
|
||||
*
|
||||
* @param user The integer userHandle of the added user. See {@link #EXTRA_USER_HANDLE}.
|
||||
*
|
||||
* @hide
|
||||
* @param user The userHandle of the added user. See {@link #EXTRA_USER_HANDLE}.
|
||||
*/
|
||||
public synchronized void onUserAdded(@NonNull UserHandle user) {
|
||||
ensureRunningOnHandlerThread();
|
||||
|
|
@ -585,9 +581,7 @@ public class PermissionMonitor {
|
|||
/**
|
||||
* Called when an user is removed. See {link #ACTION_USER_REMOVED}.
|
||||
*
|
||||
* @param user The integer userHandle of the removed user. See {@link #EXTRA_USER_HANDLE}.
|
||||
*
|
||||
* @hide
|
||||
* @param user The userHandle of the removed user. See {@link #EXTRA_USER_HANDLE}.
|
||||
*/
|
||||
public synchronized void onUserRemoved(@NonNull UserHandle user) {
|
||||
ensureRunningOnHandlerThread();
|
||||
|
|
@ -772,8 +766,6 @@ public class PermissionMonitor {
|
|||
*
|
||||
* @param packageName The name of the new package.
|
||||
* @param uid The uid of the new package.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public synchronized void onPackageAdded(@NonNull final String packageName, final int uid) {
|
||||
ensureRunningOnHandlerThread();
|
||||
|
|
@ -837,8 +829,6 @@ public class PermissionMonitor {
|
|||
*
|
||||
* @param packageName The name of the removed package or null.
|
||||
* @param uid containing the integer uid previously assigned to the package.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public synchronized void onPackageRemoved(@NonNull final String packageName, final int uid) {
|
||||
ensureRunningOnHandlerThread();
|
||||
|
|
@ -1117,8 +1107,6 @@ public class PermissionMonitor {
|
|||
*
|
||||
* @param appId the appId of the package installed
|
||||
* @param permissions the permissions the app requested and netd cares about.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void sendPackagePermissionsForAppId(int appId, int permissions) {
|
||||
|
|
@ -1136,8 +1124,6 @@ public class PermissionMonitor {
|
|||
*
|
||||
* @param netdPermissionsAppIds integer pairs of appIds and the permission granted to it. If the
|
||||
* permission is 0, revoke all permissions of that appId.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void sendAppIdsTrafficPermission(SparseIntArray netdPermissionsAppIds) {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@ import android.Manifest;
|
|||
import android.annotation.NonNull;
|
||||
import android.app.role.OnRoleHoldersChangedListener;
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Handler;
|
||||
|
|
@ -45,7 +42,6 @@ import java.util.function.Consumer;
|
|||
* Tracks the uid of all the default messaging application which are role_sms role and
|
||||
* satellite_communication permission complaint and requests ConnectivityService to create multi
|
||||
* layer request with satellite internet access support for the default message application.
|
||||
* @hide
|
||||
*/
|
||||
public class SatelliteAccessController {
|
||||
private static final String TAG = SatelliteAccessController.class.getSimpleName();
|
||||
|
|
@ -217,23 +213,6 @@ public class SatelliteAccessController {
|
|||
|
||||
// register sms OnRoleHoldersChangedListener
|
||||
mDefaultMessageRoleListener.register();
|
||||
|
||||
// Monitor for User removal intent, to update satellite fallback uids.
|
||||
IntentFilter userRemovedFilter = new IntentFilter(Intent.ACTION_USER_REMOVED);
|
||||
mContext.registerReceiver(new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
||||
final UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
|
||||
if (userHandle == null) return;
|
||||
updateSatelliteFallbackUidListOnUserRemoval(userHandle.getIdentifier());
|
||||
} else {
|
||||
Log.wtf(TAG, "received unexpected intent: " + action);
|
||||
}
|
||||
}
|
||||
}, userRemovedFilter, null, mConnectivityServiceHandler);
|
||||
|
||||
}
|
||||
|
||||
private void updateAllUserRoleSmsUids() {
|
||||
|
|
@ -249,6 +228,15 @@ public class SatelliteAccessController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a user is removed. See {link #ACTION_USER_REMOVED}.
|
||||
*
|
||||
* @param userHandle The userHandle of the removed user. See {@link #EXTRA_USER_HANDLE}.
|
||||
*/
|
||||
public void onUserRemoved(@NonNull UserHandle userHandle) {
|
||||
updateSatelliteFallbackUidListOnUserRemoval(userHandle.getIdentifier());
|
||||
}
|
||||
|
||||
private void updateSatelliteFallbackUidListOnUserRemoval(int userIdRemoved) {
|
||||
Log.i(TAG, "user id removed:" + userIdRemoved);
|
||||
if (mAllUsersSatelliteNetworkFallbackUidCache.contains(userIdRemoved)) {
|
||||
|
|
|
|||
|
|
@ -18,10 +18,7 @@ package com.android.server.connectivity
|
|||
import android.Manifest
|
||||
import android.app.role.OnRoleHoldersChangedListener
|
||||
import android.app.role.RoleManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
|
|
@ -32,6 +29,7 @@ import android.os.UserManager
|
|||
import android.util.ArraySet
|
||||
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
|
||||
import com.android.testutils.DevSdkIgnoreRunner
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.function.Consumer
|
||||
import org.junit.Before
|
||||
|
|
@ -41,7 +39,6 @@ import org.mockito.ArgumentCaptor
|
|||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
import org.mockito.ArgumentMatchers.isNull
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.never
|
||||
|
|
@ -87,7 +84,6 @@ class SatelliteAccessControllerTest {
|
|||
private var mSatelliteAccessController =
|
||||
SatelliteAccessController(context, mDeps, mCallback, mHandler)
|
||||
private lateinit var mRoleHolderChangedListener: OnRoleHoldersChangedListener
|
||||
private lateinit var mUserRemovedReceiver: BroadcastReceiver
|
||||
|
||||
private fun <T> mockService(name: String, clazz: Class<T>, service: T) {
|
||||
doReturn(name).`when`(context).getSystemServiceName(clazz)
|
||||
|
|
@ -290,13 +286,18 @@ class SatelliteAccessControllerTest {
|
|||
)
|
||||
mRoleHolderChangedListener.onRoleHoldersChanged(RoleManager.ROLE_SMS, SECONDARY_USER_HANDLE)
|
||||
verify(mCallback).accept(setOf(PRIMARY_USER_SMS_APP_UID2, SECONDARY_USER_SMS_APP_UID1))
|
||||
|
||||
val userRemovalIntent = Intent(Intent.ACTION_USER_REMOVED)
|
||||
userRemovalIntent.putExtra(Intent.EXTRA_USER, SECONDARY_USER_HANDLE)
|
||||
mUserRemovedReceiver.onReceive(context, userRemovalIntent)
|
||||
processOnHandlerThread {
|
||||
mSatelliteAccessController.onUserRemoved(SECONDARY_USER_HANDLE)
|
||||
}
|
||||
verify(mCallback, times(2)).accept(setOf(PRIMARY_USER_SMS_APP_UID2))
|
||||
}
|
||||
|
||||
private fun <T : Any> processOnHandlerThread(function: () -> T): T {
|
||||
val future = CompletableFuture<T>()
|
||||
mHandler.post { future.complete(function()) }
|
||||
return future.get()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnStartUpCallbackSatelliteFallbackUidWithExistingUsers() {
|
||||
doReturn(
|
||||
|
|
@ -320,15 +321,5 @@ class SatelliteAccessControllerTest {
|
|||
any(UserHandle::class.java)
|
||||
)
|
||||
mRoleHolderChangedListener = listenerCaptor.value
|
||||
|
||||
// Get registered receiver using captor
|
||||
val userRemovedReceiverCaptor = ArgumentCaptor.forClass(BroadcastReceiver::class.java)
|
||||
verify(context).registerReceiver(
|
||||
userRemovedReceiverCaptor.capture(),
|
||||
any(IntentFilter::class.java),
|
||||
isNull(),
|
||||
any(Handler::class.java)
|
||||
)
|
||||
mUserRemovedReceiver = userRemovedReceiverCaptor.value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue