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

Commit 5e7ddc67 authored by Hakjun Choi's avatar Hakjun Choi
Browse files

add report satellite controller/provision metrics

reporting satellite controller atom parameter
  count for successful/failed service enablement
  count for successful/failed outgoing/incoming datagrams
  count for successful/failed SOS sms
  count for successful/failed location sharing
  count for successful/failed provision/deprovision
  total service up time
  total battery consumption percent while satellite (modem) is on
  total time when battery is being charged

reporting satellite provision atom parameter
  provision result code
  time to process provisioning
  whether provision/deprovision
  is requested canceled

Bug: 271792323
Test: flash and device test for controller parameter passing
Change-Id: Iddf9ffc0f0cb32b8792a5825b13173c87f629e2a
parent e3bd7336
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.metrics.SatelliteStats;
import com.android.internal.telephony.satellite.metrics.ControllerMetricsStats;

import java.util.LinkedHashMap;
import java.util.Map.Entry;
@@ -52,6 +53,7 @@ public class DatagramDispatcher extends Handler {
    @NonNull private static DatagramDispatcher sInstance;
    @NonNull private final Context mContext;
    @NonNull private final DatagramController mDatagramController;
    @NonNull private final ControllerMetricsStats mControllerMetricsStats;

    private static AtomicLong mNextDatagramId = new AtomicLong(0);

@@ -103,6 +105,7 @@ public class DatagramDispatcher extends Handler {
        super(looper);
        mContext = context;
        mDatagramController = datagramController;
        mControllerMetricsStats = ControllerMetricsStats.getInstance();

        synchronized (mLock) {
            mSendingDatagramInProgress = false;
@@ -236,6 +239,8 @@ public class DatagramDispatcher extends Handler {
                        mDatagramController.updateSendStatus(argument.subId,
                                SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_SEND_SUCCESS,
                                getPendingDatagramCount(), error);
                        mControllerMetricsStats.reportOutgoingDatagramSuccessCount(
                                argument.datagramType);

                        if (getPendingDatagramCount() != 0) {
                            // Send pending datagrams
@@ -245,10 +250,13 @@ public class DatagramDispatcher extends Handler {
                                    SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE,
                                    getPendingDatagramCount(),
                                    SatelliteManager.SATELLITE_ERROR_NONE);

                        }
                    } else {
                        // Abort sending all the pending datagrams
                        abortSendingPendingDatagrams(argument.subId, error);
                        mControllerMetricsStats.reportOutgoingDatagramFailCount(
                                argument.datagramType);
                    }
                }
                break;
@@ -352,6 +360,7 @@ public class DatagramDispatcher extends Handler {
            SendSatelliteDatagramArgument argument = entry.getValue();
            argument.callback.accept(errorCode);
            reportSendDatagramCompleted(argument, errorCode);
            mControllerMetricsStats.reportOutgoingDatagramFailCount(argument.datagramType);
        }

        // Clear pending datagram maps
+10 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.ILongConsumer;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.metrics.SatelliteStats;
import com.android.internal.telephony.satellite.metrics.ControllerMetricsStats;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
@@ -69,6 +70,7 @@ public class DatagramReceiver extends Handler {
    @NonNull private final ContentResolver mContentResolver;
    @NonNull private SharedPreferences mSharedPreferences = null;
    @NonNull private final DatagramController mDatagramController;
    @NonNull private final ControllerMetricsStats mControllerMetricsStats;

    private long mDatagramTransferStartTime = 0;

@@ -112,6 +114,7 @@ public class DatagramReceiver extends Handler {
        mContext = context;
        mContentResolver = context.getContentResolver();
        mDatagramController = datagramController;
        mControllerMetricsStats = ControllerMetricsStats.getInstance();

        HandlerThread backgroundThread = new HandlerThread(TAG);
        backgroundThread.start();
@@ -342,6 +345,9 @@ public class DatagramReceiver extends Handler {
                                    obtainMessage(EVENT_RETRY_DELIVERING_RECEIVED_DATAGRAM,
                                    argument), getTimeoutToReceiveAck());
                        });

                        sInstance.mControllerMetricsStats.reportIncomingDatagramCount(
                                SatelliteManager.SATELLITE_ERROR_NONE);
                    }

                    if (pendingCount == 0) {
@@ -412,8 +418,9 @@ public class DatagramReceiver extends Handler {
                            mDatagramController.getReceivePendingCount(),
                            SatelliteManager.SATELLITE_ERROR_NONE);

                    // report not able to poll pending datagrams
                    reportMetrics(null, SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
                    mControllerMetricsStats.reportIncomingDatagramCount(
                                    SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
                }
                break;
            }
@@ -430,7 +437,9 @@ public class DatagramReceiver extends Handler {
                    mDatagramController.updateReceiveStatus(request.subId,
                            SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_RECEIVE_FAILED,
                            mDatagramController.getReceivePendingCount(), error);

                    reportMetrics(null, error);
                    mControllerMetricsStats.reportIncomingDatagramCount(error);
                }
                break;
            }
+55 −1
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ import com.android.internal.telephony.IIntegerConsumer;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.satellite.metrics.ControllerMetricsStats;
import com.android.internal.telephony.satellite.metrics.ProvisionMetricsStats;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.util.FunctionalUtils;

@@ -100,6 +102,8 @@ public class SatelliteController extends Handler {
    @NonNull private SatelliteSessionController mSatelliteSessionController;
    @NonNull private final PointingAppController mPointingAppController;
    @NonNull private final DatagramController mDatagramController;
    @NonNull private final ControllerMetricsStats mControllerMetricsStats;
    @NonNull private final ProvisionMetricsStats mProvisionMetricsStats;
    private SharedPreferences mSharedPreferences = null;
    private final CommandsInterface mCi;

@@ -170,6 +174,7 @@ public class SatelliteController extends Handler {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected SatelliteController(@NonNull Context context, @NonNull Looper looper) {
        super(looper);

        mContext = context;
        Phone phone = SatelliteServiceUtils.getPhone();
        mCi = phone.mCi;
@@ -181,6 +186,12 @@ public class SatelliteController extends Handler {
        // which is used to manage interactions with PointingUI app.
        mPointingAppController = PointingAppController.make(mContext);

        // Create the SatelliteControllerMetrics to report controller metrics
        // should be called before making DatagramController
        loge("mControllerMetricsStats = ControllerMetricsStats.make(mContext);");
        mControllerMetricsStats = ControllerMetricsStats.make(mContext);
        mProvisionMetricsStats = ProvisionMetricsStats.getOrCreateInstance();

        // Create the DatagramController singleton,
        // which is used to send and receive satellite datagrams.
        mDatagramController = DatagramController.make(mContext, looper, mPointingAppController);
@@ -436,6 +447,8 @@ public class SatelliteController extends Handler {
                }
                mSatelliteProvisionCallbacks.put(argument.subId, argument.callback);
                onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
                // Log the current time for provision triggered
                mProvisionMetricsStats.setProvisioningStartTime();
                if (mSatelliteModemInterface.isSatelliteServiceSupported()) {
                    mSatelliteModemInterface.provisionSatelliteService(argument.token,
                            argument.regionId, onCompleted);
@@ -448,6 +461,11 @@ public class SatelliteController extends Handler {
                    loge("provisionSatelliteService: No phone object");
                    argument.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
                    notifyRequester(request);
                    mProvisionMetricsStats
                            .setResultCode(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE)
                            .reportProvisionMetrics();
                    mControllerMetricsStats.reportProvisionCount(
                            SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
                }
                break;
            }
@@ -468,6 +486,9 @@ public class SatelliteController extends Handler {
                ProvisionSatelliteServiceArgument argument =
                        (ProvisionSatelliteServiceArgument) request.argument;
                onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
                if (argument.callback != null) {
                    mProvisionMetricsStats.setProvisioningStartTime();
                }
                if (mSatelliteModemInterface.isSatelliteServiceSupported()) {
                    mSatelliteModemInterface
                            .deprovisionSatelliteService(argument.token, onCompleted);
@@ -481,6 +502,11 @@ public class SatelliteController extends Handler {
                    if (argument.callback != null) {
                        argument.callback.accept(
                                SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
                        mProvisionMetricsStats
                                .setResultCode(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE)
                                .reportProvisionMetrics();
                        mControllerMetricsStats.reportDeprovisionCount(
                                SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
                    }
                }
                break;
@@ -511,7 +537,7 @@ public class SatelliteController extends Handler {
                if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
                    if (argument.enableSatellite) {
                        //If satellite mode is enabled successfully, disable Bluetooth and wifi
                        disableBluetoothWifiState();;
                        disableBluetoothWifiState();
                    } else {
                        //Disabled satellite mode, Reset BT and Wifi if previously changed here
                        checkAndEnableBluetoothWifiState();
@@ -529,6 +555,17 @@ public class SatelliteController extends Handler {
                }
                argument.callback.accept(error);
                // TODO: if error is ERROR_NONE, request satellite capabilities

                if (argument.enableSatellite) {
                    if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
                        mControllerMetricsStats.onSatelliteEnabled();
                        mControllerMetricsStats.reportServiceEnablementSuccessCount();
                    } else {
                        mControllerMetricsStats.reportServiceEnablementFailCount();
                    }
                } else {
                    mControllerMetricsStats.onSatelliteDisabled();
                }
                break;
            }

@@ -564,6 +601,7 @@ public class SatelliteController extends Handler {
                        boolean enabled = ((int[]) ar.result)[0] == 1;
                        if (DBG) logd("isSatelliteEnabled: " + enabled);
                        bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
                        updateSatelliteEnabledState(enabled, "EVENT_IS_SATELLITE_ENABLED_DONE");
                    }
                }
                ((ResultReceiver) request.argument).send(error, bundle);
@@ -1008,6 +1046,7 @@ public class SatelliteController extends Handler {
            sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
                    new ProvisionSatelliteServiceArgument(token, regionId, null, validSubId),
                    phone);
            mProvisionMetricsStats.setIsCanceled(true);
        });
        return cancelTransport;
    }
@@ -1350,6 +1389,12 @@ public class SatelliteController extends Handler {
        if (callback == null) {
            loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
                    + arg.subId);
            mProvisionMetricsStats
                    .setResultCode(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE)
                    .setIsProvisionRequest(true)
                    .reportProvisionMetrics();
            mControllerMetricsStats.reportProvisionCount(
                    SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
            return;
        }
        callback.accept(result);
@@ -1364,6 +1409,11 @@ public class SatelliteController extends Handler {
         * TODO (b/267826133) we need to do this for all subscriptions on the device.
         */
        registerForSatelliteProvisionStateChanged(arg.subId, null);

        mProvisionMetricsStats.setResultCode(result)
                .setIsProvisionRequest(true)
                .reportProvisionMetrics();
        mControllerMetricsStats.reportProvisionCount(result);
    }

    private void handleEventDeprovisionSatelliteServiceDone(
@@ -1378,6 +1428,10 @@ public class SatelliteController extends Handler {

        if (arg.callback != null) {
            arg.callback.accept(result);
            mProvisionMetricsStats.setResultCode(result)
                    .setIsProvisionRequest(false)
                    .reportProvisionMetrics();
            mControllerMetricsStats.reportDeprovisionCount(result);
        }

        if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
+327 −0

File added.

Preview size limit exceeded, changes collapsed.

+110 −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.satellite.metrics;

import android.annotation.NonNull;
import android.telephony.satellite.SatelliteManager;
import android.util.Log;

import com.android.internal.telephony.metrics.SatelliteStats;

/**
 * Stats to log to satellite metrics
 */
public class ProvisionMetricsStats {
    private static final String TAG = ProvisionMetricsStats.class.getSimpleName();
    private static final boolean DBG = false;

    private static ProvisionMetricsStats sInstance = null;

    public static final int INVALID_TIME = -1;

    private int mResultCode;
    private int mProvisioningStartTimeSec;
    private boolean mIsProvisionRequest;
    private boolean mIsCanceled;

    private ProvisionMetricsStats() {
        initializeProvisionParams();
    }

    /**
     * Returns the Singleton instance of ProvisionMetricsStats class.
     * If an instance of the Singleton class has not been created,
     * it creates a new instance and returns it. Otherwise, it returns
     * the existing instance.
     * @return the Singleton instance of ProvisionMetricsStats
     */
    public static ProvisionMetricsStats getOrCreateInstance() {
        if (sInstance == null) {
            logd("Create new ProvisionMetricsStats.");
            sInstance = new ProvisionMetricsStats();
        }
        return sInstance;
    }

    /** Sets the resultCode for provision metrics */
    public ProvisionMetricsStats setResultCode(@SatelliteManager.SatelliteError int error) {
        mResultCode = error;
        return this;
    }

    /** Sets the start time of provisioning */
    public void setProvisioningStartTime() {
        mProvisioningStartTimeSec = (int) (System.currentTimeMillis() / 1000);
    }

    /** Sets the isProvisionRequest to indicate whether provision or de-provision */
    public ProvisionMetricsStats setIsProvisionRequest(boolean isProvisionRequest) {
        mIsProvisionRequest = isProvisionRequest;
        return this;
    }

    /** Sets the isCanceled to know whether the provision is canceled */
    public ProvisionMetricsStats setIsCanceled(boolean isCanceled) {
        mIsCanceled = isCanceled;
        return this;
    }

    /** Report the provision metrics atoms to PersistAtomsStorage in telephony */
    public void reportProvisionMetrics() {
        SatelliteStats.SatelliteProvisionParams provisionParams =
                new SatelliteStats.SatelliteProvisionParams.Builder()
                        .setResultCode(mResultCode)
                        .setProvisioningTimeSec((int)
                                (System.currentTimeMillis() / 1000) - mProvisioningStartTimeSec)
                        .setIsProvisionRequest(mIsProvisionRequest)
                        .setIsCanceled(mIsCanceled)
                        .build();
        SatelliteStats.getInstance().onSatelliteProvisionMetrics(provisionParams);
        logd(provisionParams.toString());
        initializeProvisionParams();
    }

    private void initializeProvisionParams() {
        mResultCode = -1;
        mProvisioningStartTimeSec = INVALID_TIME;
        mIsProvisionRequest = false;
        mIsCanceled = false;
    }

    private static void logd(@NonNull String log) {
        if (DBG) {
            Log.d(TAG, log);
        }
    }
}