diff options
author | 2025-02-18 17:45:23 -0800 | |
---|---|---|
committer | 2025-02-18 17:52:31 -0800 | |
commit | b0514c4e229ef09328bc7aeaf09c4c2f3a3ace71 (patch) | |
tree | d4447ea60f8eb61a4be8b06fa16b99d848e509e9 | |
parent | dd7b19f366baefa6ead8f124c85bb04d93e718df (diff) |
Query for contacts in the same user as the call when deciding trusted
This ensures the correct set of contacts is queried before a call is
declared trusted
Fixes: 396541213
Test: (in HSUM mode) atest EnhancedConfirmationInCallTest
Flag: EXEMPT fix for HSUM test
Relnote: 25Q2
Change-Id: I420dd9f99a4fc4c5231166c05dea3a97a458adc4
-rw-r--r-- | service/java/com/android/ecm/EnhancedConfirmationService.java | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/service/java/com/android/ecm/EnhancedConfirmationService.java b/service/java/com/android/ecm/EnhancedConfirmationService.java index fc0ed20d0..1e5ab2fed 100644 --- a/service/java/com/android/ecm/EnhancedConfirmationService.java +++ b/service/java/com/android/ecm/EnhancedConfirmationService.java @@ -110,7 +110,6 @@ public class EnhancedConfirmationService extends SystemService { new EnhancedConfirmationManagerLocalImpl(this)); } - private ContentResolver mContentResolver; private TelephonyManager mTelephonyManager; @GuardedBy("mUserAccessibilityManagers") @@ -128,7 +127,6 @@ public class EnhancedConfirmationService extends SystemService { systemConfigManager.getEnhancedConfirmationTrustedInstallers()); publishBinderService(Context.ECM_ENHANCED_CONFIRMATION_SERVICE, new Stub()); - mContentResolver = getContext().getContentResolver(); mTelephonyManager = getContext().getSystemService(TelephonyManager.class); } @@ -177,10 +175,12 @@ public class EnhancedConfirmationService extends SystemService { // device, either because the device lacks telephony calling, or the telephony service // is unavailable. } + UserHandle user = call.getDetails().getAccountHandle().getUserHandle(); if (number != null) { - return hasContactWithPhoneNumber(number) ? CALL_TYPE_TRUSTED : CALL_TYPE_UNTRUSTED; + return hasContactWithPhoneNumber(number, user) + ? CALL_TYPE_TRUSTED : CALL_TYPE_UNTRUSTED; } else { - return hasContactWithDisplayName(call.getDetails().getCallerDisplayName()) + return hasContactWithDisplayName(call.getDetails().getCallerDisplayName(), user) ? CALL_TYPE_TRUSTED : CALL_TYPE_UNTRUSTED; } } @@ -196,7 +196,7 @@ public class EnhancedConfirmationService extends SystemService { return handle.getSchemeSpecificPart(); } - private boolean hasContactWithPhoneNumber(String phoneNumber) { + private boolean hasContactWithPhoneNumber(String phoneNumber, UserHandle user) { if (phoneNumber == null) { return false; } @@ -206,12 +206,12 @@ public class EnhancedConfirmationService extends SystemService { PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup._ID }; - try (Cursor res = mContentResolver.query(uri, projection, null, null)) { + try (Cursor res = getUserContentResolver(user).query(uri, projection, null, null)) { return res != null && res.getCount() > 0; } } - private boolean hasContactWithDisplayName(String displayName) { + private boolean hasContactWithDisplayName(String displayName, UserHandle user) { if (displayName == null) { return false; } @@ -219,11 +219,16 @@ public class EnhancedConfirmationService extends SystemService { String[] projection = new String[]{PhoneLookup._ID}; String selection = StructuredName.DISPLAY_NAME + " = ?"; String[] selectionArgs = new String[]{displayName}; - try (Cursor res = mContentResolver.query(uri, projection, selection, selectionArgs, null)) { + try (Cursor res = getUserContentResolver(user) + .query(uri, projection, selection, selectionArgs, null)) { return res != null && res.getCount() > 0; } } + private ContentResolver getUserContentResolver(UserHandle user) { + return getContext().createContextAsUser(user, 0).getContentResolver(); + } + private boolean hasCallOfType(@CallType int callType) { for (int ongoingCallType : mOngoingCalls.values()) { if (ongoingCallType == callType) { |