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

Commit 0edfc66e authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Send PhoneAccount register/unregistered intents to default dialer.

A few cleanups:
1. When sending the register/unregister phone account intents, previously
there was no attempt made to ensure the intents were only sent when a
new account was added, or an existing one was removed.  Cleaned this up
so that we don't over-send the intents.
2. Minor fix to account diff string in PhoneAccountRegistrar which would
cause icon to always be shown as a diff; removed since bitmaps can't be
compared.
3. Also sending the intents to the default dialer app as an explicit
intent.

Test: Manual
Bug: 37106957
Merged-In: I7fdaa3e225df6fe3aaf292f9b0b93042f69ca469
Change-Id: I7fdaa3e225df6fe3aaf292f9b0b93042f69ca469
parent baf105bf
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
@@ -143,6 +143,9 @@ public class CallsManager extends Call.ListenerBase
     */
    private static final int CALL_FILTER_ALL = 3;

    private static final String PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION =
            "android.permission.PROCESS_PHONE_ACCOUNT_REGISTRATION";

    private static final int HANDLER_WAIT_TIMEOUT = 10000;
    private static final int MAXIMUM_LIVE_CALLS = 1;
    private static final int MAXIMUM_HOLD_CALLS = 1;
@@ -260,6 +263,21 @@ public class CallsManager extends Call.ListenerBase

    private Runnable mStopTone;

    /**
     * Listener to PhoneAccountRegistrar events.
     */
    private PhoneAccountRegistrar.Listener mPhoneAccountListener =
            new PhoneAccountRegistrar.Listener() {
        public void onPhoneAccountRegistered(PhoneAccountRegistrar registrar,
                                             PhoneAccountHandle handle) {
            broadcastRegisterIntent(handle);
        }
        public void onPhoneAccountUnRegistered(PhoneAccountRegistrar registrar,
                                               PhoneAccountHandle handle) {
            broadcastUnregisterIntent(handle);
        }
    };

    /**
     * Initializes the required Telecom components.
     */
@@ -288,6 +306,7 @@ public class CallsManager extends Call.ListenerBase
        mContactsAsyncHelper = contactsAsyncHelper;
        mCallerInfoAsyncQueryFactory = callerInfoAsyncQueryFactory;
        mPhoneAccountRegistrar = phoneAccountRegistrar;
        mPhoneAccountRegistrar.addListener(mPhoneAccountListener);
        mMissedCallNotifier = missedCallNotifier;
        StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this);
        mWiredHeadsetManager = wiredHeadsetManager;
