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

Commit c8d912f6 authored by zxuan's avatar zxuan Committed by android-build-merger
Browse files

Merge "Notify the listener when user change the mobile data status toggle."...

Merge "Notify the listener when user change the mobile data status toggle." am: 64c6af7e am: 95e91330
am: 0a71a180

Change-Id: I3682d35b2598d6a33ae1d29773c40c128ddc323f
parents 865116e1 0a71a180
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -309,6 +309,16 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
        }
    }

    @Override
    public void notifyUserMobileDataStateChanged(Phone sender, boolean state) {
        try {
            mRegistry.notifyUserMobileDataStateChangedForPhoneId(
                    sender.getPhoneId(), sender.getSubId(), state);
        } catch (RemoteException ex) {
            // system process is dead
        }
    }

    /**
     * Convert the {@link Phone.DataActivityState} enum into the TelephonyManager.DATA_* constants
     * for the public API.
+4 −0
Original line number Diff line number Diff line
@@ -2120,6 +2120,10 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mNotifier.notifyDataActivationStateChanged(this, state);
    }

    public void notifyUserMobileDataStateChanged(boolean state) {
        mNotifier.notifyUserMobileDataStateChanged(this, state);
    }

    public void notifySignalStrength() {
        mNotifier.notifySignalStrength(this);
    }
+2 −0
Original line number Diff line number Diff line
@@ -62,4 +62,6 @@ public interface PhoneNotifier {
    public void notifyVoiceActivationStateChanged(Phone sender, int activationState);

    public void notifyDataActivationStateChanged(Phone sender, int activationState);

    public void notifyUserMobileDataStateChanged(Phone sender, boolean state);
}
+2 −0
Original line number Diff line number Diff line
@@ -812,6 +812,8 @@ public class DcTracker extends Handler {
                    }
                }

                mPhone.notifyUserMobileDataStateChanged(enabled);

                // TODO: We should register for DataEnabledSetting's data enabled/disabled event and
                // handle the rest from there.
                if (enabled) {
+24 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import static org.mockito.Mockito.verify;

@@ -29,6 +31,7 @@ public class PhoneStateListenerTest extends TelephonyTest {

    private PhoneStateListener mPhoneStateListenerUT;
    private PhoneStateListenerHandler mPhoneStateListenerHandler;
    private boolean mUserMobileDataState = false;

    private class PhoneStateListenerHandler extends HandlerThread {
        private PhoneStateListenerHandler(String name) {
@@ -45,6 +48,13 @@ public class PhoneStateListenerTest extends TelephonyTest {
                    mServiceState.setDataRegState(serviceState.getDataRegState());
                    setReady(true);
                }

                @Override
                public void onUserMobileDataStateChanged(boolean state) {
                    logd("User Mobile Data State Changed");
                    mUserMobileDataState = true;
                    setReady(true);
                }
            };
            setReady(true);
        }
@@ -81,4 +91,18 @@ public class PhoneStateListenerTest extends TelephonyTest {
        verify(mServiceState).setVoiceRegState(ServiceState.STATE_EMERGENCY_ONLY);
    }

    @Test @SmallTest
    public void testTriggerUserMobileDataStateChanged() throws Exception {
        Field field = PhoneStateListener.class.getDeclaredField("callback");
        field.setAccessible(true);

        assertFalse(mUserMobileDataState);

        setReady(false);
        ((IPhoneStateListener) field.get(mPhoneStateListenerUT)).onUserMobileDataStateChanged(true);
        waitUntilReady();

        assertTrue(mUserMobileDataState);
    }

}
Loading