Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69390aa5 authored by Ken Chen's avatar Ken Chen
Browse files

Take metered information from setResolverConfiguration

1. Uses dnsresolver_aidl_interface_lateststable_version 12.
2. Get the 'metered' parameter from setResolverConfiguration and keep it
   in NetConfig of each network.
3. Add resolv_is_metered_network() for DnsProxyListener.

Bug: 288340533
Test: atest resolv_integration_test resolv_unit_test
Change-Id: I390199b93a9f5b3c0abc8f072d91153ef9fac32e
parent b900105e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ cc_library_headers {
    ],
}

dnsresolver_aidl_interface_lateststable_version = "V11"
dnsresolver_aidl_interface_lateststable_version = "V12"

cc_library_static {
    name: "dnsresolver_aidl_interface-lateststable-ndk",
+2 −1
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ int ResolverController::setResolverConfiguration(const ResolverParamsParcel& res

    return resolv_set_nameservers(resolverParams.netId, resolverParams.servers,
                                  resolverParams.domains, res_params,
                                  resolverParams.resolverOptions, resolverParams.transportTypes);
                                  resolverParams.resolverOptions, resolverParams.transportTypes,
                                  resolverParams.meteredNetwork);
}

int ResolverController::getResolverInfo(int32_t netId, std::vector<std::string>* servers,
+12 −1
Original line number Diff line number Diff line
@@ -1065,6 +1065,7 @@ struct NetConfig {
    int tc_mode = aidl::android::net::IDnsResolver::TC_MODE_DEFAULT;
    bool enforceDnsUid = false;
    std::vector<int32_t> transportTypes;
    bool metered = false;
};

/* gets cache associated with a network, or NULL if none exists */
@@ -1642,7 +1643,7 @@ std::vector<std::string> getCustomizedTableByName(const size_t netid, const char
int resolv_set_nameservers(unsigned netid, const std::vector<std::string>& servers,
                           const std::vector<std::string>& domains, const res_params& params,
                           const std::optional<ResolverOptionsParcel> optionalResolverOptions,
                           const std::vector<int32_t>& transportTypes) {
                           const std::vector<int32_t>& transportTypes, bool metered) {
    std::vector<std::string> nameservers = filter_nameservers(servers);
    const int numservers = static_cast<int>(nameservers.size());

@@ -1709,6 +1710,7 @@ int resolv_set_nameservers(unsigned netid, const std::vector<std::string>& serve
        return -EINVAL;
    }
    netconfig->transportTypes = transportTypes;
    netconfig->metered = metered;
    if (optionalResolverOptions.has_value()) {
        const ResolverOptionsParcel& resolverOptions = optionalResolverOptions.value();
        return netconfig->setOptions(resolverOptions);
@@ -2090,6 +2092,7 @@ void resolv_netconfig_dump(DumpWriter& dw, unsigned netid) {
        // TODO: dump info->hosts
        dw.println("TC mode: %s", tc_mode_to_str(info->tc_mode));
        dw.println("TransportType: %s", transport_type_to_str(info->transportTypes));
        dw.println("Metered: %s", info->metered ? "true" : "false");
    }
}

@@ -2110,3 +2113,11 @@ bool resolv_is_enforceDnsUid_enabled_network(unsigned netid) {
    }
    return false;
}

bool resolv_is_metered_network(unsigned netid) {
    std::lock_guard guard(cache_mutex);
    if (const auto info = find_netconfig_locked(netid); info != nullptr) {
        return info->metered;
    }
    return false;
}
+4 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ std::vector<std::string> getCustomizedTableByName(const size_t netid, const char
int resolv_set_nameservers(unsigned netid, const std::vector<std::string>& servers,
                           const std::vector<std::string>& domains, const res_params& params,
                           std::optional<aidl::android::net::ResolverOptionsParcel> resolverOptions,
                           const std::vector<int32_t>& transportTypes = {});
                           const std::vector<int32_t>& transportTypes = {}, bool metered = false);

// Sets options for a given network.
int resolv_set_options(unsigned netid, const aidl::android::net::ResolverOptionsParcel& options);
@@ -146,3 +146,6 @@ int resolv_get_max_cache_entries(unsigned netid);

// Return true if the enforceDnsUid is enabled on the network.
bool resolv_is_enforceDnsUid_enabled_network(unsigned netid);

// Return true if the network is metered.
bool resolv_is_metered_network(unsigned netid);
+4 −0
Original line number Diff line number Diff line
@@ -91,6 +91,10 @@ class ResolverParams {
            mParcel.retryCount = params[IDnsResolver::RESOLVER_PARAMS_RETRY_COUNT];
            return *this;
        }
        constexpr Builder& setMetered(const bool metered) {
            mParcel.meteredNetwork = metered;
            return *this;
        }
        aidl::android::net::ResolverParamsParcel build() { return mParcel; }

      private:
Loading