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

Commit 92cb8535 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Correct erroneous call logging failure reporting.

There was some issue with the call log "verification" code we added wrt
to multiuser functionality.  This code was causing a lot of false reports
of call logging issues.  In practice this code was added as a speculative
way to diagnose call logging issues on the assumption the provider was
not actually logging.  As it turned out the logging issues we had in
the past were not related at all.  Checking for a valid URI after logging
is enough to know that a call was logged.  Internal logging in the
provider itself would point out to DB errors and things like that.

Test: Manually reproduce logging issue and confirm it is fixed.
Fixes: 330282747
Change-Id: I2a72dcbf2e4b4f9a520cfdb47ef5aca5a6bca01c
parent 55486a56
Loading
Loading
Loading
Loading
+3 −59
Original line number Diff line number Diff line
@@ -575,17 +575,10 @@ public final class CallLogManager extends CallsManagerListenerBase {
                AddCallArgs c = callList[i];
                mListeners[i] = c.logCallCompletedListener;
                try {
                    Pair<Integer, Integer> startStats = getCallLogStats(c.call);
                    Log.i(TAG, "LogCall; about to log callId=%s, "
                                    + "startCount=%d, startMaxId=%d",
                            c.call.getId(), startStats.first, startStats.second);

                    result[i] = Calls.addCall(c.context, c.params);
                    Pair<Integer, Integer> endStats = getCallLogStats(c.call);
                    Log.i(TAG, "LogCall; logged callId=%s, uri=%s, "
                                    + "endCount=%d, endMaxId=%s",
                            c.call.getId(), result, endStats.first, endStats.second);
                    if ((endStats.second - startStats.second) <= 0) {
                    Log.i(TAG, "LogCall; logged callId=%s, uri=%s",
                            c.call.getId(), result[i]);
                    if (result[i] == null) {
                        // 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
                        // call log while we were writing to it here; that is pretty unlikely, and
@@ -686,55 +679,6 @@ public final class CallLogManager extends CallsManagerListenerBase {
        }
    }

    /**
     * Returns a pair containing the number of rows in the call log, as well as the maximum call log
     * 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 be more call log
     * entries after logging than before, and certainly not less.
     * @return pair with number of rows in the call log and max id.
     */
    private Pair<Integer, Integer> getCallLogStats(@NonNull Call call) {
        try {
            // 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.
            Uri providerUri;
            boolean isCurrentUserUnlocked = mFeatureFlags.telecomResolveHiddenDependencies()
                    ? userManager.isUserUnlocked(UserHandle.CURRENT)
                    : userManager.isUserUnlocked(currentUserId);
            if (isCurrentUserUnlocked) {
                providerUri = Calls.CONTENT_URI;
            } else {
                providerUri = Calls.SHADOW_CONTENT_URI;
            }
            int maxCallId = -1;
            int numFound;
            try (Cursor countCursor = currentUserResolver.query(providerUri,
                    new String[]{Calls._ID},
                    null,
                    null,
                    Calls._ID + " DESC")) {
                numFound = countCursor.getCount();
                if (numFound > 0) {
                    countCursor.moveToFirst();
                    maxCallId = countCursor.getInt(0);
                }
            }
            return new Pair<>(numFound, maxCallId);
        } catch (Exception e) {
            // Oh jeepers, we crashed getting the call count.
            Log.e(TAG, e, "getCountOfCallLogRows: failed");
            return new Pair<>(-1, -1);
        }
    }

    @VisibleForTesting
    public void setAnomalyReporterAdapter(AnomalyReporterAdapter anomalyReporterAdapter){
        mAnomalyReporterAdapter = anomalyReporterAdapter;