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

Commit 4f17ca44 authored by Grant Menke's avatar Grant Menke
Browse files

Ensure that getCallLogStats references the current user.

This CL updates the logic in getCallLogStats to ensure that the current user is referenced when checking that the call was properly logged to the call log. This was causing false anomaly reporting when a user was making calls from their work profile. This CL also ensures this anomlay report uses a newly created UUID so that the old UUID that was being used can be remotely disabled to prevent false positives from flooding in while still allowing genuine anomlies triggered after this logic fix merges to go through.

Flag: Test debug logging only
Test: manual using TestDPC
Fixes: 303858592
Change-Id: Idc634efacff0144b5e09ef6247fb8521200c2992
parent 525dc1a7
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -75,18 +75,18 @@ public final class CallLogManager extends CallsManagerListenerBase {
    private static class AddCallArgs {
        public AddCallArgs(Context context, CallLog.AddCallParams params,
                @Nullable LogCallCompletedListener logCallCompletedListener,
                @NonNull String callId) {
                @NonNull Call call) {
            this.context = context;
            this.params = params;
            this.logCallCompletedListener = logCallCompletedListener;
            this.callId = callId;
            this.call = call;

        }
        // Since the members are accessed directly, we don't use the
        // mXxxx notation.
        public final Context context;
        public final CallLog.AddCallParams params;
        public final String callId;
        public final Call call;
        @Nullable
        public final LogCallCompletedListener logCallCompletedListener;
    }
@@ -98,9 +98,9 @@ public final class CallLogManager extends CallsManagerListenerBase {
    // a conference was merged successfully
    private static final String REASON_IMS_MERGED_SUCCESSFULLY = "IMS_MERGED_SUCCESSFULLY";
    private static final UUID LOG_CALL_FAILED_ANOMALY_ID =
            UUID.fromString("1c4c15f3-ab4f-459c-b9ef-43d2988bae82");
            UUID.fromString("d9b38771-ff36-417b-8723-2363a870c702");
    private static final String LOG_CALL_FAILED_ANOMALY_DESC =
            "Failed to record a call to the call log.";
            "Based on the current user, Telecom detected failure to record a call to the call log.";

    private final Context mContext;
    private final CarrierConfigManager mCarrierConfigManager;
@@ -400,7 +400,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
                okayToLogCall(accountHandle, logNumber, call.isEmergencyCall());
        if (okayToLog) {
            AddCallArgs args = new AddCallArgs(mContext, paramBuilder.build(),
                    logCallCompletedListener, call.getId());
                    logCallCompletedListener, call);
            Log.addEvent(call, LogUtils.Events.LOG_CALL, "number=" + Log.piiHandle(logNumber)
                    + ",postDial=" + Log.piiHandle(call.getPostDialDigits()) + ",pres="
                    + call.getHandlePresentation());
@@ -531,18 +531,16 @@ public final class CallLogManager extends CallsManagerListenerBase {
                AddCallArgs c = callList[i];
                mListeners[i] = c.logCallCompletedListener;
                try {
                    // May block.
                    ContentResolver resolver = c.context.getContentResolver();
                    Pair<Integer, Integer> startStats = getCallLogStats(resolver);
                    Pair<Integer, Integer> startStats = getCallLogStats(c.call);
                    Log.i(TAG, "LogCall; about to log callId=%s, "
                                    + "startCount=%d, startMaxId=%d",
                            c.callId, startStats.first, startStats.second);
                            c.call.getId(), startStats.first, startStats.second);

                    result[i] = Calls.addCall(c.context, c.params);
                    Pair<Integer, Integer> endStats = getCallLogStats(resolver);
                    Pair<Integer, Integer> endStats = getCallLogStats(c.call);
                    Log.i(TAG, "LogCall; logged callId=%s, uri=%s, "
                                    + "endCount=%d, endMaxId=%s",
                            c.callId, result, endStats.first, endStats.second);
                            c.call.getId(), result, endStats.first, endStats.second);
                    if ((endStats.second - startStats.second) <= 0) {
                        // No call was added or even worse we lost a call in the log.  Trigger an
                        // anomaly report.  Note: it technically possible that an app modified the
@@ -560,7 +558,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
                    //
                    // We don't want to crash the whole process just because of that, so just log
                    // it instead.
                    Log.e(TAG, e, "LogCall: Exception raised adding callId=%s", c.callId);
                    Log.e(TAG, e, "LogCall: Exception raised adding callId=%s", c.call.getId());
                    result[i] = null;
                    mAnomalyReporterAdapter.reportAnomaly(LOG_CALL_FAILED_ANOMALY_ID,
                            LOG_CALL_FAILED_ANOMALY_DESC);
@@ -645,14 +643,17 @@ public final class CallLogManager extends CallsManagerListenerBase {
     * ID.  There is a limit of 500 entries in the call log for a phone account, so once we hit 500
     * we can reasonably expect that number to not change before and after logging a call.
     * We determine the maximum ID in the call log since this is a way we can objectively check if
     * the provider did record a call log entry or not.  Ideally there should me more call log
     * the provider did record a call log entry or not.  Ideally there should be more call log
     * entries after logging than before, and certainly not less.
     * @param resolver content resolver
     * @return pair with number of rows in the call log and max id.
     */
    private Pair<Integer, Integer> getCallLogStats(@NonNull ContentResolver resolver) {
    private Pair<Integer, Integer> getCallLogStats(@NonNull Call call) {
        try {
            final UserManager userManager = mContext.getSystemService(UserManager.class);
            // Ensure we query the call log based on the current user.
            final Context currentUserContext = mContext.createContextAsUser(
                    call.getAssociatedUser(), /* flags= */ 0);
            final ContentResolver currentUserResolver = currentUserContext.getContentResolver();
            final UserManager userManager = currentUserContext.getSystemService(UserManager.class);
            final int currentUserId = userManager.getProcessUserId();

            // Use shadow provider based on current user unlock state.
@@ -664,7 +665,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
            }
            int maxCallId = -1;
            int numFound;
            try (Cursor countCursor = resolver.query(providerUri,
            try (Cursor countCursor = currentUserResolver.query(providerUri,
                    new String[]{Calls._ID},
                    null,
                    null,