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

Commit 73ae62a6 authored by yongnamcha's avatar yongnamcha
Browse files

Updating the APIs for the emergency callback mode

This commit updates the APIs for the emergency callback mode.
This includes an updated implementation of TelephonyCallback.

Bug: 260533540
Bug: 359064059
Test: atest CtsTelephonyTestCases:TelephonyCallbackTest,
      atest CtsTelephonyTestCases:TelephonyRegistryManagerTest
Test: atest TelephonyRegistryTest, atest DefaultPhoneNotifierTest
Flag: com.android.internal.telephony.flags.emergency_callback_mode_notification

Change-Id: I60a4d1c080a39571cc939cee1448673b36895795
parent f0bab654
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -303,14 +303,28 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    }

    @Override
    public void notifyCallbackModeStarted(Phone sender, @EmergencyCallbackModeType int type) {
        mTelephonyRegistryMgr.notifyCallBackModeStarted(sender.getPhoneId(),
                sender.getSubId(), type);
    public void notifyCallbackModeStarted(Phone sender, @EmergencyCallbackModeType int type,
            long durationMillis) {
        if (!mFeatureFlags.emergencyCallbackModeNotification()) return;

        mTelephonyRegistryMgr.notifyCallbackModeStarted(sender.getPhoneId(),
                sender.getSubId(), type, durationMillis);
    }

    @Override
    public void notifyCallbackModeRestarted(Phone sender, @EmergencyCallbackModeType int type,
            long durationMillis) {
        if (!mFeatureFlags.emergencyCallbackModeNotification()) return;

        mTelephonyRegistryMgr.notifyCallbackModeRestarted(sender.getPhoneId(),
                sender.getSubId(), type, durationMillis);
    }

    @Override
    public void notifyCallbackModeStopped(Phone sender, @EmergencyCallbackModeType int type,
            @EmergencyCallbackModeStopReason int reason) {
        if (!mFeatureFlags.emergencyCallbackModeNotification()) return;

        mTelephonyRegistryMgr.notifyCallbackModeStopped(sender.getPhoneId(),
                sender.getSubId(), type, reason);
    }
+28 −7
Original line number Diff line number Diff line
@@ -5283,22 +5283,43 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    }

    /**
     * Start callback mode
     * Start the emergency callback mode
     * @param type for callback mode entry.
     * @param durationMillis is the number of milliseconds remaining in the emergency callback
     *                        mode.
     */
    public void startCallbackMode(@TelephonyManager.EmergencyCallbackModeType int type) {
        Rlog.d(mLogTag, "startCallbackMode:type=" + type);
        mNotifier.notifyCallbackModeStarted(this, type);
    public void startEmergencyCallbackMode(@TelephonyManager.EmergencyCallbackModeType int type,
            long durationMillis) {
        if (!mFeatureFlags.emergencyCallbackModeNotification()) return;

        Rlog.d(mLogTag, "startEmergencyCallbackMode:type=" + type);
        mNotifier.notifyCallbackModeStarted(this, type, durationMillis);
    }

    /**
     * Restart the emergency callback mode
     * @param type for callback mode entry.
     * @param durationMillis is the number of milliseconds remaining in the emergency callback
     *                        mode.
     */
    public void restartEmergencyCallbackMode(@TelephonyManager.EmergencyCallbackModeType int type,
            long durationMillis) {
        if (!mFeatureFlags.emergencyCallbackModeNotification()) return;

        Rlog.d(mLogTag, "restartEmergencyCallbackMode:type=" + type);
        mNotifier.notifyCallbackModeRestarted(this, type, durationMillis);
    }

    /**
     * Stop callback mode
     * Stop the emergency callback mode
     * @param type for callback mode exit.
     * @param reason for stopping callback mode.
     */
    public void stopCallbackMode(@TelephonyManager.EmergencyCallbackModeType int type,
    public void stopEmergencyCallbackMode(@TelephonyManager.EmergencyCallbackModeType int type,
            @TelephonyManager.EmergencyCallbackModeStopReason int reason) {
        Rlog.d(mLogTag, "stopCallbackMode:type=" + type + ", reason=" + reason);
        if (!mFeatureFlags.emergencyCallbackModeNotification()) return;

        Rlog.d(mLogTag, "stopEmergencyCallbackMode:type=" + type + ", reason=" + reason);
        mNotifier.notifyCallbackModeStopped(this, type, reason);
    }

+6 −1
Original line number Diff line number Diff line
@@ -145,7 +145,12 @@ public interface PhoneNotifier {
            List<LinkCapacityEstimate> linkCapacityEstimateList);

    /** Notify callback mode started. */
    void notifyCallbackModeStarted(Phone sender, @EmergencyCallbackModeType int type);
    void notifyCallbackModeStarted(Phone sender, @EmergencyCallbackModeType int type,
            long durationMillis);

    /** Notify callback mode restarted. */
    void notifyCallbackModeRestarted(Phone sender, @EmergencyCallbackModeType int type,
            long durationMillis);

    /** Notify callback mode stopped. */
    void notifyCallbackModeStopped(Phone sender, @EmergencyCallbackModeType int type,
+45 −0
Original line number Diff line number Diff line
@@ -376,6 +376,51 @@ public class DefaultPhoneNotifierTest extends TelephonyTest {
                eq(subs));
    }

    @Test
    @SmallTest
    public void testNotifyCallbackModeStarted() {
        doReturn(true).when(mFeatureFlags).emergencyCallbackModeNotification();
        int phoneId = mPhone.getPhoneId();
        int subId = mPhone.getSubId();
        int type = 1;
        long durationMillis = 1000;

        mDefaultPhoneNotifierUT.notifyCallbackModeStarted(mPhone, type, durationMillis);

        verify(mTelephonyRegistryManager).notifyCallbackModeStarted(eq(phoneId), eq(subId),
                eq(type), eq(durationMillis));
    }

    @Test
    @SmallTest
    public void testNotifyCallbackModeRestarted() {
        doReturn(true).when(mFeatureFlags).emergencyCallbackModeNotification();
        int phoneId = mPhone.getPhoneId();
        int subId = mPhone.getSubId();
        int type = 1;
        long durationMillis = 1000;

        mDefaultPhoneNotifierUT.notifyCallbackModeRestarted(mPhone, type, durationMillis);

        verify(mTelephonyRegistryManager).notifyCallbackModeRestarted(eq(phoneId), eq(subId),
                eq(type), eq(durationMillis));
    }

    @Test
    @SmallTest
    public void testNotifyCallbackModeStopped() {
        doReturn(true).when(mFeatureFlags).emergencyCallbackModeNotification();
        int phoneId = mPhone.getPhoneId();
        int subId = mPhone.getSubId();
        int type = 1;
        int reason = 0;

        mDefaultPhoneNotifierUT.notifyCallbackModeStopped(mPhone, type, reason);

        verify(mTelephonyRegistryManager).notifyCallbackModeStopped(eq(phoneId), eq(subId),
                eq(type), eq(reason));
    }

    @Test
    @SmallTest
    public void testCarrierRoamingNtnModeChanged() {
+76 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -123,6 +124,8 @@ public class TelephonyRegistryTest extends TelephonyTest {
    private CellIdentity mCellIdentityForRegiFail;
    private int mRegistrationFailReason;
    private Set<Integer> mSimultaneousCallingSubscriptions;
    private int mCallbackModeStopReason = TelephonyManager.STOP_REASON_UNKNOWN;
    private long mCallbackModeDurationMillis;
    private boolean mCarrierRoamingNtnMode;
    private boolean mCarrierRoamingNtnEligible;

@@ -201,6 +204,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
            TelephonyCallback.RegistrationFailedListener,
            TelephonyCallback.DataActivityListener,
            TelephonyCallback.SimultaneousCellularCallingSupportListener,
            TelephonyCallback.EmergencyCallbackModeListener,
            TelephonyCallback.CarrierRoamingNtnModeListener {
        // This class isn't mockable to get invocation counts because the IBinder is null and
        // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative.
@@ -297,6 +301,27 @@ public class TelephonyRegistryTest extends TelephonyTest {
            mSimultaneousCallingSubscriptions = simultaneousCallingSubscriptionIds;
        }

        @Override
        public void onCallbackModeStarted(@TelephonyManager.EmergencyCallbackModeType int type,
                @NonNull Duration timerDuration, int subId) {
            invocationCount.incrementAndGet();
            mCallbackModeDurationMillis = timerDuration.toMillis();
        }

        @Override
        public void onCallbackModeRestarted(@TelephonyManager.EmergencyCallbackModeType int type,
                @NonNull Duration timerDuration, int subId) {
            invocationCount.incrementAndGet();
            mCallbackModeDurationMillis = timerDuration.toMillis();
        }

        @Override
        public void onCallbackModeStopped(@TelephonyManager.EmergencyCallbackModeType int type,
                @TelephonyManager.EmergencyCallbackModeStopReason int reason, int subId) {
            invocationCount.incrementAndGet();
            mCallbackModeStopReason = reason;
        }

        @Override
        public void onCarrierRoamingNtnModeChanged(boolean active) {
            invocationCount.incrementAndGet();
@@ -1588,6 +1613,57 @@ public class TelephonyRegistryTest extends TelephonyTest {
        assertEquals(subIdSet, mSimultaneousCallingSubscriptions);
    }

    @Test
    @EnableFlags(Flags.FLAG_EMERGENCY_CALLBACK_MODE_NOTIFICATION)
    public void testNotifyCallbackModeStarted() {
        final long durationMillis = 1000;
        int[] events = {TelephonyCallback.EVENT_EMERGENCY_CALLBACK_MODE_CHANGED};

        mTelephonyRegistry.listenWithEventList(false, false, 1/*subId*/,
                mContext.getOpPackageName(), mContext.getAttributionTag(),
                mTelephonyCallback.callback, events, true);
        mTelephonyRegistry.notifyCallbackModeStarted(0/*phoneId*/, 1/*subId*/,
                TelephonyManager.EMERGENCY_CALLBACK_MODE_CALL, durationMillis);
        processAllMessages();

        assertEquals(1, mTelephonyCallback.invocationCount.get());
        assertEquals(durationMillis, mCallbackModeDurationMillis);
    }

    @Test
    @EnableFlags(Flags.FLAG_EMERGENCY_CALLBACK_MODE_NOTIFICATION)
    public void testNotifyCallbackModeReStarted() {
        final long durationMillis = 1000;
        int[] events = {TelephonyCallback.EVENT_EMERGENCY_CALLBACK_MODE_CHANGED};

        mTelephonyRegistry.listenWithEventList(false, false, 1/*subId*/,
                mContext.getOpPackageName(), mContext.getAttributionTag(),
                mTelephonyCallback.callback, events, true);
        mTelephonyRegistry.notifyCallbackModeRestarted(0/*phoneId*/, 1/*subId*/,
                TelephonyManager.EMERGENCY_CALLBACK_MODE_CALL, durationMillis);
        processAllMessages();

        assertEquals(1, mTelephonyCallback.invocationCount.get());
        assertEquals(durationMillis, mCallbackModeDurationMillis);
    }

    @Test
    @EnableFlags(Flags.FLAG_EMERGENCY_CALLBACK_MODE_NOTIFICATION)
    public void testNotifyCallbackModeStopped() {
        final int reason = TelephonyManager.STOP_REASON_OUTGOING_EMERGENCY_CALL_INITIATED;
        int[] events = {TelephonyCallback.EVENT_EMERGENCY_CALLBACK_MODE_CHANGED};

        mTelephonyRegistry.listenWithEventList(false, false, 1/*subId*/,
                mContext.getOpPackageName(), mContext.getAttributionTag(),
                mTelephonyCallback.callback, events, true);
        mTelephonyRegistry.notifyCallbackModeStopped(0/*phoneId*/, 1/*subId*/,
                TelephonyManager.EMERGENCY_CALLBACK_MODE_CALL, reason);
        processAllMessages();

        assertEquals(1, mTelephonyCallback.invocationCount.get());
        assertEquals(reason, mCallbackModeStopReason);
    }

    @Test
    public void testNotifyCarrierRoamingNtnModeChanged() {
        int subId = INVALID_SUBSCRIPTION_ID;