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

Commit 1d71b0a4 authored by Rana Mouawi's avatar Rana Mouawi
Browse files

Do not log calls with EXTRA_DO_NOT_LOG_CALL.

Bug: b/295530944
Test: Manual and unit tests pass
Defer-CP-To-Master: 297157687

Change-Id: I76ac87a90fee02deebf3327a872237715dc7cb0c
(cherry picked from commit 48a26abde98bd80c85660d4a66ac89fc6b6c009e)
parent 5b68c3e0
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -6,3 +6,10 @@ flag {
  description: "log external call if current device is a wearable one"
  bug: "292600751"
}

flag {
  name: "telecom_skip_log_based_on_extra"
  namespace: "telecom"
  description: "skipping logging a call based on passed extra"
  bug: "295530944"
}
+19 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -324,6 +325,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                }
            };

    private final boolean mIsModifyStatePermissionGranted;
    /**
     * One of CALL_DIRECTION_INCOMING, CALL_DIRECTION_OUTGOING, or CALL_DIRECTION_UNKNOWN
     */
@@ -873,6 +875,8 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        mStartRingTime = 0;

        mCallStateChangedAtomWriter.setExistingCallCount(callsManager.getCalls().size());
        mIsModifyStatePermissionGranted =
                isModifyPhoneStatePermissionGranted(getDelegatePhoneAccountHandle());
    }

    /**
@@ -3098,6 +3102,12 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                    Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE));
        }

        if (mExtras.containsKey(TelecomManager.EXTRA_DO_NOT_LOG_CALL)) {
            if (source != SOURCE_CONNECTION_SERVICE || !mIsModifyStatePermissionGranted) {
                mExtras.remove(TelecomManager.EXTRA_DO_NOT_LOG_CALL);
            }
        }

        // If the change originated from an InCallService, notify the connection service.
        if (source == SOURCE_INCALL_SERVICE) {
            Log.addEvent(this, LogUtils.Events.ICS_EXTRAS_CHANGED);
@@ -3112,6 +3122,15 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        }
    }

    private boolean isModifyPhoneStatePermissionGranted(PhoneAccountHandle phoneAccountHandle) {
        if (phoneAccountHandle == null) {
            return false;
        }
        String packageName = phoneAccountHandle.getComponentName().getPackageName();
        return PackageManager.PERMISSION_GRANTED == mContext.getPackageManager().checkPermission(
                android.Manifest.permission.MODIFY_PHONE_STATE, packageName);
    }

    /**
     * Removes extras from the extras bundle associated with this {@link Call}.
     *
+6 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
     * Call was NOT in the "choose account" phase when disconnected
     * Call is NOT a conference call which had children (unless it was remotely hosted).
     * Call is NOT a child call from a conference which was remotely hosted.
     * Call has NOT indicated it should be skipped for logging in its extras
     * Call is NOT simulating a single party conference.
     * Call was NOT explicitly canceled, except for disconnecting from a conference.
     * Call is NOT an external call or an external call on watch.
@@ -201,6 +202,11 @@ public final class CallLogManager extends CallsManagerListenerBase {
            return false;
        }

        if (mFeatureFlags.telecomSkipLogBasedOnExtra() && call.getExtras() != null
                && call.getExtras().containsKey(TelecomManager.EXTRA_DO_NOT_LOG_CALL)) {
            return false;
        }

        // A child call of a conference which was remotely hosted; these didn't originate on this
        // device and should not be logged.
        if (call.getParentCall() != null && call.hasProperty(Connection.PROPERTY_REMOTELY_HOSTED)) {
+50 −0
Original line number Diff line number Diff line
@@ -965,6 +965,56 @@ public class CallLogManagerTest extends TelecomTestCase {
                false /* isCanceled */));
    }

    @SmallTest
    @Test
    public void testDoNotLogCallExtra() {
        when(mFeatureFlags.telecomSkipLogBasedOnExtra()).thenReturn(true);
        Call fakeCall = makeFakeCall(
                DisconnectCause.LOCAL, // disconnectCauseCode
                false, // isConference
                true, // isIncoming
                1L, // creationTimeMillis
                1000L, // ageMillis
                TEL_PHONEHANDLE, // callHandle
                mDefaultAccountHandle, // phoneAccountHandle
                NO_VIDEO_STATE, // callVideoState
                POST_DIAL_STRING, // postDialDigits
                VIA_NUMBER_STRING, // viaNumber
                UserHandle.of(CURRENT_USER_ID)
        );
        Bundle extras = new Bundle();
        extras.putBoolean(TelecomManager.EXTRA_DO_NOT_LOG_CALL, true);
        when(fakeCall.getExtras()).thenReturn(extras);

        assertFalse(mCallLogManager.shouldLogDisconnectedCall(fakeCall, CallState.DISCONNECTED,
                false /* isCanceled */));
    }

    @SmallTest
    @Test
    public void testIgnoresDoNotLogCallExtra_whenFlagDisabled() {
        when(mFeatureFlags.telecomSkipLogBasedOnExtra()).thenReturn(false);
        Call fakeCall = makeFakeCall(
                DisconnectCause.LOCAL, // disconnectCauseCode
                false, // isConference
                true, // isIncoming
                1L, // creationTimeMillis
                1000L, // ageMillis
                TEL_PHONEHANDLE, // callHandle
                mDefaultAccountHandle, // phoneAccountHandle
                NO_VIDEO_STATE, // callVideoState
                POST_DIAL_STRING, // postDialDigits
                VIA_NUMBER_STRING, // viaNumber
                UserHandle.of(CURRENT_USER_ID)
        );
        Bundle extras = new Bundle();
        extras.putBoolean(TelecomManager.EXTRA_DO_NOT_LOG_CALL, true);
        when(fakeCall.getExtras()).thenReturn(extras);

        assertTrue(mCallLogManager.shouldLogDisconnectedCall(fakeCall, CallState.DISCONNECTED,
                false /* isCanceled */));
    }

    @SmallTest
    @Test
    public void testDoNotLogConferenceWithChildren() {
+47 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.argThat;
@@ -34,6 +33,7 @@ import static org.mockito.Mockito.verify;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
@@ -728,6 +728,52 @@ public class CallTest extends TelecomTestCase {
                }));
    }

    @Test
    @SmallTest
    public void testExcludesInCallServiceFromDoNotLogCallExtra() {
        Call call = createCall("any");
        Bundle extra = new Bundle();
        extra.putBoolean(TelecomManager.EXTRA_DO_NOT_LOG_CALL, true);

        call.putInCallServiceExtras(extra, "packageName");

        assertFalse(call.getExtras().containsKey(TelecomManager.EXTRA_DO_NOT_LOG_CALL));
    }

    @Test
    @SmallTest
    public void testExcludesConnectionServiceWithoutModifyStatePermissionFromDoNotLogCallExtra() {
        PackageManager packageManager = mContext.getPackageManager();
        Bundle extra = new Bundle();
        extra.putBoolean(TelecomManager.EXTRA_DO_NOT_LOG_CALL, true);
        String packageName = SIM_1_HANDLE.getComponentName().getPackageName();
        doReturn(PackageManager.PERMISSION_DENIED)
                .when(packageManager)
                .checkPermission(android.Manifest.permission.MODIFY_PHONE_STATE, packageName);
        Call call = createCall("any");

        call.putConnectionServiceExtras(extra);

        assertFalse(call.getExtras().containsKey(TelecomManager.EXTRA_DO_NOT_LOG_CALL));
    }

    @Test
    @SmallTest
    public void testDoesNotExcludeConnectionServiceWithModifyStatePermissionFromDoNotLogCallExtra() {
        String packageName = SIM_1_HANDLE.getComponentName().getPackageName();
        Bundle extra = new Bundle();
        extra.putBoolean(TelecomManager.EXTRA_DO_NOT_LOG_CALL, true);
        PackageManager packageManager = mContext.getPackageManager();
        doReturn(PackageManager.PERMISSION_GRANTED)
                .when(packageManager)
                .checkPermission(android.Manifest.permission.MODIFY_PHONE_STATE, packageName);
        Call call = createCall("any");

        call.putConnectionServiceExtras(extra);

        assertTrue(call.getExtras().containsKey(TelecomManager.EXTRA_DO_NOT_LOG_CALL));
    }

    private Call createCall(String id) {
        return createCall(id, Call.CALL_DIRECTION_UNDEFINED);
    }