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

Commit 323e5bab authored by Luca Stefani's avatar Luca Stefani
Browse files

Revert "NtpTrustedTime: Refresh NTP server from resources before requesting time"

* Replaced by upstream fix

This reverts commit ea17661a.

Change-Id: If667faf3595c856ffbf7352c67ba4daad00003de
parent d0ad7f6b
Loading
Loading
Loading
Loading
+9 −5
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2011 The Android Open Source Project
 * Copyright (C) 2011 The Android Open Source Project
 * Copyright (C) 2018 The LineageOS Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -64,14 +63,17 @@ public class NtpTrustedTime implements TrustedTime {
            final Resources res = context.getResources();
            final Resources res = context.getResources();
            final ContentResolver resolver = context.getContentResolver();
            final ContentResolver resolver = context.getContentResolver();


            final String defaultServer = res.getString(
                    com.android.internal.R.string.config_ntpServer);
            final long defaultTimeout = res.getInteger(
            final long defaultTimeout = res.getInteger(
                    com.android.internal.R.integer.config_ntpTimeout);
                    com.android.internal.R.integer.config_ntpTimeout);


            final String server = Settings.Global.getString(
            final String secureServer = Settings.Global.getString(
                    resolver, Settings.Global.NTP_SERVER);
                    resolver, Settings.Global.NTP_SERVER);
            final long timeout = Settings.Global.getLong(
            final long timeout = Settings.Global.getLong(
                    resolver, Settings.Global.NTP_TIMEOUT, defaultTimeout);
                    resolver, Settings.Global.NTP_TIMEOUT, defaultTimeout);


            final String server = secureServer != null ? secureServer : defaultServer;
            sSingleton = new NtpTrustedTime(server, timeout);
            sSingleton = new NtpTrustedTime(server, timeout);
            sContext = context;
            sContext = context;
        }
        }
@@ -94,8 +96,10 @@ public class NtpTrustedTime implements TrustedTime {
    }
    }


    public boolean forceRefresh(Network network) {
    public boolean forceRefresh(Network network) {
        final String realServer = TextUtils.isEmpty(mServer) ? sContext.getResources().getString(
        if (TextUtils.isEmpty(mServer)) {
                com.android.internal.R.string.config_ntpServer) : mServer;
            // missing server, so no trusted time available
            return false;
        }


        // We can't do this at initialization time: ConnectivityService might not be running yet.
        // We can't do this at initialization time: ConnectivityService might not be running yet.
        synchronized (this) {
        synchronized (this) {
@@ -113,7 +117,7 @@ public class NtpTrustedTime implements TrustedTime {


        if (LOGD) Log.d(TAG, "forceRefresh() from cache miss");
        if (LOGD) Log.d(TAG, "forceRefresh() from cache miss");
        final SntpClient client = new SntpClient();
        final SntpClient client = new SntpClient();
        if (client.requestTime(realServer, (int) mTimeout, network)) {
        if (client.requestTime(mServer, (int) mTimeout, network)) {
            mHasCache = true;
            mHasCache = true;
            mCachedNtpTime = client.getNtpTime();
            mCachedNtpTime = client.getNtpTime();
            mCachedNtpElapsedRealtime = client.getNtpTimeReference();
            mCachedNtpElapsedRealtime = client.getNtpTimeReference();