diff options
| author | 2022-08-17 17:54:41 +0000 | |
|---|---|---|
| committer | 2022-08-17 17:54:41 +0000 | |
| commit | e18b857c29e45c0f554b0f9bbcc29e9a0bb5ca7f (patch) | |
| tree | 1c5075384dcc8c7f3f21325e41dc650d1deabad7 | |
| parent | c83d2754010ca63c37b416fb11deb78dd6bdad57 (diff) | |
| parent | 403a1356458fb8ef2218a3ff166c164b20d2442e (diff) | |
Merge "Write to Zen Log for recording callers & when checking on repeat callers" into tm-qpr-dev am: 403a135645
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19633079
Change-Id: Ib396b5b35a0722a273b8e30b53c07b6f90098610
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
5 files changed, 80 insertions, 34 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 9bfdd0465168..20f37cfae9f0 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -5171,7 +5171,8 @@ public class NotificationManagerService extends SystemService { extras, mRankingHelper.findExtractor(ValidateNotificationPeople.class), MATCHES_CALL_FILTER_CONTACTS_TIMEOUT_MS, - MATCHES_CALL_FILTER_TIMEOUT_AFFINITY); + MATCHES_CALL_FILTER_TIMEOUT_AFFINITY, + Binder.getCallingUid()); } @Override diff --git a/services/core/java/com/android/server/notification/ZenLog.java b/services/core/java/com/android/server/notification/ZenLog.java index 7d7f3a96595c..c0bc474cd8fa 100644 --- a/services/core/java/com/android/server/notification/ZenLog.java +++ b/services/core/java/com/android/server/notification/ZenLog.java @@ -66,6 +66,8 @@ public class ZenLog { private static final int TYPE_SET_NOTIFICATION_POLICY = 16; private static final int TYPE_SET_CONSOLIDATED_ZEN_POLICY = 17; private static final int TYPE_MATCHES_CALL_FILTER = 18; + private static final int TYPE_RECORD_CALLER = 19; + private static final int TYPE_CHECK_REPEAT_CALLER = 20; private static int sNext; private static int sSize; @@ -167,11 +169,28 @@ public class ZenLog { + hintsToString(newHints) + ",listeners=" + listenerCount); } - /* + /** * Trace calls to matchesCallFilter with the result of the call and the reason for the result. */ - public static void traceMatchesCallFilter(boolean result, String reason) { - append(TYPE_MATCHES_CALL_FILTER, "result=" + result + ", reason=" + reason); + public static void traceMatchesCallFilter(boolean result, String reason, int callingUid) { + append(TYPE_MATCHES_CALL_FILTER, "result=" + result + ", reason=" + reason + + ", calling uid=" + callingUid); + } + + /** + * Trace what information is available about an incoming call when it's recorded + */ + public static void traceRecordCaller(boolean hasPhone, boolean hasUri) { + append(TYPE_RECORD_CALLER, "has phone number=" + hasPhone + ", has uri=" + hasUri); + } + + /** + * Trace what information was provided about a caller when checking whether it is from a repeat + * caller + */ + public static void traceCheckRepeatCaller(boolean found, boolean hasPhone, boolean hasUri) { + append(TYPE_CHECK_REPEAT_CALLER, "res=" + found + ", given phone number=" + hasPhone + + ", given uri=" + hasUri); } private static String subscribeResult(IConditionProvider provider, RemoteException e) { @@ -198,6 +217,8 @@ public class ZenLog { case TYPE_SET_NOTIFICATION_POLICY: return "set_notification_policy"; case TYPE_SET_CONSOLIDATED_ZEN_POLICY: return "set_consolidated_policy"; case TYPE_MATCHES_CALL_FILTER: return "matches_call_filter"; + case TYPE_RECORD_CALLER: return "record_caller"; + case TYPE_CHECK_REPEAT_CALLER: return "check_repeat_caller"; default: return "unknown"; } } diff --git a/services/core/java/com/android/server/notification/ZenModeFiltering.java b/services/core/java/com/android/server/notification/ZenModeFiltering.java index b0d40efed690..7e36aed81d4a 100644 --- a/services/core/java/com/android/server/notification/ZenModeFiltering.java +++ b/services/core/java/com/android/server/notification/ZenModeFiltering.java @@ -101,23 +101,24 @@ public class ZenModeFiltering { */ public static boolean matchesCallFilter(Context context, int zen, NotificationManager.Policy consolidatedPolicy, UserHandle userHandle, Bundle extras, - ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) { + ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity, + int callingUid) { if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) { - ZenLog.traceMatchesCallFilter(false, "no interruptions"); + ZenLog.traceMatchesCallFilter(false, "no interruptions", callingUid); return false; // nothing gets through } if (zen == Global.ZEN_MODE_ALARMS) { - ZenLog.traceMatchesCallFilter(false, "alarms only"); + ZenLog.traceMatchesCallFilter(false, "alarms only", callingUid); return false; // not an alarm } if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { if (consolidatedPolicy.allowRepeatCallers() && REPEAT_CALLERS.isRepeat(context, extras, null)) { - ZenLog.traceMatchesCallFilter(true, "repeat caller"); + ZenLog.traceMatchesCallFilter(true, "repeat caller", callingUid); return true; } if (!consolidatedPolicy.allowCalls()) { - ZenLog.traceMatchesCallFilter(false, "calls not allowed"); + ZenLog.traceMatchesCallFilter(false, "calls not allowed", callingUid); return false; // no other calls get through } if (validator != null) { @@ -125,11 +126,12 @@ public class ZenModeFiltering { contactsTimeoutMs, timeoutAffinity); boolean match = audienceMatches(consolidatedPolicy.allowCallsFrom(), contactAffinity); - ZenLog.traceMatchesCallFilter(match, "contact affinity " + contactAffinity); + ZenLog.traceMatchesCallFilter(match, "contact affinity " + contactAffinity, + callingUid); return match; } } - ZenLog.traceMatchesCallFilter(true, "no restrictions"); + ZenLog.traceMatchesCallFilter(true, "no restrictions", callingUid); return true; } @@ -419,6 +421,7 @@ public class ZenModeFiltering { private synchronized void recordCallers(String[] people, ArraySet<String> phoneNumbers, long now) { + boolean recorded = false, hasTel = false, hasOther = false; for (int i = 0; i < people.length; i++) { String person = people[i]; if (person == null) continue; @@ -427,10 +430,16 @@ public class ZenModeFiltering { // while ideally we should not need to decode this, sometimes we have seen tel // numbers given in an encoded format String tel = Uri.decode(uri.getSchemeSpecificPart()); - if (tel != null) mTelCalls.put(tel, now); + if (tel != null) { + mTelCalls.put(tel, now); + recorded = true; + hasTel = true; + } } else { // for non-tel calls, store the entire string, uri-component and all mOtherCalls.put(person, now); + recorded = true; + hasOther = true; } } @@ -438,9 +447,16 @@ public class ZenModeFiltering { // provided; these are in the format of just a phone number string if (phoneNumbers != null) { for (String num : phoneNumbers) { - if (num != null) mTelCalls.put(num, now); + if (num != null) { + mTelCalls.put(num, now); + recorded = true; + hasTel = true; + } } } + if (recorded) { + ZenLog.traceRecordCaller(hasTel, hasOther); + } } // helper function to check mTelCalls array for a number, and also check its decoded @@ -468,6 +484,8 @@ public class ZenModeFiltering { // previously recorded phone call. private synchronized boolean checkCallers(Context context, String[] people, ArraySet<String> phoneNumbers) { + boolean found = false, checkedTel = false, checkedOther = false; + // get the default country code for checking telephone numbers final String defaultCountryCode = context.getSystemService(TelephonyManager.class).getNetworkCountryIso(); @@ -477,12 +495,14 @@ public class ZenModeFiltering { final Uri uri = Uri.parse(person); if ("tel".equals(uri.getScheme())) { String number = uri.getSchemeSpecificPart(); + checkedTel = true; if (checkForNumber(number, defaultCountryCode)) { - return true; + found = true; } } else { + checkedOther = true; if (mOtherCalls.containsKey(person)) { - return true; + found = true; } } } @@ -490,14 +510,16 @@ public class ZenModeFiltering { // also check any passed-in phone numbers if (phoneNumbers != null) { for (String num : phoneNumbers) { + checkedTel = true; if (checkForNumber(num, defaultCountryCode)) { - return true; + found = true; } } } // no matches - return false; + ZenLog.traceCheckRepeatCaller(found, checkedTel, checkedOther); + return found; } } diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 6135fe8acbed..d42667951608 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -177,10 +177,12 @@ public class ZenModeHelper { } public boolean matchesCallFilter(UserHandle userHandle, Bundle extras, - ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) { + ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity, + int callingUid) { synchronized (mConfig) { return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConsolidatedPolicy, - userHandle, extras, validator, contactsTimeoutMs, timeoutAffinity); + userHandle, extras, validator, contactsTimeoutMs, timeoutAffinity, + callingUid); } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java index 8ac729e29424..c7905a0e8056 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java @@ -8,7 +8,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distriZenbuted on an "AS IS" BASIS, + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -397,10 +397,10 @@ public class ZenModeFilteringTest extends UiServiceTestCase { Bundle inputWrong = makeExtrasBundleWithPeople(new String[]{"mailto:nope"}); assertTrue(ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - inputMatches, null, 0, 0)); + inputMatches, null, 0, 0, 0)); assertFalse(ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - inputWrong, null, 0, 0)); + inputWrong, null, 0, 0, 0)); } @Test @@ -428,19 +428,19 @@ public class ZenModeFilteringTest extends UiServiceTestCase { assertTrue("identical numbers should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - identical, null, 0, 0)); + identical, null, 0, 0, 0)); assertTrue("equivalent but non-identical numbers should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - same, null, 0, 0)); + same, null, 0, 0, 0)); assertFalse("non-equivalent numbers should not match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - different, null, 0, 0)); + different, null, 0, 0, 0)); assertFalse("non-tel strings should not match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - garbage, null, 0, 0)); + garbage, null, 0, 0, 0)); } @Test @@ -469,23 +469,23 @@ public class ZenModeFilteringTest extends UiServiceTestCase { assertTrue("same number 1 should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - same1, null, 0, 0)); + same1, null, 0, 0, 0)); assertTrue("same number 2 should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - same2, null, 0, 0)); + same2, null, 0, 0, 0)); assertTrue("same number 3 should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - same3, null, 0, 0)); + same3, null, 0, 0, 0)); assertFalse("different number 1 should not match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - different1, null, 0, 0)); + different1, null, 0, 0, 0)); assertFalse("different number 2 should not match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - different2, null, 0, 0)); + different2, null, 0, 0, 0)); } @Test @@ -516,14 +516,14 @@ public class ZenModeFilteringTest extends UiServiceTestCase { assertTrue("contact number 1 should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - tel1, null, 0, 0)); + tel1, null, 0, 0, 0)); assertTrue("contact number 2 should match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - tel2, null, 0, 0)); + tel2, null, 0, 0, 0)); assertFalse("different number should not match", ZenModeFiltering.matchesCallFilter(mContext, ZEN_MODE_IMPORTANT_INTERRUPTIONS, policy, UserHandle.SYSTEM, - different, null, 0, 0)); + different, null, 0, 0, 0)); } } |