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

Commit 58fd0500 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Mark self-managed calls as "read" when logged.

When self-maanged calls are logged to the call log, ensure that the is_read
flag is set to 1.  This is important for missed calls.  Missed calls which
are unread trigger a missed-call notification.  Realistically we expect
the app to handle the missed called notification on its own, so marking
them as read makes sense.

Also updated the example self managed calling test app to support missed
calls.  Yay.

Test: Added unit tests for this scenario, used manual test harness.
Bug: 67637603
Change-Id: If8488e9ad81f0b4df8d4296e10fb89f3cb56d728
parent b1445fde
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -69,12 +69,13 @@ public final class CallLogManager extends CallsManagerListenerBase {
         * @param creationDate Time when the call was created (milliseconds since epoch).
         * @param durationInMillis Duration of the call (milliseconds).
         * @param dataUsage Data usage in bytes, or null if not applicable.
         * @param isRead Indicates if the entry has been read or not.
         * @param logCallCompletedListener optional callback called after the call is logged.
         */
        public AddCallArgs(Context context, CallerInfo callerInfo, String number,
                String postDialDigits, String viaNumber, int presentation, int callType,
                int features, PhoneAccountHandle accountHandle, long creationDate,
                long durationInMillis, Long dataUsage, UserHandle initiatingUser,
                long durationInMillis, Long dataUsage, UserHandle initiatingUser, boolean isRead,
                @Nullable LogCallCompletedListener logCallCompletedListener) {
            this.context = context;
            this.callerInfo = callerInfo;
@@ -89,6 +90,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
            this.durationInSec = (int)(durationInMillis / 1000);
            this.dataUsage = dataUsage;
            this.initiatingUser = initiatingUser;
            this.isRead = isRead;
            this.logCallCompletedListener = logCallCompletedListener;
        }
        // Since the members are accessed directly, we don't use the
@@ -106,6 +108,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
        public final int durationInSec;
        public final Long dataUsage;
        public final UserHandle initiatingUser;
        public final boolean isRead;

        @Nullable
        public final LogCallCompletedListener logCallCompletedListener;
@@ -235,7 +238,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
        logCall(call.getCallerInfo(), logNumber, call.getPostDialDigits(), formattedViaNumber,
                call.getHandlePresentation(), callLogType, callFeatures, accountHandle,
                creationTime, age, callDataUsage, call.isEmergencyCall(), call.getInitiatingUser(),
                logCallCompletedListener);
                call.isSelfManaged(), logCallCompletedListener);
    }

    /**
@@ -253,6 +256,8 @@ public final class CallLogManager extends CallsManagerListenerBase {
     * @param dataUsage The data usage for the call, null if not applicable.
     * @param isEmergency {@code true} if this is an emergency call, {@code false} otherwise.
     * @param logCallCompletedListener optional callback called after the call is logged.
     * @param initiatingUser The user the call was initiated under.
     * @param isSelfManaged {@code true} if this is a self-managed call, {@code false} otherwise.
     */
    private void logCall(
            CallerInfo callerInfo,
@@ -268,6 +273,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
            Long dataUsage,
            boolean isEmergency,
            UserHandle initiatingUser,
            boolean isSelfManaged,
            @Nullable LogCallCompletedListener logCallCompletedListener) {

        // On some devices, to avoid accidental redialing of emergency numbers, we *never* log
@@ -292,9 +298,15 @@ public final class CallLogManager extends CallsManagerListenerBase {
            Log.d(TAG, "Logging Call log entry: " + callerInfo + ", "
                    + Log.pii(number) + "," + presentation + ", " + callType
                    + ", " + start + ", " + duration);
            boolean isRead = false;
            if (isSelfManaged) {
                // Mark self-managed calls are read since they're being handled by their own app.
                // Their inclusion in the call log is informational only.
                isRead = true;
            }
            AddCallArgs args = new AddCallArgs(mContext, callerInfo, number, postDialDigits,
                    viaNumber, presentation, callType, features, accountHandle, start, duration,
                    dataUsage, initiatingUser, logCallCompletedListener);
                    dataUsage, initiatingUser, isRead, logCallCompletedListener);
            logCallAsync(args);
        } else {
          Log.d(TAG, "Not adding emergency call to call log.");
@@ -440,7 +452,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
            return Calls.addCall(c.callerInfo, c.context, c.number, c.postDialDigits, c.viaNumber,
                    c.presentation, c.callType, c.features, c.accountHandle, c.timestamp,
                    c.durationInSec, c.dataUsage, userToBeInserted == null,
                    userToBeInserted);
                    userToBeInserted, c.isRead);
        }


