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

Commit 01793147 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10127524 from b9266470 to udc-release

Change-Id: I970d0ebdc5fffa69298bd3d0546bfc261e9b4419
parents 38140375 b9266470
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -274,6 +274,7 @@ message VoiceCallSession {
    optional bool is_multiparty = 31;
    optional int32 call_duration = 32;
    optional int32 last_known_rat = 33;

    // Internal use only
    optional int64 setup_begin_millis = 10001;
}
@@ -375,6 +376,7 @@ message CellularServiceState {
    optional int64 total_time_millis = 9; // Duration needs to be rounded when pulled
    optional bool is_emergency_only = 10;
    optional bool is_internet_pdn_up = 11;
    optional int32 fold_state = 12;

    // Internal use only
    optional int64 last_used_millis = 10001;
+11 −13
Original line number Diff line number Diff line
@@ -1695,16 +1695,9 @@ public class ServiceStateTracker extends Handler {
                                .findFirst()
                                .orElse(PhysicalChannelConfig.PHYSICAL_CELL_ID_UNKNOWN);
                    }
                    boolean includeLte = mCarrierConfig.getBoolean(CarrierConfigManager
                            .KEY_INCLUDE_LTE_FOR_NR_ADVANCED_THRESHOLD_BANDWIDTH_BOOL);
                    int[] bandwidths = new int[0];
                    if (list != null) {
                        bandwidths = list.stream()
                                .filter(config -> includeLte || config.getNetworkType()
                                        == TelephonyManager.NETWORK_TYPE_NR)
                                .map(PhysicalChannelConfig::getCellBandwidthDownlinkKhz)
                                .mapToInt(Integer::intValue)
                                .toArray();
                        bandwidths = getBandwidthsFromLastPhysicalChannelConfigs();
                    }
                    if (anchorNrCellId == mLastAnchorNrCellId
                            && anchorNrCellId != PhysicalChannelConfig.PHYSICAL_CELL_ID_UNKNOWN) {
@@ -1712,7 +1705,8 @@ public class ServiceStateTracker extends Handler {
                        hasChanged |= RatRatcheter.updateBandwidths(bandwidths, mSS);
                    } else {
                        log("Do not ratchet bandwidths since anchor NR cell is different ("
                                + mLastAnchorNrCellId + "->" + anchorNrCellId + ").");
                                + mLastAnchorNrCellId + " -> " + anchorNrCellId
                                + "). New bandwidths are " + Arrays.toString(bandwidths));
                        mLastAnchorNrCellId = anchorNrCellId;
                        hasChanged |= !Arrays.equals(mSS.getCellBandwidths(), bandwidths);
                        mSS.setCellBandwidths(bandwidths);
@@ -1796,8 +1790,12 @@ public class ServiceStateTracker extends Handler {
        return simAbsent;
    }

    private static int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) {
        return list.stream()
    private int[] getBandwidthsFromLastPhysicalChannelConfigs() {
        boolean includeLte = mCarrierConfig.getBoolean(
                CarrierConfigManager.KEY_INCLUDE_LTE_FOR_NR_ADVANCED_THRESHOLD_BANDWIDTH_BOOL);
        return mLastPhysicalChannelConfigList.stream()
                .filter(config -> includeLte
                        || config.getNetworkType() == TelephonyManager.NETWORK_TYPE_NR)
                .map(PhysicalChannelConfig::getCellBandwidthDownlinkKhz)
                .mapToInt(Integer::intValue)
                .toArray();
@@ -2557,7 +2555,7 @@ public class ServiceStateTracker extends Handler {
            // Prioritize the PhysicalChannelConfig list because we might already be in carrier
            // aggregation by the time poll state is performed.
            if (primaryPcc != null) {
                bandwidths = getBandwidthsFromConfigs(mLastPhysicalChannelConfigList);
                bandwidths = getBandwidthsFromLastPhysicalChannelConfigs();
                for (int bw : bandwidths) {
                    if (!isValidLteBandwidthKhz(bw)) {
                        loge("Invalid LTE Bandwidth in RegistrationState, " + bw);
@@ -2593,7 +2591,7 @@ public class ServiceStateTracker extends Handler {
            // Prioritize the PhysicalChannelConfig list because we might already be in carrier
            // aggregation by the time poll state is performed.
            if (primaryPcc != null) {
                bandwidths = getBandwidthsFromConfigs(mLastPhysicalChannelConfigList);
                bandwidths = getBandwidthsFromLastPhysicalChannelConfigs();
                for (int bw : bandwidths) {
                    if (!isValidNrBandwidthKhz(bw)) {
                        loge("Invalid NR Bandwidth in RegistrationState, " + bw);
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_CLOSED;
import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_FLIPPED;
import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_HALF_OPENED;
import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_OPENED;
import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_UNKNOWN;

import android.content.Context;
import android.hardware.devicestate.DeviceStateManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.HandlerThread;

import com.android.internal.telephony.Phone;

/** Device state information like the fold state. */
public class DeviceStateHelper {
    private int mFoldState = CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_UNKNOWN;

    public DeviceStateHelper(Context context) {
        HandlerThread mHandlerThread = new HandlerThread("DeviceStateHelperThread");
        mHandlerThread.start();
        context.getSystemService(DeviceStateManager.class)
                .registerCallback(
                        new HandlerExecutor(new Handler(mHandlerThread.getLooper())),
                        state -> {
                            updateFoldState(state);
                        });
    }

    private void updateFoldState(int posture) {
        switch (posture) {
            case 0:
                mFoldState = CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_CLOSED;
                break;
            case 1:
                mFoldState = CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_HALF_OPENED;
                break;
            case 2:
                mFoldState = CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_OPENED;
                break;
            case 4:
                mFoldState = CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_FLIPPED;
                break;
            default:
                mFoldState = CELLULAR_SERVICE_STATE__FOLD_STATE__STATE_UNKNOWN;
        }
        updateServiceStateStats();
    }

    private void updateServiceStateStats() {
        for (Phone phone : MetricsCollector.getPhonesIfAny()) {
            phone.getServiceStateTracker().getServiceStateStats().onFoldStateChanged(mFoldState);
        }
    }

    public int getFoldState() {
        return mFoldState;
    }
}
+13 −5
Original line number Diff line number Diff line
@@ -145,20 +145,22 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
            DBG ? 2L * MILLIS_PER_SECOND : 5L * MILLIS_PER_MINUTE;

    private final PersistAtomsStorage mStorage;
    private final DeviceStateHelper mDeviceStateHelper;
    private final StatsManager mStatsManager;
    private final AirplaneModeStats mAirplaneModeStats;
    private final Set<DataCallSessionStats> mOngoingDataCallStats = ConcurrentHashMap.newKeySet();
    private static final Random sRandom = new Random();

    public MetricsCollector(Context context) {
        this(context, new PersistAtomsStorage(context));
        this(context, new PersistAtomsStorage(context), new DeviceStateHelper(context));
    }

    /** Allows dependency injection. Used during unit tests. */
    @VisibleForTesting
    public MetricsCollector(Context context,
            PersistAtomsStorage storage) {
    public MetricsCollector(
            Context context, PersistAtomsStorage storage, DeviceStateHelper deviceStateHelper) {
        mStorage = storage;
        mDeviceStateHelper = deviceStateHelper;
        mStatsManager = (StatsManager) context.getSystemService(Context.STATS_MANAGER);
        if (mStatsManager != null) {
            // Most (but not all) of these are subject to cooldown specified by MIN_COOLDOWN_MILLIS.
@@ -299,6 +301,11 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
        return mStorage;
    }

    /** Returns the {@link DeviceStateHelper}. */
    public DeviceStateHelper getDeviceStateHelper() {
        return mDeviceStateHelper;
    }

    /** Updates duration segments and calls {@link PersistAtomsStorage#flushAtoms()}. */
    public void flushAtomsStorage() {
        concludeAll();
@@ -915,7 +922,8 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
                state.carrierId,
                roundAndConvertMillisToSeconds(state.totalTimeMillis),
                state.isEmergencyOnly,
                state.isInternetPdnUp);
                state.isInternetPdnUp,
                state.foldState);
    }

    private static StatsEvent buildStatsEvent(VoiceCallRatUsage usage) {
@@ -1316,7 +1324,7 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
    }

    /** Returns all phones in {@link PhoneFactory}, or an empty array if phones not made yet. */
    private static Phone[] getPhonesIfAny() {
    static Phone[] getPhonesIfAny() {
        try {
            return PhoneFactory.getPhones();
        } catch (IllegalStateException e) {
+3 −2
Original line number Diff line number Diff line
@@ -1708,7 +1708,8 @@ public class PersistAtomsStorage {
                    && state.isMultiSim == key.isMultiSim
                    && state.carrierId == key.carrierId
                    && state.isEmergencyOnly == key.isEmergencyOnly
                    && state.isInternetPdnUp == key.isInternetPdnUp) {
                    && state.isInternetPdnUp == key.isInternetPdnUp
                    && state.foldState == key.foldState) {
                return state;
            }
        }
Loading