diff options
Diffstat (limited to 'src/com/android/server/telecom/CallLogManager.java')
-rw-r--r-- | src/com/android/server/telecom/CallLogManager.java | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/src/com/android/server/telecom/CallLogManager.java b/src/com/android/server/telecom/CallLogManager.java index 72aecacd0..fc4e05d69 100644 --- a/src/com/android/server/telecom/CallLogManager.java +++ b/src/com/android/server/telecom/CallLogManager.java @@ -24,6 +24,7 @@ import android.annotation.Nullable; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.database.Cursor; import android.location.Country; import android.location.CountryDetector; @@ -50,6 +51,7 @@ import android.util.Pair; import com.android.internal.annotations.VisibleForTesting; import com.android.server.telecom.callfiltering.CallFilteringResult; +import com.android.server.telecom.flags.FeatureFlags; import java.util.Arrays; import java.util.Locale; @@ -75,18 +77,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 +100,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; @@ -117,8 +119,11 @@ public final class CallLogManager extends CallsManagerListenerBase { private Object mLock; private String mCurrentCountryIso; + private final FeatureFlags mFeatureFlags; + public CallLogManager(Context context, PhoneAccountRegistrar phoneAccountRegistrar, - MissedCallNotifier missedCallNotifier, AnomalyReporterAdapter anomalyReporterAdapter) { + MissedCallNotifier missedCallNotifier, AnomalyReporterAdapter anomalyReporterAdapter, + FeatureFlags featureFlags) { mContext = context; mCarrierConfigManager = (CarrierConfigManager) mContext .getSystemService(Context.CARRIER_CONFIG_SERVICE); @@ -126,6 +131,7 @@ public final class CallLogManager extends CallsManagerListenerBase { mMissedCallNotifier = missedCallNotifier; mAnomalyReporterAdapter = anomalyReporterAdapter; mLock = new Object(); + mFeatureFlags = featureFlags; } @Override @@ -164,9 +170,10 @@ 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 + * Call is NOT an external call or an external call on watch. * Call is NOT disconnected because of merging into a conference. * Call is NOT a self-managed call OR call is a self-managed call which has indicated it * should be logged in its PhoneAccount @@ -195,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)) { @@ -215,8 +227,10 @@ public final class CallLogManager extends CallsManagerListenerBase { & Connection.CAPABILITY_DISCONNECT_FROM_CONFERENCE) == Connection.CAPABILITY_DISCONNECT_FROM_CONFERENCE; } - // An external call - if (call.isExternalCall()) { + // An external and non-watch call + if (call.isExternalCall() && (!mContext.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_WATCH) + || !mFeatureFlags.telecomLogExternalWearableCalls())) { return false; } @@ -255,8 +269,13 @@ public final class CallLogManager extends CallsManagerListenerBase { logCall(call, type, new LogCallCompletedListener() { @Override public void onLogCompleted(@Nullable Uri uri) { - mMissedCallNotifier.showMissedCallNotification( - new MissedCallNotifier.CallInfo(call)); + if (mFeatureFlags.addCallUriForMissedCalls()){ + mMissedCallNotifier.showMissedCallNotification( + new MissedCallNotifier.CallInfo(call), uri); + } else { + mMissedCallNotifier.showMissedCallNotification( + new MissedCallNotifier.CallInfo(call), /* uri= */ null); + } } }, result); } else { @@ -400,7 +419,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 +550,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 +577,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 +662,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,19 +684,16 @@ public final class CallLogManager extends CallsManagerListenerBase { } int maxCallId = -1; int numFound; - Cursor countCursor = resolver.query(providerUri, + try (Cursor countCursor = currentUserResolver.query(providerUri, new String[]{Calls._ID}, null, null, - Calls._ID + " DESC"); - try { + Calls._ID + " DESC")) { numFound = countCursor.getCount(); if (numFound > 0) { countCursor.moveToFirst(); maxCallId = countCursor.getInt(0); } - } finally { - countCursor.close(); } return new Pair<>(numFound, maxCallId); } catch (Exception e) { |