Use connectivityHandler in CarrierPrivilegeAuthenticator

When request_restricted_wifi is enabled CarrierPrivilegeAuthenticator
calls CarrierPrivilegesLost callback passed from ConnectivityService.
But CarrierPrivilegeAuthenticator was using its own handler thread to
receive broadcast and callbacks so CarrierPrivilegesLost callback needed
to post a message to the CS handler.
This CL updates CarrierPrivilegeAuthenticator to use CS handler if
request_restricted_wifi is enabled, and remove the message post in
ConnectivityService.

Test: TH
Change-Id: Ib41304a30e3dd366b0f6f1d7df81145f0e05ece1
This commit is contained in:
Motomu Utsumi 2024-02-28 17:15:41 +09:00
commit 4fcaa4e803

View file

@ -844,11 +844,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/
private static final int EVENT_UID_FROZEN_STATE_CHANGED = 61;
/**
* Event to inform the ConnectivityService handler when a uid has lost carrier privileges.
*/
private static final int EVENT_UID_CARRIER_PRIVILEGES_LOST = 62;
/**
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
* should be shown.
@ -1289,14 +1284,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
private final LegacyTypeTracker mLegacyTypeTracker = new LegacyTypeTracker(this);
@VisibleForTesting
void onCarrierPrivilegesLost(Integer uid, Integer subId) {
if (mRequestRestrictedWifiEnabled) {
mHandler.sendMessage(mHandler.obtainMessage(
EVENT_UID_CARRIER_PRIVILEGES_LOST, uid, subId));
}
}
final LocalPriorityDump mPriorityDumper = new LocalPriorityDump();
/**
* Helper class which parses out priority arguments and dumps sections according to their
@ -1518,10 +1505,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
@NonNull final Context context,
@NonNull final TelephonyManager tm,
boolean requestRestrictedWifiEnabled,
@NonNull BiConsumer<Integer, Integer> listener) {
@NonNull BiConsumer<Integer, Integer> listener,
@NonNull final Handler connectivityServiceHandler) {
if (isAtLeastT()) {
return new CarrierPrivilegeAuthenticator(
context, tm, requestRestrictedWifiEnabled, listener);
return new CarrierPrivilegeAuthenticator(context, tm, requestRestrictedWifiEnabled,
listener, connectivityServiceHandler);
} else {
return null;
}
@ -1806,7 +1794,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
&& mDeps.isFeatureEnabled(context, REQUEST_RESTRICTED_WIFI);
mCarrierPrivilegeAuthenticator = mDeps.makeCarrierPrivilegeAuthenticator(
mContext, mTelephonyManager, mRequestRestrictedWifiEnabled,
this::onCarrierPrivilegesLost);
this::handleUidCarrierPrivilegesLost, mHandler);
if (mDeps.isAtLeastU()
&& mDeps
@ -3823,6 +3811,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
mSatelliteAccessController.start();
}
if (mCarrierPrivilegeAuthenticator != null) {
mCarrierPrivilegeAuthenticator.start();
}
// On T+ devices, register callback for statsd to pull NETWORK_BPF_MAP_INFO atom
if (mDeps.isAtLeastT()) {
mBpfNetMaps.setPullAtomCallback(mContext);
@ -6510,9 +6502,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
UidFrozenStateChangedArgs args = (UidFrozenStateChangedArgs) msg.obj;
handleFrozenUids(args.mUids, args.mFrozenStates);
break;
case EVENT_UID_CARRIER_PRIVILEGES_LOST:
handleUidCarrierPrivilegesLost(msg.arg1, msg.arg2);
break;
}
}
}
@ -9168,6 +9157,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
private void handleUidCarrierPrivilegesLost(int uid, int subId) {
if (!mRequestRestrictedWifiEnabled) {
return;
}
ensureRunningOnConnectivityServiceThread();
// A NetworkRequest needs to be revoked when all the conditions are met
// 1. It requests restricted network