Use FakeSettingsProvider callbacks to simplify CS tests.
Because FakeSettingsProvider and other test infrastructure did not support settings observers, the tests called internal ConnectivityService methods to cause the settings to be re-read. Now that FakeSettingsProvider supports callbacks, use ContentResolverWithFakeSettingsProvider in the CS tests and just use the callbacks. Bug: 397521796 Flag: TEST_ONLY Test: test-only change Change-Id: I26d8e98706fec99aa423721bf1474af2f9b60099
This commit is contained in:
parent
7b693cae9f
commit
6e3afc7dc6
1 changed files with 54 additions and 65 deletions
|
|
@ -1587,6 +1587,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
return new HandlerThread(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a content observer. This method exists because ContentResolver#registerObserver
|
||||
* is final and cannot be overridden by tests.
|
||||
*/
|
||||
public void registerContentObserver(ContentResolver cr, Uri uri,
|
||||
boolean notifyForDescendants, ContentObserver observer) {
|
||||
cr.registerContentObserver(uri, notifyForDescendants, observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the ModuleNetworkStackClient.
|
||||
*/
|
||||
|
|
@ -2249,7 +2258,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
loge("Error registering event listener :" + e);
|
||||
}
|
||||
|
||||
mSettingsObserver = new SettingsObserver(mContext, mHandler);
|
||||
mSettingsObserver = new SettingsObserver(mContext, mHandler, mDeps);
|
||||
registerSettingsCallbacks();
|
||||
|
||||
mKeepaliveTracker = mDeps.makeAutomaticOnOffKeepaliveTracker(mContext, mHandler);
|
||||
|
|
@ -2426,33 +2435,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
return new NetworkRequest(netCap, TYPE_NONE, nextNetworkRequestId(), type);
|
||||
}
|
||||
|
||||
// Used only for testing.
|
||||
// TODO: Delete this and either:
|
||||
// 1. Give FakeSettingsProvider the ability to send settings change notifications (requires
|
||||
// changing ContentResolver to make registerContentObserver non-final).
|
||||
// 2. Give FakeSettingsProvider an alternative notification mechanism and have the test use it
|
||||
// by subclassing SettingsObserver.
|
||||
@VisibleForTesting
|
||||
void updateAlwaysOnNetworks() {
|
||||
mHandler.sendEmptyMessage(EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);
|
||||
}
|
||||
|
||||
// See FakeSettingsProvider comment above.
|
||||
@VisibleForTesting
|
||||
void updatePrivateDnsSettings() {
|
||||
mHandler.sendEmptyMessage(EVENT_PRIVATE_DNS_SETTINGS_CHANGED);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void updateMobileDataPreferredUids() {
|
||||
mHandler.sendEmptyMessage(EVENT_MOBILE_DATA_PREFERRED_UIDS_CHANGED);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateIngressRateLimit() {
|
||||
mHandler.sendEmptyMessage(EVENT_INGRESS_RATE_LIMIT_CHANGED);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void simulateUpdateProxyInfo(@Nullable final Network network,
|
||||
@NonNull final ProxyInfo proxyInfo) {
|
||||
|
|
@ -4402,7 +4384,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
// rules are applied before system ready. Normally, the empty uid list means to clear
|
||||
// the uids rules on netd.
|
||||
if (!ConnectivitySettingsManager.getMobileDataPreferredUids(mContext).isEmpty()) {
|
||||
updateMobileDataPreferredUids();
|
||||
mHandler.sendEmptyMessage(EVENT_MOBILE_DATA_PREFERRED_UIDS_CHANGED);
|
||||
}
|
||||
|
||||
if (mSatelliteAccessController != null) {
|
||||
|
|
@ -7685,21 +7667,22 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
}
|
||||
|
||||
private static class SettingsObserver extends ContentObserver {
|
||||
final private HashMap<Uri, Integer> mUriEventMap;
|
||||
final private Context mContext;
|
||||
final private Handler mHandler;
|
||||
private final HashMap<Uri, Integer> mUriEventMap;
|
||||
private final Context mContext;
|
||||
private final Handler mHandler;
|
||||
private final Dependencies mDeps;
|
||||
|
||||
SettingsObserver(Context context, Handler handler) {
|
||||
SettingsObserver(Context context, Handler handler, Dependencies deps) {
|
||||
super(null);
|
||||
mUriEventMap = new HashMap<>();
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
mDeps = deps;
|
||||
}
|
||||
|
||||
void observe(Uri uri, int what) {
|
||||
mUriEventMap.put(uri, what);
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
resolver.registerContentObserver(uri, false, this);
|
||||
mDeps.registerContentObserver(mContext.getContentResolver(), uri, false, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in a new issue