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

Commit cd581c20 authored by Ling Ma's avatar Ling Ma
Browse files

Add SMS and telephonyProperties metrics for work profile

Bug: 261776686
Test: sample: https://paste.googleplex.com/5101693573267456
Change-Id: I8b2738d2ee3ef20c4922b18bf723d571e2c06493
parent 17357534
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -259,6 +259,7 @@ message IncomingSms {
    optional int32 carrier_id = 13;
    optional int64 message_id = 14;
    optional int32 count = 15;
    optional bool is_managed_profile = 16;

    // Internal use only
    optional int32 hashCode = 10001;
@@ -282,6 +283,7 @@ message OutgoingSms {
    optional int32 count = 15;
    optional int32 send_error_code = 16;
    optional int32 network_error_code = 17;
    optional bool is_managed_profile = 18;

    // Internal use only
    optional int32 hashCode = 10001;
+15 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.RegistrantList;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.WorkSource;
import android.preference.PreferenceManager;
import android.sysprop.TelephonyProperties;
@@ -5134,6 +5135,20 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
                : null;
    }

    /**
     * Checks if the context user is a managed profile.
     *
     * Note that this applies specifically to <em>managed</em> profiles.
     *
     * @return whether the context user is a managed profile.
     */
    public boolean isManagedProfile() {
        UserHandle userHandle = getUserHandle();
        UserManager userManager = mContext.getSystemService(UserManager.class);
        if (userHandle == null || userManager == null) return false;
        return userManager.isManagedProfile(userHandle.getIdentifier());
    }

    /**
     * @return global null cipher and integrity enabled preference
     */
+14 −12
Original line number Diff line number Diff line
@@ -483,17 +483,17 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
        if (phones.length == 0) {
            return StatsManager.PULL_SKIP;
        }
        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;
            }
        }
        boolean isAutoDataSwitchOn = Arrays.stream(phones)
                .anyMatch(phone ->
                        phone.getSubId() != SubscriptionManager.getDefaultDataSubscriptionId()
                                && phone.getDataSettingsManager().isMobileDataPolicyEnabled(
                        TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH));
        boolean hasDedicatedManagedProfileSub = Arrays.stream(phones)
                .anyMatch(Phone::isManagedProfile);

        data.add(TelephonyStatsLog.buildStatsEvent(DEVICE_TELEPHONY_PROPERTIES, true,
                isAutoDataSwitchOn, mStorage.getAutoDataSwitchToggleCount()));
                isAutoDataSwitchOn, mStorage.getAutoDataSwitchToggleCount(),
                hasDedicatedManagedProfileSub));
        return StatsManager.PULL_SUCCESS;
    }

@@ -816,7 +816,8 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
                sms.isEsim,
                sms.carrierId,
                sms.messageId,
                sms.count);
                sms.count,
                sms.isManagedProfile);
    }

    private static StatsEvent buildStatsEvent(OutgoingSms sms) {
@@ -838,7 +839,8 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
                sms.intervalMillis,
                sms.count,
                sms.sendErrorCode,
                sms.networkErrorCode);
                sms.networkErrorCode,
                sms.isManagedProfile);
    }

    private static StatsEvent buildStatsEvent(DataCallSession dataCallSession) {
+2 −0
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ public class SmsStats {
        // SMS messages (e.g. those handled by OS or error cases).
        proto.messageId = RANDOM.nextLong();
        proto.count = 1;
        proto.isManagedProfile = mPhone.isManagedProfile();
        return proto;
    }

@@ -258,6 +259,7 @@ public class SmsStats {
        proto.retryId = 0;
        proto.intervalMillis = intervalMillis;
        proto.count = 1;
        proto.isManagedProfile = mPhone.isManagedProfile();
        return proto;
    }