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

Commit 1770fa95 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Permission READ_PRECISE_PHONE_STATE implementation polish" am:...

Merge "Permission READ_PRECISE_PHONE_STATE implementation polish" am: 7062b0f2 am: c8ee617b am: 792bd167

Change-Id: I2d9dc6b05cace46700bcc2c8e80f029bcc0af297
parents f0f38378 792bd167
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -296,4 +296,45 @@ public class TelephonyRegistryTest extends TelephonyTest {
        processAllMessages();
        assertEquals(mPhoneStateListener.invocationCount.get(), 4);
    }

    /**
     * Validate that SecuirtyException is thrown when we try to listen without permission
     * READ_PRECISE_PHONE_STATE.
     */
    @Test
    @SmallTest
    public void testListenWithoutPermission() {
        // Clear all permission grants for test.
        mContextFixture.addCallingOrSelfPermission("");

        assertThrowSecurityExceptionWhenListenWithoutPermission(
                PhoneStateListener.LISTEN_PRECISE_CALL_STATE,
                "LISTEN_PRECISE_CALL_STATE");

        assertThrowSecurityExceptionWhenListenWithoutPermission(
                PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE,
                "LISTEN_PRECISE_DATA_CONNECTION_STATE");

        assertThrowSecurityExceptionWhenListenWithoutPermission(
                PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES,
                "LISTEN_CALL_DISCONNECT_CAUSES");

        assertThrowSecurityExceptionWhenListenWithoutPermission(
                PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED,
                "LISTEN_CALL_ATTRIBUTES_CHANGED");

        assertThrowSecurityExceptionWhenListenWithoutPermission(
                PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES,
                "LISTEN_IMS_CALL_DISCONNECT_CAUSES");
    }

    private void assertThrowSecurityExceptionWhenListenWithoutPermission(int event,
            String eventDesc) {
        try {
            mTelephonyRegistry.listen(mContext.getOpPackageName(),
                    mPhoneStateListener.callback, event, true);
            fail("SecurityException should throw when listen " + eventDesc + " without permission");
        } catch (SecurityException expected) {
        }
    }
}