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

Commit 5d195895 authored by Rambo Wang's avatar Rambo Wang
Browse files

Permission READ_PRECISE_PHONE_STATE implementation polish

- Update the javadoc for all APIs that require this permission.
- Allow apps with carrier previleges to call the APIs without
permission.
- Add CTS test cases to verify that SecurityException thrown if call
the APIs without permission.

Bug: 146383220
Test: atest TelephonyRegistryTest PhoneStateListenerTest
Change-Id: I857a7cea182c580c56a8db7d9a49e2481f66a6da
parent b50e6cee
Loading
Loading
Loading
Loading
+41 −0
Original line number Original line Diff line number Diff line
@@ -291,4 +291,45 @@ public class TelephonyRegistryTest extends TelephonyTest {
        processAllMessages();
        processAllMessages();
        assertEquals(mPhoneStateListener.invocationCount.get(), 4);
        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) {
        }
    }
}
}