@@ -2737,4 +2756,48 @@ public class CallsManager extends Call.ListenerBase
            service.createConnectionFailed(call);
        }
    }

    private void broadcastUnregisterIntent(PhoneAccountHandle accountHandle) {
        Intent intent =
                new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED);
        intent.putExtra(
                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
        Log.i(this, "Sending phone-account %s unregistered intent as user", accountHandle);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
                PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION);

        String dialerPackage = mDefaultDialerCache.getDefaultDialerApplication(
                getCurrentUserHandle().getIdentifier());
        if (!TextUtils.isEmpty(dialerPackage)) {
            Intent directedIntent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED)
                    .setPackage(dialerPackage);
            directedIntent.putExtra(
                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
            Log.i(this, "Sending phone-account unregistered intent to default dialer");
            mContext.sendBroadcastAsUser(directedIntent, UserHandle.ALL, null);
        }
        return ;
    }

    private void broadcastRegisterIntent(PhoneAccountHandle accountHandle) {
        Intent intent = new Intent(
                TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED);
        intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
                accountHandle);
        Log.i(this, "Sending phone-account %s registered intent as user", accountHandle);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
                PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION);

        String dialerPackage = mDefaultDialerCache.getDefaultDialerApplication(
                getCurrentUserHandle().getIdentifier());
        if (!TextUtils.isEmpty(dialerPackage)) {
            Intent directedIntent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED)
                    .setPackage(dialerPackage);
            directedIntent.putExtra(
                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
            Log.i(this, "Sending phone-account registered intent to default dialer");
            mContext.sendBroadcastAsUser(directedIntent, UserHandle.ALL, null);
        }
        return ;
    }
}
+24 −2
Original line number Diff line number Diff line
@@ -120,6 +120,10 @@ public class PhoneAccountRegistrar {
        public void onAccountsChanged(PhoneAccountRegistrar registrar) {}
        public void onDefaultOutgoingChanged(PhoneAccountRegistrar registrar) {}
        public void onSimCallManagerChanged(PhoneAccountRegistrar registrar) {}
        public void onPhoneAccountRegistered(PhoneAccountRegistrar registrar,
                                             PhoneAccountHandle handle) {}
        public void onPhoneAccountUnRegistered(PhoneAccountRegistrar registrar,
                                             PhoneAccountHandle handle) {}
    }

    /**
@@ -652,14 +656,17 @@ public class PhoneAccountRegistrar {
        // !!! IMPORTANT !!! It is important that we do not read the enabled state that the
        // source app provides or else an third party app could enable itself.
        boolean isEnabled = false;
        boolean isNewAccount;

        PhoneAccount oldAccount = getPhoneAccountUnchecked(account.getAccountHandle());
        if (oldAccount != null) {
            mState.accounts.remove(oldAccount);
            isEnabled = oldAccount.isEnabled();
            Log.i(this, getAccountDiffString(account, oldAccount));
            Log.i(this, "Modify account: %s", getAccountDiffString(account, oldAccount));
            isNewAccount = false;
        } else {
            Log.i(this, "New phone account registered: " + account);
            isNewAccount = true;
        }

        // When registering a self-managed PhoneAccount we enforce the rule that the label that the
@@ -695,6 +702,9 @@ public class PhoneAccountRegistrar {

        write();
        fireAccountsChanged();
        if (isNewAccount) {
            fireAccountRegistered(account.getAccountHandle());
        }
    }

    public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
@@ -703,6 +713,7 @@ public class PhoneAccountRegistrar {
            if (mState.accounts.remove(account)) {
                write();
                fireAccountsChanged();
                fireAccountUnRegistered(accountHandle);
            }
        }
    }
@@ -748,6 +759,18 @@ public class PhoneAccountRegistrar {
        }
    }

    private void fireAccountRegistered(PhoneAccountHandle handle) {
        for (Listener l : mListeners) {
            l.onPhoneAccountRegistered(this, handle);
        }
    }

    private void fireAccountUnRegistered(PhoneAccountHandle handle) {
        for (Listener l : mListeners) {
            l.onPhoneAccountUnRegistered(this, handle);
        }
    }

    private void fireAccountsChanged() {
        for (Listener l : mListeners) {
            l.onAccountsChanged(this);
@@ -771,7 +794,6 @@ public class PhoneAccountRegistrar {
                Log.piiHandle(account2.getAddress()));
        appendDiff(sb, "cap", account1.getCapabilities(), account2.getCapabilities());
        appendDiff(sb, "hl", account1.getHighlightColor(), account2.getHighlightColor());
        appendDiff(sb, "icon", account1.getIcon(), account2.getIcon());
        appendDiff(sb, "lbl", account1.getLabel(), account2.getLabel());
        appendDiff(sb, "desc", account1.getShortDescription(), account2.getShortDescription());
        appendDiff(sb, "subAddr", Log.piiHandle(account1.getSubscriptionAddress()),
+1 −29
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.EventLog;

// TODO: Needed for move to system service: import com.android.internal.R;
@@ -78,8 +79,6 @@ public class TelecomServiceImpl {
        }
    }

    private static final String PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION =
            "android.permission.PROCESS_PHONE_ACCOUNT_REGISTRATION";
    private static final int DEFAULT_VIDEO_STATE = -1;

    private final ITelecomService.Stub mBinderImpl = new ITelecomService.Stub() {
@@ -401,19 +400,6 @@ public class TelecomServiceImpl {
                        }
                        enforceUserHandleMatchesCaller(account.getAccountHandle());
                        mPhoneAccountRegistrar.registerPhoneAccount(account);
                        // Broadcast an intent indicating the phone account which was registered.
                        long token = Binder.clearCallingIdentity();
                        try {
                            Intent intent = new Intent(
                                    TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED);
                            intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
                                    account.getAccountHandle());
                            Log.i(this, "Sending phone-account registered intent as user");
                            mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
                                    PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION);
                        } finally {
                            Binder.restoreCallingIdentity(token);
                        }
                    } catch (Exception e) {
                        Log.e(this, e, "registerPhoneAccount %s", account);
                        throw e;
@@ -433,20 +419,6 @@ public class TelecomServiceImpl {
                            accountHandle.getComponentName().getPackageName());
                    enforceUserHandleMatchesCaller(accountHandle);
                    mPhoneAccountRegistrar.unregisterPhoneAccount(accountHandle);

                    // Broadcast an intent indicating the phone account which was unregistered.
                    long token = Binder.clearCallingIdentity();
                    try {
                        Intent intent =
                                new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED);
                        intent.putExtra(
                                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
                        Log.i(this, "Sending phone-account unregistered intent as user");
                        mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
                                PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION);
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }
                } catch (Exception e) {
                    Log.e(this, e, "unregisterPhoneAccount %s", accountHandle);
                    throw e;
+2 −1
Original line number Diff line number Diff line
@@ -66,7 +66,8 @@
            <intent-filter>
                <action android:name="android.server.telecom.testapps.ACTION_SEND_UPDATE_REQUEST_FROM_TEST_INCALL_SERVICE"/>
                <action android:name="android.server.telecom.testapps.ACTION_SEND_UPGRADE_RESPONSE"/>
                <data android:scheme="int" />
                <action android:name="android.telecom.action.PHONE_ACCOUNT_REGISTERED"/>
                <action android:name="android.telecom.action.PHONE_ACCOUNT_UNREGISTERED"/>
            </intent-filter>
        </receiver>

+7 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.telecom.testapps;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telecom.TelecomManager;
import android.util.Log;

/**
@@ -56,6 +57,12 @@ public class TestInCallServiceBroadcastReceiver extends BroadcastReceiver {
        } else if (ACTION_SEND_UPGRADE_RESPONSE.equals(action)) {
            final int videoState = Integer.parseInt(intent.getData().getSchemeSpecificPart());
            TestCallList.getInstance().sendUpgradeToVideoResponse(videoState);
        } else if (TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED.equals(action)) {
            Log.i(TAG, "onReceive: registered " + intent.getExtras().get(
                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
        } else if (TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED.equals(action)) {
            Log.i(TAG, "onReceive: unregistered " + intent.getExtras().get(
                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
        }
    }
}