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

Commit 433eaaf1 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8404621 from d3a59af2 to tm-release

Change-Id: I3041381e9353de21dde51d5df244633ce952c11b
parents a7d66b32 d3a59af2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -3987,6 +3987,19 @@ public class CallsManager extends Call.ListenerBase
        return false;
    }

    /**
     * Determines if there are any ongoing self managed calls for the given package/user.
     * @param packageName The package name to check.
     * @param userHandle The userhandle to check.
     * @return {@code true} if the app has ongoing calls, or {@code false} otherwise.
     */
    public boolean isInSelfManagedCall(String packageName, UserHandle userHandle) {
        return mCalls.stream().anyMatch(
                c -> c.isSelfManaged()
                && c.getTargetPhoneAccount().getComponentName().getPackageName().equals(packageName)
                && c.getTargetPhoneAccount().getUserHandle().equals(userHandle));
    }

    @VisibleForTesting
    public int getNumCallsWithState(final boolean isSelfManaged, Call excludeCall,
                                    PhoneAccountHandle phoneAccountHandle, int... states) {
+33 −0
Original line number Diff line number Diff line
@@ -2093,6 +2093,39 @@ public class TelecomServiceImpl {
                Log.endSession();
            }
        }

        /**
         * Determines whether there are any ongoing {@link PhoneAccount#CAPABILITY_SELF_MANAGED}
         * calls for a given {@code packageName} and {@code userHandle}.
         *
         * @param packageName the package name of the app to check calls for.
         * @param userHandle the user handle on which to check for calls.
         * @param callingPackage The caller's package name.
         * @return {@code true} if there are ongoing calls, {@code false} otherwise.
         */
        @Override
        public boolean isInSelfManagedCall(String packageName, UserHandle userHandle,
                String callingPackage) {
            try {
                if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                    throw new SecurityException("Only the system can call this API");
                }
                mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE,
                        "READ_PRIVILEGED_PHONE_STATE required.");

                Log.startSession("TSI.iISMC", Log.getPackageAbbreviation(callingPackage));
                synchronized (mLock) {
                    long token = Binder.clearCallingIdentity();
                    try {
                        return mCallsManager.isInSelfManagedCall(packageName, userHandle);
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }
                }
            } finally {
                Log.endSession();
            }
        }
    };

    /**
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class TestCallList extends Call.Callback {
    }

    public Call getCall(int position) {
        return mCalls.get(position);
        return (position < mCalls.size()) ? mCalls.get(position) : null;
    }

    public void addCall(Call call) {
+6 −3
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import static android.content.res.Configuration.UI_MODE_TYPE_CAR;

import android.app.Activity;
import android.app.UiModeManager;
import android.app.role.RoleManager;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
@@ -133,9 +134,11 @@ public class TestDialerActivity extends Activity {
    }

    private void setDefault() {
        final Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
        intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
        startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
        RoleManager roleManager = getSystemService(RoleManager.class);
        if(roleManager!= null) {
            startActivityForResult(roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER),
                    REQUEST_CODE_SET_DEFAULT_DIALER);
        }
    }

    private void placeCall() {
+51 −0
Original line number Diff line number Diff line
@@ -1625,6 +1625,57 @@ public class CallsManagerTest extends TelecomTestCase {
        verify(callSpy, never()).setDisconnectCause(any(DisconnectCause.class));
    }

    @Test
    public void testIsInSelfManagedCallOnlyManaged() {
        Call managedCall = createCall(SIM_1_HANDLE, CallState.ACTIVE);
        managedCall.setIsSelfManaged(false);
        mCallsManager.addCall(managedCall);

        // Certainly nothing from the self managed handle.
        assertFalse(mCallsManager.isInSelfManagedCall(
                SELF_MANAGED_HANDLE.getComponentName().getPackageName(),
                SELF_MANAGED_HANDLE.getUserHandle()));
        // And nothing in a random other package.
        assertFalse(mCallsManager.isInSelfManagedCall(
                "com.foo",
                SELF_MANAGED_HANDLE.getUserHandle()));
        // And this method is only checking self managed not managed.
        assertFalse(mCallsManager.isInSelfManagedCall(
                SIM_1_HANDLE.getComponentName().getPackageName(),
                SELF_MANAGED_HANDLE.getUserHandle()));
    }

    @Test
    public void testIsInSelfManagedCallOnlySelfManaged() {
        Call selfManagedCall = createCall(SELF_MANAGED_HANDLE, CallState.ACTIVE);
        selfManagedCall.setIsSelfManaged(true);
        mCallsManager.addCall(selfManagedCall);

        assertTrue(mCallsManager.isInSelfManagedCall(
                SELF_MANAGED_HANDLE.getComponentName().getPackageName(),
                SELF_MANAGED_HANDLE.getUserHandle()));
        assertFalse(mCallsManager.isInSelfManagedCall(
                "com.foo",
                SELF_MANAGED_HANDLE.getUserHandle()));
        assertFalse(mCallsManager.isInSelfManagedCall(
                SIM_1_HANDLE.getComponentName().getPackageName(),
                SELF_MANAGED_HANDLE.getUserHandle()));

        Call managedCall = createCall(SIM_1_HANDLE, CallState.ACTIVE);
        managedCall.setIsSelfManaged(false);
        mCallsManager.addCall(managedCall);

        // Still not including managed
        assertFalse(mCallsManager.isInSelfManagedCall(
                SIM_1_HANDLE.getComponentName().getPackageName(),
                SELF_MANAGED_HANDLE.getUserHandle()));

        // Also shouldn't be something in another user's version of the same package.
        assertFalse(mCallsManager.isInSelfManagedCall(
                SELF_MANAGED_HANDLE.getComponentName().getPackageName(),
                new UserHandle(90210)));
    }

    private Call addSpyCall() {
        return addSpyCall(SIM_2_HANDLE, CallState.ACTIVE);
    }