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

Commit f1aa768f authored by Nagendra Prasad Nagarle Basavaraju's avatar Nagendra Prasad Nagarle Basavaraju
Browse files

Bootstrap Data Limit improvements

- Ignore EIMS Network request for Bootstrap Profile check
- Add Guard timer to limit querying Data Usage Stats api
- consider only metered capability for data usage calculation, using METERED_YES param at
  querySummaryForDevice() data usage stats api.

Bug: 319319590
Test: atest FrameworksTelephonyTests
Test: Manual test at b/332619961 & b/319319590#comment73
Test: Basic test @ b/332640742#comment1
Change-Id: I178f92708f9579144f0c7c756874c8f7e41c1365
parent 1cc12e50
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.data;

import android.annotation.CallbackExecutor;
import android.annotation.ElapsedRealtimeLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -38,6 +39,7 @@ import android.os.AsyncResult;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.telecom.TelecomManager;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.AccessNetworkType;
@@ -250,11 +252,23 @@ public class DataNetworkController extends Handler {
    private static final long REEVALUATE_BOOTSTRAP_SIM_DATA_USAGE_MILLIS =
            TimeUnit.SECONDS.toMillis(60);

    /**
     * The guard timer in milliseconds to limit querying the data usage api stats frequently
     */
    private static final long GUARD_TIMER_INTERVAL_TO_QUERY_DATA_USAGE_API_STATS_MILLIS =
            TimeUnit.SECONDS.toMillis(1);

    /**
     * bootstrap sim total data usage bytes
     */
    private long mBootStrapSimTotalDataUsageBytes = 0L;

    /**
     * bootstrap sim last data usage query time
     */
    @ElapsedRealtimeLong
    private long mBootstrapSimLastDataUsageQueryTime = 0L;

    private final Phone mPhone;
    private final String mLogTag;
    private final LocalLog mLocalLog = new LocalLog(128);
@@ -1545,7 +1559,7 @@ public class DataNetworkController extends Handler {
            DataProfile emergencyProfile = mDataProfileManager.getDataProfileForNetworkRequest(
                    networkRequest, getDataNetworkType(transport),
                    mServiceState.isUsingNonTerrestrialNetwork(),
                    isEsimBootStrapProvisioningActivated(), true);
                    false /*isEsimBootStrapProvisioning*/, true);

            // Check if the profile is being throttled.
            if (mDataConfigManager.shouldHonorRetryTimerForEmergencyNetworkRequest()
@@ -1760,7 +1774,8 @@ public class DataNetworkController extends Handler {
     *  - At evaluation network request and evaluation data network determines, if
     *    bootstrap sim current data usage reached bootstrap sim max data limit allowed set
     *    at {@link DataConfigManager#getEsimBootStrapMaxDataLimitBytes()}
     *  - Query the current data usage at {@link #getDataUsage()}
     *  - Query the current data usage at {@link #getDataUsage()}, if last data usage query guarding
     *    interval as expired.
     *
     * @return true, if bootstrap sim data limit is reached
     *         else false, if bootstrap sim max data limit allowed set is -1(Unlimited) or current
@@ -1775,13 +1790,15 @@ public class DataNetworkController extends Handler {
            return false;
        }

        log("current bootstrap sim data Usage: " + mBootStrapSimTotalDataUsageBytes);
        if (mBootStrapSimTotalDataUsageBytes >= esimBootStrapMaxDataLimitBytes) {
            return true;
        } else {
        if (mBootStrapSimTotalDataUsageBytes < esimBootStrapMaxDataLimitBytes
                && (mBootstrapSimLastDataUsageQueryTime == 0
                || SystemClock.elapsedRealtime() - mBootstrapSimLastDataUsageQueryTime
                > GUARD_TIMER_INTERVAL_TO_QUERY_DATA_USAGE_API_STATS_MILLIS)) {
            mBootStrapSimTotalDataUsageBytes = getDataUsage();
            return mBootStrapSimTotalDataUsageBytes >= esimBootStrapMaxDataLimitBytes;
            log("current bootstrap sim data usage: " + mBootStrapSimTotalDataUsageBytes);
            mBootstrapSimLastDataUsageQueryTime =  SystemClock.elapsedRealtime();
        }
        return mBootStrapSimTotalDataUsageBytes >= esimBootStrapMaxDataLimitBytes;
    }

    /**
@@ -1801,6 +1818,8 @@ public class DataNetworkController extends Handler {

            if (!TextUtils.isEmpty(subscriberId)) {
                builder.setSubscriberIds(Set.of(subscriberId));
                // Consider data usage calculation of only metered capabilities / data network
                builder.setMeteredness(android.net.NetworkStats.METERED_YES);
                NetworkTemplate template = builder.build();
                final NetworkStats.Bucket ret = networkStatsManager
                        .querySummaryForDevice(template, 0L, System.currentTimeMillis());