Reference DataSaver setting from BPF map on V+ only
Only reference DataSaverEnabled map on V+ platform because the information in map before platform V is not time-precise. See comment in this commit for detail. Bug: 288340533 Test: presubmit Change-Id: I0795e88e6006e6d24d27b63c31d0e3ed81d0262c
This commit is contained in:
@@ -62,16 +62,24 @@ base::Result<bool> DnsBpfHelper::isUidNetworkingBlocked(uid_t uid, bool metered)
|
||||
if (isBlockedByUidRules(enabledRules.value(), uidRules)) return true;
|
||||
|
||||
// For data saver.
|
||||
if (!metered) return false;
|
||||
// DataSaverEnabled map on V+ platforms is the only reliable source of information about the
|
||||
// current data saver status. While ConnectivityService offers two ways to update this map for U
|
||||
// and V+, the U- platform implementation can have delays, potentially leading to inaccurate
|
||||
// results. Conversely, the V+ platform implementation is synchronized with the actual data saver
|
||||
// state, making it a trustworthy source. Since this library primarily serves DNS resolvers,
|
||||
// relying solely on V+ data prevents erroneous blocking of DNS queries.
|
||||
if (android::modules::sdklevel::IsAtLeastV() && metered) {
|
||||
// The background data setting (PENALTY_BOX_MATCH) and unrestricted data usage setting
|
||||
// (HAPPY_BOX_MATCH) for individual apps override the system wide Data Saver setting.
|
||||
if (uidRules & PENALTY_BOX_MATCH) return true;
|
||||
if (uidRules & HAPPY_BOX_MATCH) return false;
|
||||
|
||||
// The background data setting (PENALTY_BOX_MATCH) and unrestricted data usage setting
|
||||
// (HAPPY_BOX_MATCH) for individual apps override the system wide Data Saver setting.
|
||||
if (uidRules & PENALTY_BOX_MATCH) return true;
|
||||
if (uidRules & HAPPY_BOX_MATCH) return false;
|
||||
auto dataSaverSetting = mDataSaverEnabledMap.readValue(DATA_SAVER_ENABLED_KEY);
|
||||
RETURN_IF_RESULT_NOT_OK(dataSaverSetting);
|
||||
return dataSaverSetting.value();
|
||||
}
|
||||
|
||||
auto dataSaverSetting = mDataSaverEnabledMap.readValue(DATA_SAVER_ENABLED_KEY);
|
||||
RETURN_IF_RESULT_NOT_OK(dataSaverSetting);
|
||||
return dataSaverSetting.value();
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
||||
Reference in New Issue
Block a user