Stop CarrierPrivilegeAuthenticator thread in tests
Bug: 308519360 Test: CarrierPrivilegeAuthenticatorTest Change-Id: I59164be00a9e1fcced8538537c1dcabd214f2170
This commit is contained in:
@@ -1362,8 +1362,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
/**
|
||||
* Create a HandlerThread to use in ConnectivityService.
|
||||
*/
|
||||
public HandlerThread makeHandlerThread() {
|
||||
return new HandlerThread("ConnectivityServiceThread");
|
||||
public HandlerThread makeHandlerThread(@NonNull final String tag) {
|
||||
return new HandlerThread(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1458,7 +1458,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
public CarrierPrivilegeAuthenticator makeCarrierPrivilegeAuthenticator(
|
||||
@NonNull final Context context, @NonNull final TelephonyManager tm) {
|
||||
if (isAtLeastT()) {
|
||||
return new CarrierPrivilegeAuthenticator(context, this, tm);
|
||||
return new CarrierPrivilegeAuthenticator(context, tm);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -1706,7 +1706,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
mNetd = netd;
|
||||
mBpfNetMaps = mDeps.getBpfNetMaps(mContext, netd);
|
||||
mHandlerThread = mDeps.makeHandlerThread();
|
||||
mHandlerThread = mDeps.makeHandlerThread("ConnectivityServiceThread");
|
||||
mPermissionMonitor =
|
||||
new PermissionMonitor(mContext, mNetd, mBpfNetMaps, mHandlerThread);
|
||||
mHandlerThread.start();
|
||||
|
||||
@@ -43,11 +43,11 @@ import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.modules.utils.HandlerExecutor;
|
||||
import com.android.net.module.util.DeviceConfigUtils;
|
||||
import com.android.networkstack.apishim.TelephonyManagerShimImpl;
|
||||
import com.android.networkstack.apishim.common.TelephonyManagerShim;
|
||||
import com.android.networkstack.apishim.common.TelephonyManagerShim.CarrierPrivilegesListenerShim;
|
||||
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
|
||||
import com.android.server.ConnectivityService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -78,13 +78,13 @@ public class CarrierPrivilegeAuthenticator {
|
||||
private final boolean mUseCallbacksForServiceChanged;
|
||||
|
||||
public CarrierPrivilegeAuthenticator(@NonNull final Context c,
|
||||
@NonNull final ConnectivityService.Dependencies deps,
|
||||
@NonNull final Dependencies deps,
|
||||
@NonNull final TelephonyManager t,
|
||||
@NonNull final TelephonyManagerShim telephonyManagerShim) {
|
||||
mContext = c;
|
||||
mTelephonyManager = t;
|
||||
mTelephonyManagerShim = telephonyManagerShim;
|
||||
final HandlerThread thread = new HandlerThread(TAG);
|
||||
final HandlerThread thread = deps.makeHandlerThread();
|
||||
thread.start();
|
||||
mHandler = new Handler(thread.getLooper());
|
||||
mUseCallbacksForServiceChanged = deps.isFeatureEnabled(
|
||||
@@ -110,9 +110,24 @@ public class CarrierPrivilegeAuthenticator {
|
||||
}
|
||||
|
||||
public CarrierPrivilegeAuthenticator(@NonNull final Context c,
|
||||
@NonNull final ConnectivityService.Dependencies deps,
|
||||
@NonNull final TelephonyManager t) {
|
||||
this(c, deps, t, TelephonyManagerShimImpl.newInstance(t));
|
||||
this(c, new Dependencies(), t, TelephonyManagerShimImpl.newInstance(t));
|
||||
}
|
||||
|
||||
public static class Dependencies {
|
||||
/**
|
||||
* Create a HandlerThread to use in CarrierPrivilegeAuthenticator.
|
||||
*/
|
||||
public HandlerThread makeHandlerThread() {
|
||||
return new HandlerThread(TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeviceConfigUtils#isTetheringFeatureEnabled
|
||||
*/
|
||||
public boolean isFeatureEnabled(Context context, String name) {
|
||||
return DeviceConfigUtils.isTetheringFeatureEnabled(context, name);
|
||||
}
|
||||
}
|
||||
|
||||
private void simConfigChanged() {
|
||||
|
||||
@@ -33,7 +33,6 @@ public final class ConnectivityFlags {
|
||||
public static final String NO_REMATCH_ALL_REQUESTS_ON_REGISTER =
|
||||
"no_rematch_all_requests_on_register";
|
||||
|
||||
@VisibleForTesting
|
||||
public static final String CARRIER_SERVICE_CHANGED_USE_CALLBACK =
|
||||
"carrier_service_changed_use_callback_version";
|
||||
|
||||
|
||||
@@ -1991,7 +1991,7 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerThread makeHandlerThread() {
|
||||
public HandlerThread makeHandlerThread(@NonNull final String tag) {
|
||||
return mCsHandlerThread;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import android.content.pm.PackageManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.TelephonyNetworkSpecifier;
|
||||
import android.os.Build;
|
||||
import android.os.HandlerThread;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
@@ -52,10 +53,11 @@ import com.android.net.module.util.CollectionUtils;
|
||||
import com.android.networkstack.apishim.TelephonyManagerShimImpl;
|
||||
import com.android.networkstack.apishim.common.TelephonyManagerShim.CarrierPrivilegesListenerShim;
|
||||
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
|
||||
import com.android.server.ConnectivityService;
|
||||
import com.android.server.connectivity.CarrierPrivilegeAuthenticator.Dependencies;
|
||||
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
|
||||
import com.android.testutils.DevSdkIgnoreRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
@@ -86,10 +88,11 @@ public class CarrierPrivilegeAuthenticatorTest {
|
||||
private final int mCarrierConfigPkgUid = 12345;
|
||||
private final String mTestPkg = "com.android.server.connectivity.test";
|
||||
private final BroadcastReceiver mMultiSimBroadcastReceiver;
|
||||
@NonNull private final HandlerThread mHandlerThread;
|
||||
|
||||
public class TestCarrierPrivilegeAuthenticator extends CarrierPrivilegeAuthenticator {
|
||||
TestCarrierPrivilegeAuthenticator(@NonNull final Context c,
|
||||
@NonNull final ConnectivityService.Dependencies deps,
|
||||
@NonNull final Dependencies deps,
|
||||
@NonNull final TelephonyManager t) {
|
||||
super(c, deps, t, mTelephonyManagerShim);
|
||||
}
|
||||
@@ -100,6 +103,11 @@ public class CarrierPrivilegeAuthenticatorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mHandlerThread.quit();
|
||||
}
|
||||
|
||||
/** Parameters to test both using callbacks or the old broadcast */
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Boolean> shouldUseCallbacks() {
|
||||
@@ -111,9 +119,11 @@ public class CarrierPrivilegeAuthenticatorTest {
|
||||
mTelephonyManager = mock(TelephonyManager.class);
|
||||
mTelephonyManagerShim = mock(TelephonyManagerShimImpl.class);
|
||||
mPackageManager = mock(PackageManager.class);
|
||||
final ConnectivityService.Dependencies deps = mock(ConnectivityService.Dependencies.class);
|
||||
mHandlerThread = new HandlerThread(CarrierPrivilegeAuthenticatorTest.class.getSimpleName());
|
||||
final Dependencies deps = mock(Dependencies.class);
|
||||
doReturn(useCallbacks).when(deps).isFeatureEnabled(any() /* context */,
|
||||
eq(CARRIER_SERVICE_CHANGED_USE_CALLBACK));
|
||||
doReturn(mHandlerThread).when(deps).makeHandlerThread();
|
||||
doReturn(SUBSCRIPTION_COUNT).when(mTelephonyManager).getActiveModemCount();
|
||||
doReturn(mTestPkg).when(mTelephonyManagerShim)
|
||||
.getCarrierServicePackageNameForLogicalSlot(anyInt());
|
||||
|
||||
@@ -176,7 +176,7 @@ open class CSTest {
|
||||
override fun getClatCoordinator(netd: INetd?) = this@CSTest.clatCoordinator
|
||||
override fun getNetworkStack() = this@CSTest.networkStack
|
||||
|
||||
override fun makeHandlerThread() = csHandlerThread
|
||||
override fun makeHandlerThread(tag: String) = csHandlerThread
|
||||
override fun makeProxyTracker(context: Context, connServiceHandler: Handler) = proxyTracker
|
||||
|
||||
override fun makeCarrierPrivilegeAuthenticator(
|
||||
|
||||
Reference in New Issue
Block a user