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

Commit 6191486f authored by Wei Liu's avatar Wei Liu
Browse files

Move the wear dialer off the custom component and use the default dialer hook.

b/30832184

Change-Id: If7fe13997e51df68aa8641048db489c4b00b6c42
parent 7997cba9
Loading
Loading
Loading
Loading
+14 −50
Original line number Diff line number Diff line
@@ -133,7 +133,6 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
    private final PhoneAccountRegistrar mPhoneAccountRegistrar;
    private final NotificationManager mNotificationManager;
    private final NotificationBuilderFactory mNotificationBuilderFactory;
    private final ComponentName mNotificationComponent;
    private final PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter;
    private UserHandle mCurrentUserHandle;

@@ -155,11 +154,8 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
        mNotificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        final String notificationComponent = context.getString(R.string.notification_component);

        mNotificationBuilderFactory = notificationBuilderFactory;
        mNotificationComponent = notificationComponent != null
                ? ComponentName.unflattenFromString(notificationComponent) : null;
        mMissedCallCounts = new ConcurrentHashMap<>();
    }

@@ -200,44 +196,6 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        }.prepare());
    }

    /**
     * Broadcasts missed call notification to custom component if set.
     * Currently the component is set in phone capable android wear device.
     * @param userHandle The user that has the missed call(s).
     * @return {@code true} if the broadcast was sent. {@code false} otherwise.
     */
    private boolean sendNotificationCustomComponent(Call call, UserHandle userHandle) {
        if (mNotificationComponent != null) {
            int count = mMissedCallCounts.get(userHandle).get();
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
            intent.setComponent(mNotificationComponent);
            intent.setAction(TelecomManager.ACTION_SHOW_MISSED_CALLS_NOTIFICATION);
            intent.putExtra(TelecomManager.EXTRA_NOTIFICATION_COUNT, count);
            intent.putExtra(TelecomManager.EXTRA_NOTIFICATION_PHONE_NUMBER,
                    call != null ? call.getPhoneNumber() : null);
            intent.putExtra(TelecomManager.EXTRA_CLEAR_MISSED_CALLS_INTENT,
                    createClearMissedCallsPendingIntent(userHandle));


            if (count == 1 && call != null) {
                final Uri handleUri = call.getHandle();
                String handle = handleUri == null ? null : handleUri.getSchemeSpecificPart();

                if (!TextUtils.isEmpty(handle) && !TextUtils.equals(handle,
                        mContext.getString(R.string.handle_restricted))) {
                    intent.putExtra(TelecomManager.EXTRA_CALL_BACK_INTENT,
                            createCallBackPendingIntent(handleUri, userHandle));
                }
            }

            mContext.sendBroadcast(intent);
            return true;
        }

        return false;
    }

    /**
     * Returns the missed-call notificatino intent to send to the default dialer for the given user.     * Note, the passed in userHandle is always the non-managed user for SIM calls (multi-user
     * calls). In this case we return the default dialer for the logged in user. This is never the
@@ -272,10 +230,24 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        int count = mMissedCallCounts.get(userHandle).get();
        Intent intent = getShowMissedCallIntentForDefaultDialer(userHandle)
            .setFlags(Intent.FLAG_RECEIVER_FOREGROUND)
            .putExtra(TelecomManager.EXTRA_CLEAR_MISSED_CALLS_INTENT,
                    createClearMissedCallsPendingIntent(userHandle))
            .putExtra(TelecomManager.EXTRA_NOTIFICATION_COUNT, count)
            .putExtra(TelecomManager.EXTRA_NOTIFICATION_PHONE_NUMBER,
                    call != null ? call.getPhoneNumber() : null);

        if (count == 1 && call != null) {
            final Uri handleUri = call.getHandle();
            String handle = handleUri == null ? null : handleUri.getSchemeSpecificPart();

            if (!TextUtils.isEmpty(handle) && !TextUtils.equals(handle,
                    mContext.getString(R.string.handle_restricted))) {
                intent.putExtra(TelecomManager.EXTRA_CALL_BACK_INTENT,
                        createCallBackPendingIntent(handleUri, userHandle));
            }
        }


        Log.w(this, "Showing missed calls through default dialer.");
        mContext.sendBroadcastAsUser(intent, userHandle, READ_PHONE_STATE);
    }
@@ -304,10 +276,6 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        mMissedCallCounts.putIfAbsent(userHandle, new AtomicInteger(0));
        int missCallCounts = mMissedCallCounts.get(userHandle).incrementAndGet();

        if (sendNotificationCustomComponent(call, userHandle)) {
            return;
        }

        if (shouldManageNotificationThroughDefaultDialer(userHandle)) {
            sendNotificationThroughDefaultDialer(call, userHandle);
            return;
@@ -420,10 +388,6 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
        mMissedCallCounts.putIfAbsent(userHandle, new AtomicInteger(0));
        mMissedCallCounts.get(userHandle).set(0);

        if (sendNotificationCustomComponent(null, userHandle)) {
            return;
        }

        if (shouldManageNotificationThroughDefaultDialer(userHandle)) {
            sendNotificationThroughDefaultDialer(null, userHandle);
            return;