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

Commit 41275ecc authored by Amit Mahajan's avatar Amit Mahajan Committed by android-build-merger
Browse files

Merge "Change to release wakelock on ECM exit in ImsPhone." into nyc-dev

am: 8af04cc8

* commit '8af04cc8':
  Change to release wakelock on ECM exit in ImsPhone.
parents 7d00b6f9 8af04cc8
Loading
Loading
Loading
Loading
+31 −9
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import static com.android.internal.telephony.CommandsInterface.CF_REASON_UNCONDI
import static com.android.internal.telephony.CommandsInterface.SERVICE_CLASS_VOICE;
import static com.android.internal.telephony.CommandsInterface.SERVICE_CLASS_NONE;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallForwardInfo;
import com.android.internal.telephony.CallStateException;
@@ -167,9 +168,14 @@ public class ImsPhone extends ImsPhoneBase {
    }

    // Constructors

    public ImsPhone(Context context, PhoneNotifier notifier, Phone defaultPhone) {
        super("ImsPhone", context, notifier);
        this(context, notifier, defaultPhone, false);
    }

    @VisibleForTesting
    public ImsPhone(Context context, PhoneNotifier notifier, Phone defaultPhone,
                    boolean unitTestMode) {
        super("ImsPhone", context, notifier, unitTestMode);

        mDefaultPhone = defaultPhone;
        mCT = TelephonyComponentFactory.getInstance().makeImsPhoneCallTracker(this);
@@ -1204,7 +1210,7 @@ public class ImsPhone extends ImsPhoneBase {
    /**
     * Listen to the IMS ECBM state change
     */
    ImsEcbmStateListener mImsEcbmStateListener =
    private ImsEcbmStateListener mImsEcbmStateListener =
            new ImsEcbmStateListener() {
                @Override
                public void onECBMEntered() {
@@ -1219,6 +1225,11 @@ public class ImsPhone extends ImsPhoneBase {
                }
            };

    @VisibleForTesting
    public ImsEcbmStateListener getImsEcbmStateListener() {
        return mImsEcbmStateListener;
    }

    @Override
    public boolean isInEmergencyCall() {
        return mCT.isInEmergencyCall();
@@ -1288,6 +1299,12 @@ public class ImsPhone extends ImsPhoneBase {
        if (mEcmExitRespRegistrant != null) {
            mEcmExitRespRegistrant.notifyResult(Boolean.TRUE);
        }

        // release wakeLock
        if (mWakeLock.isHeld()) {
            mWakeLock.release();
        }

        if (mIsPhoneInEcmState) {
            mIsPhoneInEcmState = false;
            setSystemProperty(TelephonyProperties.PROPERTY_INECM_MODE, "false");
@@ -1497,6 +1514,11 @@ public class ImsPhone extends ImsPhoneBase {
        mDefaultPhone.setBroadcastEmergencyCallStateChanges(broadcast);
    }

    @VisibleForTesting
    public PowerManager.WakeLock getWakeLock() {
        return mWakeLock;
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("ImsPhone extends:");
+3 −2
Original line number Diff line number Diff line
@@ -54,8 +54,9 @@ abstract class ImsPhoneBase extends Phone {
    private RegistrantList mTtyModeReceivedRegistrants = new RegistrantList();
    private PhoneConstants.State mState = PhoneConstants.State.IDLE;

    public ImsPhoneBase(String name, Context context, PhoneNotifier notifier) {
        super(name, notifier, context, new ImsPhoneCommandInterface(context), false);
    public ImsPhoneBase(String name, Context context, PhoneNotifier notifier,
                        boolean unitTestMode) {
        super(name, notifier, context, new ImsPhoneCommandInterface(context), unitTestMode);
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ public class ImsPhoneCallTracker extends CallTracker {
            mImsManager.setImsConfigListener(mImsConfigListener);

            // Get the ECBM interface and set IMSPhone's listener object for notifications
            getEcbmInterface().setEcbmStateListener(mPhone.mImsEcbmStateListener);
            getEcbmInterface().setEcbmStateListener(mPhone.getImsEcbmStateListener());
            if (mPhone.isInEcm()) {
                // Call exit ECBM which will invoke onECBMExited
                mPhone.exitEmergencyCallbackMode();
+79 −5
Original line number Diff line number Diff line
@@ -16,7 +16,12 @@

package com.android.internal.telephony.imsphone;

import android.app.Activity;
import android.app.IApplicationThread;
import android.content.IIntentReceiver;
import android.content.Intent;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
@@ -24,6 +29,7 @@ import android.os.SystemProperties;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.ims.ImsCallProfile;
import com.android.ims.ImsEcbmStateListener;
import com.android.ims.ImsStreamMediaProfile;
import com.android.ims.ImsUtInterface;
import com.android.internal.telephony.Call;
@@ -32,6 +38,7 @@ import com.android.internal.telephony.Connection;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneInternalInterface;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.gsm.SuppServiceNotification;
@@ -56,6 +63,7 @@ import static org.mockito.Matchers.anyChar;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
@@ -80,8 +88,7 @@ public class ImsPhoneTest extends TelephonyTest {
    private static final int EVENT_SUPP_SERVICE_NOTIFICATION = 1;
    private static final int EVENT_SUPP_SERVICE_FAILED = 2;
    private static final int EVENT_INCOMING_RING = 3;
    private static final int EVENT_OUTGOING_CALLER_ID_DISPLAY_RESP = 4;
    private static final int EVENT_CALL_FORWARDING_OPTION_RESP = 5;
    private static final int EVENT_EMERGENCY_CALLBACK_MODE_EXIT = 4;

    private class ImsPhoneTestHandler extends HandlerThread {

@@ -91,7 +98,7 @@ public class ImsPhoneTest extends TelephonyTest {

        @Override
        public void onLooperPrepared() {
            mImsPhoneUT = new ImsPhone(mContext, mNotifier, mPhone);
            mImsPhoneUT = new ImsPhone(mContext, mNotifier, mPhone, true);
            setReady(true);
        }
    }
@@ -492,4 +499,71 @@ public class ImsPhoneTest extends TelephonyTest {
                (String[])eq(null));
        assertEquals(msg, messageArgumentCaptor.getValue().obj);
    }

    @Test
    @SmallTest
    public void testEcbm() throws Exception {
        ImsEcbmStateListener imsEcbmStateListener = mImsPhoneUT.getImsEcbmStateListener();

        // verify handling of emergency callback mode
        imsEcbmStateListener.onECBMEntered();

        // verify ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mIActivityManager, atLeast(1)).broadcastIntent(eq((IApplicationThread)null),
                intentArgumentCaptor.capture(),
                eq((String)null),
                eq((IIntentReceiver)null),
                eq(Activity.RESULT_OK),
                eq((String)null),
                eq((Bundle)null),
                eq((String[])null),
                anyInt(),
                eq((Bundle)null),
                eq(false),
                eq(true),
                anyInt());

        Intent intent = intentArgumentCaptor.getValue();
        assertEquals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, intent.getAction());
        assertEquals(true, intent.getBooleanExtra(PhoneConstants.PHONE_IN_ECM_STATE, false));

        // verify that wakeLock is acquired in ECM
        assertEquals(true, mImsPhoneUT.getWakeLock().isHeld());

        mImsPhoneUT.setOnEcbModeExitResponse(mTestHandler, EVENT_EMERGENCY_CALLBACK_MODE_EXIT,
                null);

        // verify handling of emergency callback mode exit
        imsEcbmStateListener.onECBMExited();

        // verify ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
        verify(mIActivityManager, atLeast(2)).broadcastIntent(eq((IApplicationThread)null),
                intentArgumentCaptor.capture(),
                eq((String)null),
                eq((IIntentReceiver)null),
                eq(Activity.RESULT_OK),
                eq((String)null),
                eq((Bundle)null),
                eq((String[])null),
                anyInt(),
                eq((Bundle)null),
                eq(false),
                eq(true),
                anyInt());

        intent = intentArgumentCaptor.getValue();
        assertEquals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, intent.getAction());
        assertEquals(false, intent.getBooleanExtra(PhoneConstants.PHONE_IN_ECM_STATE, true));

        ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);

        // verify EcmExitRespRegistrant is notified
        verify(mTestHandler).sendMessageAtTime(messageArgumentCaptor.capture(),
                anyLong());
        assertEquals(EVENT_EMERGENCY_CALLBACK_MODE_EXIT, messageArgumentCaptor.getValue().what);

        // verify wakeLock released
        assertEquals(false, mImsPhoneUT.getWakeLock().isHeld());
    }
}