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

Commit f322925f authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Fix for incoming and outgoing call not starting as top app

By not starting the service as a top app it caused it to grab default
scheduling priority (non RT) for a good part of the initial flow until
an activity is created by dialer which adds signficant latency per the
linux scheduler behavior. By adding this flag we make the service
start as a top app and ensure RT scheduling is set when service is
bound.

Bug: 240343304
Test: Manual and trace analysis
Change-Id: I1ad4f4352ef99571227899b00b3ae1d7ffa219f9
parent fe56b47f
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -322,7 +322,8 @@ public class InCallController extends CallsManagerListenerBase implements
            mInCallServiceInfo.setBindingStartTime(mClockProxy.elapsedRealtime());
            mInCallServiceInfo.setBindingStartTime(mClockProxy.elapsedRealtime());
            if (!mContext.bindServiceAsUser(intent, mServiceConnection,
            if (!mContext.bindServiceAsUser(intent, mServiceConnection,
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                            | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS,
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS
                        | Context.BIND_SCHEDULE_LIKE_TOP_APP,
                    UserHandle.CURRENT)) {
                    UserHandle.CURRENT)) {
                Log.w(this, "Failed to connect.");
                Log.w(this, "Failed to connect.");
                mIsConnected = false;
                mIsConnected = false;
+29 −50
Original line number Original line Diff line number Diff line
@@ -181,6 +181,10 @@ public class InCallControllerTests extends TelecomTestCase {
    private SystemStateHelper.SystemStateListener mSystemStateListener;
    private SystemStateHelper.SystemStateListener mSystemStateListener;
    private CarModeTracker mCarModeTracker = spy(new CarModeTracker());
    private CarModeTracker mCarModeTracker = spy(new CarModeTracker());


    private final int serviceBindingFlags = Context.BIND_AUTO_CREATE
        | Context.BIND_FOREGROUND_SERVICE | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS
        | Context.BIND_SCHEDULE_LIKE_TOP_APP;

    @Override
    @Override
    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -354,8 +358,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext).bindServiceAsUser(
        verify(mMockContext).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -389,8 +392,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext).bindServiceAsUser(
        verify(mMockContext).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -442,8 +444,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -473,8 +474,7 @@ public class InCallControllerTests extends TelecomTestCase {
        when(mDefaultDialerCache.getDefaultDialerApplication(CURRENT_USER_ID))
        when(mDefaultDialerCache.getDefaultDialerApplication(CURRENT_USER_ID))
                .thenReturn(DEF_PKG);
                .thenReturn(DEF_PKG);
        when(mMockContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
        when(mMockContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT))).thenReturn(true);
                eq(UserHandle.CURRENT))).thenReturn(true);
        when(mTimeoutsAdapter.getEmergencyCallbackWindowMillis(any(ContentResolver.class)))
        when(mTimeoutsAdapter.getEmergencyCallbackWindowMillis(any(ContentResolver.class)))
                .thenReturn(300_000L);
                .thenReturn(300_000L);
@@ -502,8 +502,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -552,8 +551,7 @@ public class InCallControllerTests extends TelecomTestCase {
        ArgumentCaptor<ServiceConnection> serviceConnectionCaptor =
        ArgumentCaptor<ServiceConnection> serviceConnectionCaptor =
                ArgumentCaptor.forClass(ServiceConnection.class);
                ArgumentCaptor.forClass(ServiceConnection.class);
        when(mMockContext.bindServiceAsUser(any(Intent.class), serviceConnectionCaptor.capture(),
        when(mMockContext.bindServiceAsUser(any(Intent.class), serviceConnectionCaptor.capture(),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT))).thenReturn(true);
                eq(UserHandle.CURRENT))).thenReturn(true);
        when(mTimeoutsAdapter.getEmergencyCallbackWindowMillis(any(ContentResolver.class)))
        when(mTimeoutsAdapter.getEmergencyCallbackWindowMillis(any(ContentResolver.class)))
                .thenReturn(300_000L);
                .thenReturn(300_000L);
@@ -581,8 +579,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -611,8 +608,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(2)).bindServiceAsUser(
        verify(mMockContext, times(2)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        // Verify we were re-granted the runtime permission.
        // Verify we were re-granted the runtime permission.
@@ -666,8 +662,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                serviceConnectionCaptor.capture(),
                serviceConnectionCaptor.capture(),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -699,8 +694,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(2)).bindServiceAsUser(
        verify(mMockContext, times(2)).bindServiceAsUser(
                bindIntentCaptor2.capture(),
                bindIntentCaptor2.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        bindIntent = bindIntentCaptor2.getValue();
        bindIntent = bindIntentCaptor2.getValue();
@@ -756,8 +750,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(2)).bindServiceAsUser(
        verify(mMockContext, times(2)).bindServiceAsUser(
                bindIntentCaptor2.capture(),
                bindIntentCaptor2.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
        assertEquals(sysDialerComponentName, bindIntentCaptor2.getValue().getComponent());
        assertEquals(sysDialerComponentName, bindIntentCaptor2.getValue().getComponent());
    }
    }
@@ -791,8 +784,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        Intent bindIntent = bindIntentCaptor.getValue();
        Intent bindIntent = bindIntentCaptor.getValue();
@@ -830,8 +822,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                serviceConnectionCaptor.capture(),
                serviceConnectionCaptor.capture(),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        // Pretend that the call has gone away.
        // Pretend that the call has gone away.
@@ -879,8 +870,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
        // Verify bind car mode ui
        // Verify bind car mode ui
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        assertEquals(1, bindIntentCaptor.getAllValues().size());
@@ -908,8 +898,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
        // Verify bind to default package, instead of the invalid car mode ui.
        // Verify bind to default package, instead of the invalid car mode ui.
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        assertEquals(1, bindIntentCaptor.getAllValues().size());
@@ -952,8 +941,7 @@ public class InCallControllerTests extends TelecomTestCase {
            verify(mMockContext, times(2)).bindServiceAsUser(
            verify(mMockContext, times(2)).bindServiceAsUser(
                    bindIntentCaptor.capture(),
                    bindIntentCaptor.capture(),
                    any(ServiceConnection.class),
                    any(ServiceConnection.class),
                    eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                    eq(serviceBindingFlags),
                            | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                    eq(UserHandle.CURRENT));
                    eq(UserHandle.CURRENT));


            // Verify bind
            // Verify bind
@@ -997,8 +985,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        // Verify bind
        // Verify bind
@@ -1031,8 +1018,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                serviceConnectionCaptor.capture(),
                serviceConnectionCaptor.capture(),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        verifyBinding(bindIntentCaptor, 0, DEF_PKG, DEF_CLASS);
        verifyBinding(bindIntentCaptor, 0, DEF_PKG, DEF_CLASS);
@@ -1070,8 +1056,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext).bindServiceAsUser(
        verify(mMockContext).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
    }
    }


@@ -1102,8 +1087,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(4)).bindServiceAsUser(
        verify(mMockContext, times(4)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
        // Verify bind car mode ui
        // Verify bind car mode ui
        assertEquals(4, bindIntentCaptor.getAllValues().size());
        assertEquals(4, bindIntentCaptor.getAllValues().size());
@@ -1160,8 +1144,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(2)).bindServiceAsUser(
        verify(mMockContext, times(2)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                serviceConnectionCaptor.capture(),
                serviceConnectionCaptor.capture(),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        CompletableFuture<Boolean> bindTimeout = mInCallController.getBindingFuture();
        CompletableFuture<Boolean> bindTimeout = mInCallController.getBindingFuture();
@@ -1229,8 +1212,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, never()).bindServiceAsUser(
        verify(mMockContext, never()).bindServiceAsUser(
                any(Intent.class),
                any(Intent.class),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        // Now switch to car mode.
        // Now switch to car mode.
@@ -1242,8 +1224,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));
        // Verify bind car mode ui
        // Verify bind car mode ui
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        assertEquals(1, bindIntentCaptor.getAllValues().size());
@@ -1269,8 +1250,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, never()).bindServiceAsUser(
        verify(mMockContext, never()).bindServiceAsUser(
                any(Intent.class),
                any(Intent.class),
                any(ServiceConnection.class),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        // Now switch to car mode.
        // Now switch to car mode.
@@ -1287,8 +1267,7 @@ public class InCallControllerTests extends TelecomTestCase {
        verify(mMockContext, times(1)).bindServiceAsUser(
        verify(mMockContext, times(1)).bindServiceAsUser(
                any(Intent.class),
                any(Intent.class),
                serviceConnectionCaptor.capture(),
                serviceConnectionCaptor.capture(),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                eq(serviceBindingFlags),
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
                eq(UserHandle.CURRENT));


        ServiceConnection serviceConnection = serviceConnectionCaptor.getValue();
        ServiceConnection serviceConnection = serviceConnectionCaptor.getValue();