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

Commit 6fe8b2a5 authored by Ling Ma's avatar Ling Ma
Browse files

Add metrics field to track auto data switch toggle

Bug: 255838492
Test: manual checked log
Change-Id: If618dd639b7c48ba24135673202d233fabf0e271
parent 0aefbf18
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -186,6 +186,9 @@ message PersistAtoms {

    /* Timestamp of last outgoing_short_code_sms pull. */
    optional int64 outgoing_short_code_sms_pull_timestamp_millis = 54;

    /* Number of time the user toggled the data switch feature since the last collection. */
    optional int32 auto_data_switch_toggle_count = 55;
}

// The canonical versions of the following enums live in:
+13 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SettingsObserver;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.data.DataConfigManager.DataConfigManagerCallback;
import com.android.internal.telephony.metrics.DeviceTelephonyPropertiesStats;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

@@ -610,6 +611,8 @@ public class DataSettingsManager extends Handler {
        if (enable == isMobileDataPolicyEnabled(mobileDataPolicy)) {
            return;
        }
        metricsRecordSetMobileDataPolicy(mobileDataPolicy);

        if (enable) {
            mEnabledMobileDataPolicy.add(mobileDataPolicy);
        } else {
@@ -629,6 +632,16 @@ public class DataSettingsManager extends Handler {
        }
    }

    /**
     * Record the number of times a mobile data policy is toggled to metrics.
     * @param mobileDataPolicy The mobile data policy that's toggled
     */
    private void metricsRecordSetMobileDataPolicy(@MobileDataPolicy int mobileDataPolicy) {
        if (mobileDataPolicy == TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH) {
            DeviceTelephonyPropertiesStats.recordAutoDataSwitchFeatureToggle();
        }
    }

    /**
     * Check whether data stall recovery on bad network is enabled.
     * @return {@code true} if data stall recovery is enabled and {@code false} otherwise.
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.metrics;

import com.android.internal.telephony.PhoneFactory;

/** Metrics for the telephony related properties on the device. */
public class DeviceTelephonyPropertiesStats {
    private static final String TAG = DeviceTelephonyPropertiesStats.class.getSimpleName();

    /**
     * Record whenever the auto data switch feature is toggled.
     */
    public static void recordAutoDataSwitchFeatureToggle() {
        PersistAtomsStorage storage = PhoneFactory.getMetricsCollector().getAtomsStorage();
        storage.recordToggledAutoDataSwitch();
    }
}
+14 −3
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSIO
import android.annotation.Nullable;
import android.app.StatsManager;
import android.content.Context;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.StatsEvent;

import com.android.internal.annotations.VisibleForTesting;
@@ -482,13 +484,22 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
        }
    }

    private static int pullDeviceTelephonyProperties(List<StatsEvent> data) {
    private int pullDeviceTelephonyProperties(List<StatsEvent> data) {
        Phone[] phones = getPhonesIfAny();
        if (phones.length == 0) {
            return StatsManager.PULL_SKIP;
        }

        data.add(TelephonyStatsLog.buildStatsEvent(DEVICE_TELEPHONY_PROPERTIES, true));
        boolean isAutoDataSwitchOn = false;
        for (Phone phone : phones) {
            // only applies to non-DDS
            if (phone.getSubId() != SubscriptionManager.getDefaultDataSubscriptionId()) {
                isAutoDataSwitchOn = phone.getDataSettingsManager().isMobileDataPolicyEnabled(
                        TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH);
                break;
            }
        }
        data.add(TelephonyStatsLog.buildStatsEvent(DEVICE_TELEPHONY_PROPERTIES, true,
                isAutoDataSwitchOn, mStorage.getAutoDataSwitchToggleCount()));
        return StatsManager.PULL_SUCCESS;
    }

+19 −1
Original line number Diff line number Diff line
@@ -42,8 +42,8 @@ import com.android.internal.telephony.nano.PersistAtomsProto.ImsRegistrationStat
import com.android.internal.telephony.nano.PersistAtomsProto.ImsRegistrationTermination;
import com.android.internal.telephony.nano.PersistAtomsProto.IncomingSms;
import com.android.internal.telephony.nano.PersistAtomsProto.NetworkRequestsV2;
import com.android.internal.telephony.nano.PersistAtomsProto.OutgoingSms;
import com.android.internal.telephony.nano.PersistAtomsProto.OutgoingShortCodeSms;
import com.android.internal.telephony.nano.PersistAtomsProto.OutgoingSms;
import com.android.internal.telephony.nano.PersistAtomsProto.PersistAtoms;
import com.android.internal.telephony.nano.PersistAtomsProto.PresenceNotifyEvent;
import com.android.internal.telephony.nano.PersistAtomsProto.RcsAcsProvisioningStats;
@@ -438,6 +438,14 @@ public class PersistAtomsStorage {
        }
    }

    /**
     * Store the number of times auto data switch feature is toggled.
     */
    public synchronized void recordToggledAutoDataSwitch() {
        mAtoms.autoDataSwitchToggleCount++;
        saveAtomsToFile(SAVE_TO_FILE_DELAY_FOR_UPDATE_MILLIS);
    }

    /** Adds a new {@link NetworkRequestsV2} to the storage. */
    public synchronized void addNetworkRequestsV2(NetworkRequestsV2 networkRequests) {
        NetworkRequestsV2 existingMetrics = find(networkRequests);
@@ -884,6 +892,16 @@ public class PersistAtomsStorage {
        }
    }

    /** @return the number of times auto data switch mobile data policy is toggled. */
    public synchronized int getAutoDataSwitchToggleCount() {
        int count = mAtoms.autoDataSwitchToggleCount;
        if (count > 0) {
            mAtoms.autoDataSwitchToggleCount = 0;
            saveAtomsToFile(SAVE_TO_FILE_DELAY_FOR_GET_MILLIS);
        }
        return count;
    }

    /**
     * Returns and clears the ImsRegistrationFeatureTagStats if last pulled longer than
     * {@code minIntervalMillis} ago, otherwise returns {@code null}.