+5 −0
Original line number Diff line number Diff line
@@ -47,6 +47,11 @@
            android:layout_height="wrap_content"
            android:text="Hold"
            android:id="@+id/setHeldButton" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Missed"
            android:id="@+id/missedButton" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
+19 −3
Original line number Diff line number Diff line
@@ -60,8 +60,18 @@ public class SelfManagedCallListAdapter extends BaseAdapter {
    };

    /**
     * Listener used to handle tap of the "held" button for a connection.
     * Listener used to handle tap of the "missed" button for a connection.
     */
    private View.OnClickListener mMissedListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            View parent = (View) v.getParent().getParent();
            SelfManagedConnection connection = (SelfManagedConnection) parent.getTag();
            connection.setConnectionDisconnected(DisconnectCause.MISSED);
            SelfManagedCallList.getInstance().removeConnection(connection);
        }
    };

    private View.OnClickListener mHeldListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
@@ -165,7 +175,7 @@ public class SelfManagedCallListAdapter extends BaseAdapter {
        }
        setInfoForRow(result, phoneAccountHandle.getId(), connection.getAddress().toString(),
                android.telecom.Connection.stateToString(connection.getState()), audioRoute,
                callType);
                callType, connection.getState() == android.telecom.Connection.STATE_RINGING);
        result.setTag(connection);
        return result;
    }
@@ -177,7 +187,8 @@ public class SelfManagedCallListAdapter extends BaseAdapter {
    }

    private void setInfoForRow(View view, String accountName, String number,
                               String status, String audioRoute, String callType) {
                               String status, String audioRoute, String callType,
            boolean isRinging) {

        TextView numberTextView = (TextView) view.findViewById(R.id.phoneNumber);
        TextView statusTextView = (TextView) view.findViewById(R.id.callState);
@@ -191,6 +202,11 @@ public class SelfManagedCallListAdapter extends BaseAdapter {
        speakerButton.setOnClickListener(mSpeakerListener);
        View earpieceButton = view.findViewById(R.id.earpieceButton);
        earpieceButton.setOnClickListener(mEarpieceListener);
        View missedButton = view.findViewById(R.id.missedButton);
        missedButton.setOnClickListener(mMissedListener);
        missedButton.setVisibility(isRinging ? View.VISIBLE : View.GONE);
        setHeldButton.setVisibility(!isRinging ? View.VISIBLE : View.GONE);
        disconnectButton.setVisibility(!isRinging ? View.VISIBLE : View.GONE);
        numberTextView.setText(accountName + " - " + number + " (" + audioRoute + ")");
        statusTextView.setText(callType + " - Status: " + status);
    }
+3 −0
Original line number Diff line number Diff line
@@ -183,6 +183,9 @@ public class SelfManagedConnection extends Connection {
    }

    public void setConnectionDisconnected(int cause) {
        NotificationManager notificationManager = mContext.getSystemService(
                NotificationManager.class);
        notificationManager.cancel(CALL_NOTIFICATION, mCallId);
        mMediaPlayer.stop();
        setDisconnected(new DisconnectCause(cause));
        destroy();
+1 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public class SelfManagedConnectionService extends ConnectionService {
        connection.setExtras(request.getExtras());
        if (isIncoming) {
            connection.setIsIncomingCallUiShowing(request.shouldShowIncomingCallUi());
            connection.setRinging();
        }
        Bundle requestExtras = request.getExtras();
        if (requestExtras != null) {
Loading