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

Commit a84e2e89 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix issue where system rings even if default dialer can play ringtone.

A few issues:
1. The InCallController wasn't actually tracking which UI was bound.
This turns out to be easy enough to determine using the list of
mInCallServices.
2. The static DefaultDialerManager.getDefaultDialerApplication method
was being used to get the default dialer, where there is already a local
instance of default dialer manager in InCallController.

Bug: 116871247
Test: Install dialer which is able to support ringing; verify system no
longer rings.
Test: Install dialer which does not support ringing; verify system rings.

Change-Id: I82998a318587061d930e07f1f6c132c5b31743b4
parent 38a8b9c5
Loading
Loading
Loading
Loading
+32 −9
Original line number Diff line number Diff line
@@ -716,11 +716,6 @@ public class InCallController extends CallsManagerListenerBase {
    /** The in-call app implementations, see {@link IInCallService}. */
    private final Map<InCallServiceInfo, IInCallService> mInCallServices = new ArrayMap<>();

    /**
     * The {@link ComponentName} of the bound In-Call UI Service.
     */
    private ComponentName mInCallUIComponentName;

    private final CallIdMapper mCallIdMapper = new CallIdMapper(Call::getId);

    /** The {@link ComponentName} of the default InCall UI. */
@@ -1463,18 +1458,42 @@ public class InCallController extends CallsManagerListenerBase {
        pw.decreaseIndent();
    }

    /**
     * @return The package name of the UI which is currently bound, or null if none.
     */
    private ComponentName getConnectedUi() {
        InCallServiceInfo connectedUi = mInCallServices.keySet().stream().filter(
                i -> i.getType() == IN_CALL_SERVICE_TYPE_DIALER_UI
                        || i.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI)
                .findAny()
                .orElse(null);
        if (connectedUi != null) {
            return connectedUi.mComponentName;
        }
        return null;
    }

    public boolean doesConnectedDialerSupportRinging() {
        String ringingPackage =  null;
        if (mInCallUIComponentName != null) {
            ringingPackage = mInCallUIComponentName.getPackageName().trim();

        ComponentName connectedPackage = getConnectedUi();
        if (connectedPackage != null) {
            ringingPackage = connectedPackage.getPackageName().trim();
            Log.d(this, "doesConnectedDialerSupportRinging: alreadyConnectedPackage=%s",
                    ringingPackage);
        }

        if (TextUtils.isEmpty(ringingPackage)) {
            // The current in-call UI returned nothing, so lets use the default dialer.
            ringingPackage = DefaultDialerManager.getDefaultDialerApplication(
                    mContext, UserHandle.USER_CURRENT);
            ringingPackage = mDefaultDialerCache.getDefaultDialerApplication(
                    mCallsManager.getCurrentUserHandle().getIdentifier());
            if (ringingPackage != null) {
                Log.d(this, "doesConnectedDialerSupportRinging: notCurentlyConnectedPackage=%s",
                        ringingPackage);
            }
        }
        if (TextUtils.isEmpty(ringingPackage)) {
            Log.w(this, "doesConnectedDialerSupportRinging: no default dialer found; oh no!");
            return false;
        }

@@ -1484,11 +1503,15 @@ public class InCallController extends CallsManagerListenerBase {
                intent, PackageManager.GET_META_DATA,
                mCallsManager.getCurrentUserHandle().getIdentifier());
        if (entries.isEmpty()) {
            Log.w(this, "doesConnectedDialerSupportRinging: couldn't find dialer's package info"
                    + " <sad trombone>");
            return false;
        }

        ResolveInfo info = entries.get(0);
        if (info.serviceInfo == null || info.serviceInfo.metaData == null) {
            Log.w(this, "doesConnectedDialerSupportRinging: couldn't find dialer's metadata"
                    + " <even sadder trombone>");
            return false;
        }