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

Commit d99022cb authored by Ken Chen's avatar Ken Chen Committed by Luke Huang
Browse files

Add netd binder and resolver API

- Add a path for ConnectivityService to pass log severity to resolver.
- Remove persist system property. No more keep logging severity setting
after reboot.

Bug: 129108902
Test: full build, flash ROM
Test: atest resolv_integration_test
Change-Id: I66a065dcd034c88ed8e0b5f24f53382d355735bd
parent e3419ce0
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -28,9 +28,7 @@ bool resolv_init(const ResolverNetdCallbacks& callbacks) {
    android::base::InitLogging(/*argv=*/nullptr);
    android::base::SetDefaultTag("libnetd_resolv");
    LOG(INFO) << __func__ << ": Initializing resolver";
    const std::string logSeverityStr =
            android::base::GetProperty("persist.sys.nw_dns_resolver_log", "WARNING");
    android::base::SetMinimumLogSeverity(logSeverityStrToEnum(logSeverityStr));
    resolv_set_log_severity(android::base::WARNING);

    android::net::gResNetdCallbacks = callbacks;
    android::net::gDnsResolv = android::net::DnsResolver::getInstance();
@@ -76,5 +74,9 @@ bool DnsResolver::start() {
    return true;
}

int DnsResolver::setLogSeverity(int32_t logSeverity) {
    return resolv_set_log_severity(logSeverity);
}

}  // namespace net
}  // namespace android
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ class DnsResolver {
  public:
    static DnsResolver* getInstance();
    bool start();
    int setLogSeverity(int32_t logSeverity);

    DnsResolver(DnsResolver const&) = delete;
    void operator=(DnsResolver const&) = delete;
+9 −0
Original line number Diff line number Diff line
@@ -278,6 +278,15 @@ static std::vector<uint8_t> parseBase64(const std::string& input) {
    return ::ndk::ScopedAStatus(AStatus_newOk());
}

::ndk::ScopedAStatus DnsResolverService::setLogSeverity(int32_t logSeverity) {
    ENFORCE_NETWORK_STACK_PERMISSIONS();
    auto entry = gDnsResolverLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(logSeverity);
    int res = gDnsResolv->setLogSeverity(logSeverity);

    gResNetdCallbacks.log(entry.returns(res).withAutomaticDuration().toString().c_str());
    return statusFromErrcode(res);
}

::ndk::ScopedAStatus DnsResolverService::destroyNetworkCache(int netId) {
    // Locking happens in res_cache.cpp functions.
    ENFORCE_NETWORK_STACK_PERMISSIONS();
+3 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ class DnsResolverService : public aidl::android::net::BnDnsResolver {
    // (internal use only)
    ::ndk::ScopedAStatus getPrefix64(int netId, std::string* stringPrefix) override;

    // Debug log command
    ::ndk::ScopedAStatus setLogSeverity(int32_t logSeverity) override;

  private:
    DnsResolverService() {}
    // TODO: Remove below items after libbiner_ndk supports check_permission.
+17 −0
Original line number Diff line number Diff line
@@ -144,4 +144,21 @@ interface IDnsResolver {
     * @param netId the network ID of the network to destroy.
     */
    void destroyNetworkCache(int netId);

    // Refer to enum LogSeverity from system/core/base/include/android-base/logging.h
    const int DNS_RESOLVER_LOG_VERBOSE = 0;
    const int DNS_RESOLVER_LOG_DEBUG = 1;
    const int DNS_RESOLVER_LOG_INFO = 2;
    const int DNS_RESOLVER_LOG_WARNING = 3;
    const int DNS_RESOLVER_LOG_ERROR = 4;

    /**
     * Set DNS resolver log severity
     *
     * @param logSeverity print log in "VERBOSE", "DEBUG", "INFO", "WARNING", "ERROR".
     *
     * @throws ServiceSpecificException in case of failure, with an error code corresponding to the
     *         POSIX errno.
     */
    void setLogSeverity(int logSeverity);
}
Loading