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

Commit 9464c22d authored by Hyunho's avatar Hyunho
Browse files

Added new API to notify ECBM and SCBM status

Bug: b/260533540
Test: atest CtsTelephonyTestCases:TelephonyCallbackTest, TelephonyRegistryTest
Change-Id: I255074d867869b53cb91722b516a02c3c42e0037
parent 15c346f7
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SimActivationState;
import android.telephony.Annotation.SrvccState;
import android.telephony.TelephonyManager.DataEnabledReason;
import android.telephony.TelephonyManager.EmergencyCallbackModeStopReason;
import android.telephony.TelephonyManager.EmergencyCallbackModeType;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.ImsReasonInfo;
import android.telephony.ims.MediaQualityStatus;
@@ -1304,8 +1306,6 @@ public class PhoneStateListener {
        // default implementation empty
    }



    /**
     * The callback methods need to be called on the handler thread where
     * this object was created.  If the binder did that for us it'd be nice.
@@ -1669,6 +1669,18 @@ public class PhoneStateListener {
        public final void onMediaQualityStatusChanged(MediaQualityStatus mediaQualityStatus) {
            // not support. Can't override. Use TelephonyCallback.
        }

        /** @hide */
        public final void onCallBackModeStarted(
                @TelephonyManager.EmergencyCallbackModeType int type) {
            // not support. Can't override. Use TelephonyCallback.
        }

        /** @hide */
        public final void onCallBackModeStopped(@EmergencyCallbackModeType int type,
                @EmergencyCallbackModeStopReason int reason) {
            // not support. Can't override. Use TelephonyCallback.
        }
    }

    private void log(String s) {
+85 −1
Original line number Diff line number Diff line
@@ -612,6 +612,20 @@ public class TelephonyCallback {
    @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
    public static final int EVENT_MEDIA_QUALITY_STATUS_CHANGED = 39;


    /**
     * Event for changes to the Emergency callback mode
     *
     * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}
     *
     * @see EmergencyCallbackModeListener#onCallbackModeStarted(int)
     * @see EmergencyCallbackModeListener#onCallbackModeStopped(int, int)
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    public static final int EVENT_EMERGENCY_CALLBACK_MODE_CHANGED = 40;

    /**
     * @hide
     */
@@ -654,7 +668,8 @@ public class TelephonyCallback {
            EVENT_LEGACY_CALL_STATE_CHANGED,
            EVENT_LINK_CAPACITY_ESTIMATE_CHANGED,
            EVENT_TRIGGER_NOTIFY_ANBR,
            EVENT_MEDIA_QUALITY_STATUS_CHANGED
            EVENT_MEDIA_QUALITY_STATUS_CHANGED,
            EVENT_EMERGENCY_CALLBACK_MODE_CHANGED
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface TelephonyEvent {
@@ -1567,6 +1582,53 @@ public class TelephonyCallback {
        void onMediaQualityStatusChanged(@NonNull MediaQualityStatus mediaQualityStatus);
    }

    /**
     * Interface for emergency callback mode listener.
     *
     * @hide
     */
    public interface EmergencyCallbackModeListener {
        /**
         * Indicates that Callback Mode has been started.
         * <p>
         * This method will be called when an emergency sms/emergency call is sent
         * and the callback mode is supported by the carrier.
         * If an emergency SMS is transmitted during callback mode for SMS, this API will be called
         * once again with TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS.
         *
         * @param type for callback mode entry
         *             See {@link TelephonyManager.EmergencyCallbackModeType}.
         * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_CALL
         * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS
         */
        @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
        void onCallBackModeStarted(@TelephonyManager.EmergencyCallbackModeType int type);

        /**
         * Indicates that Callback Mode has been stopped.
         * <p>
         * This method will be called when the callback mode timer expires or when
         * a normal call/SMS is sent
         *
         * @param type for callback mode entry
         * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_CALL
         * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS
         *
         * @param reason for changing callback mode
         *
         * @see TelephonyManager#STOP_REASON_UNKNOWN
         * @see TelephonyManager#STOP_REASON_OUTGOING_NORMAL_CALL_INITIATED
         * @see TelephonyManager#STOP_REASON_NORMAL_SMS_SENT
         * @see TelephonyManager#STOP_REASON_OUTGOING_EMERGENCY_CALL_INITIATED
         * @see TelephonyManager#STOP_REASON_EMERGENCY_SMS_SENT
         * @see TelephonyManager#STOP_REASON_TIMER_EXPIRED
         * @see TelephonyManager#STOP_REASON_USER_ACTION
         */
        @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
        void onCallBackModeStopped(@TelephonyManager.EmergencyCallbackModeType int type,
                @TelephonyManager.EmergencyCallbackModeStopReason int reason);
    }

    /**
     * The callback methods need to be called on the handler thread where
     * this object was created.  If the binder did that for us it'd be nice.
@@ -1935,5 +1997,27 @@ public class TelephonyCallback {
                    () -> mExecutor.execute(() -> listener.onMediaQualityStatusChanged(
                            mediaQualityStatus)));
        }

        public void onCallBackModeStarted(@TelephonyManager.EmergencyCallbackModeType int type) {
            EmergencyCallbackModeListener listener =
                    (EmergencyCallbackModeListener) mTelephonyCallbackWeakRef.get();
            Log.d(LOG_TAG, "onCallBackModeStarted:type=" + type + ", listener=" + listener);
            if (listener == null) return;

            Binder.withCleanCallingIdentity(
                    () -> mExecutor.execute(() -> listener.onCallBackModeStarted(type)));
        }

        public void onCallBackModeStopped(@TelephonyManager.EmergencyCallbackModeType int type,
                @TelephonyManager.EmergencyCallbackModeStopReason int reason) {
            EmergencyCallbackModeListener listener =
                    (EmergencyCallbackModeListener) mTelephonyCallbackWeakRef.get();
            Log.d(LOG_TAG, "onCallBackModeStopped:type=" + type
                    + ", reason=" + reason + ", listener=" + listener);
            if (listener == null) return;

            Binder.withCleanCallingIdentity(
                    () -> mExecutor.execute(() -> listener.onCallBackModeStopped(type, reason)));
        }
    }
}
+44 −0
Original line number Diff line number Diff line
@@ -1113,6 +1113,11 @@ public class TelephonyRegistryManager {
            eventList.add(TelephonyCallback.EVENT_MEDIA_QUALITY_STATUS_CHANGED);
        }

        if (telephonyCallback instanceof TelephonyCallback.EmergencyCallbackModeListener) {
            eventList.add(TelephonyCallback.EVENT_EMERGENCY_CALLBACK_MODE_CHANGED);
        }


        return eventList;
    }

@@ -1539,4 +1544,43 @@ public class TelephonyRegistryManager {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Notify Callback Mode has been started.
     * @param phoneId Sender phone ID.
     * @param subId Sender subscription ID.
     * @param type for callback mode entry.
     *             See {@link TelephonyManager.EmergencyCallbackModeType}.
     */
    public void notifyCallBackModeStarted(int phoneId, int subId,
            @TelephonyManager.EmergencyCallbackModeType int type) {
        try {
            Log.d(TAG, "notifyCallBackModeStarted:type=" + type);
            sRegistry.notifyCallbackModeStarted(phoneId, subId, type);
        } catch (RemoteException ex) {
            // system process is dead
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Notify Callback Mode has been stopped.
     * @param phoneId Sender phone ID.
     * @param subId Sender subscription ID.
     * @param type for callback mode entry.
     *             See {@link TelephonyManager.EmergencyCallbackModeType}.
     * @param reason for changing callback mode.
     *             See {@link TelephonyManager.EmergencyCallbackModeStopReason}.
     */
    public void notifyCallbackModeStopped(int phoneId, int subId,
            @TelephonyManager.EmergencyCallbackModeType int type,
            @TelephonyManager.EmergencyCallbackModeStopReason int reason) {
        try {
            Log.d(TAG, "notifyCallbackModeStopped:type=" + type + ", reason=" + reason);
            sRegistry.notifyCallbackModeStopped(phoneId, subId, type, reason);
        } catch (RemoteException ex) {
            // system process is dead
            throw ex.rethrowFromSystemServer();
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -78,4 +78,6 @@ oneway interface IPhoneStateListener {
    void onAllowedNetworkTypesChanged(in int reason, in long allowedNetworkType);
    void onLinkCapacityEstimateChanged(in List<LinkCapacityEstimate> linkCapacityEstimateList);
    void onMediaQualityStatusChanged(in MediaQualityStatus mediaQualityStatus);
    void onCallBackModeStarted(int type);
    void onCallBackModeStopped(int type, int reason);
}
+3 −0
Original line number Diff line number Diff line
@@ -117,4 +117,7 @@ interface ITelephonyRegistry {
            String pkg, String featureId);
    void removeCarrierConfigChangeListener(ICarrierConfigChangeListener listener, String pkg);
    void notifyCarrierConfigChanged(int phoneId, int subId, int carrierId, int specificCarrierId);

    void notifyCallbackModeStarted(int phoneId, int subId, int type);
    void notifyCallbackModeStopped(int phoneId, int subId, int type, int reason);
}
Loading