diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-03-08 02:50:26 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-03-08 02:50:26 +0000 |
commit | d2186758f163f0808379cfdce56223032ed8b437 (patch) | |
tree | 1756a87c6a845b9d81edb95c2e05ac60cbc53411 /java | |
parent | 2de4a3e679ecdaf9a6ea767ce9be5c92472b29d0 (diff) | |
parent | a8d677fce88d2add418cdcc868f2a00b2e2d702e (diff) |
Merge changes I23025e9b,Ic9486b3f
* changes:
Support local emergency phone number check when there are multiple SIMs.
Add additional logging to missed call notification code path
Diffstat (limited to 'java')
6 files changed, 98 insertions, 3 deletions
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java b/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java index 641be854a..f24b3cd98 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java @@ -46,6 +46,8 @@ public class MissedCallNotificationReceiver extends BroadcastReceiver { return; } + LogUtil.enterBlock("MissedCallNotificationReceiver.onReceive"); + int count = intent.getIntExtra( EXTRA_NOTIFICATION_COUNT, CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT); diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java index 80901ce88..158ae2b03 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java @@ -106,6 +106,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { @VisibleForTesting @WorkerThread void updateMissedCallNotification(int count, @Nullable String number) { + LogUtil.enterBlock("MissedCallNotifier.updateMissedCallNotification"); + final int titleResId; CharSequence expandedText; // The text in the notification's line 1 and 2. @@ -137,6 +139,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { if (count == CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT) { // If the intent did not contain a count, and we are unable to get a count from the // call log, then no notification can be shown. + LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "unknown missed call count"); return; } @@ -144,6 +147,9 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { boolean useCallList = newCalls != null; if (count == 1) { + LogUtil.i( + "MissedCallNotifier.updateMissedCallNotification", + "1 missed call, looking up contact info"); NewCall call = useCallList ? newCalls.get(0) @@ -188,6 +194,8 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> { expandedText = context.getString(R.string.notification_missedCallsMsg, count); } + LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "preparing notification"); + // Create a public viewable version of the notification, suitable for display when sensitive // notification content is hidden. Notification.Builder publicSummaryBuilder = createNotificationBuilder(); diff --git a/java/com/android/dialer/assisteddialing/Constraints.java b/java/com/android/dialer/assisteddialing/Constraints.java index 788b875ff..cae3734be 100644 --- a/java/com/android/dialer/assisteddialing/Constraints.java +++ b/java/com/android/dialer/assisteddialing/Constraints.java @@ -25,6 +25,7 @@ import android.text.TextUtils; import com.android.dialer.common.LogUtil; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.strictmode.StrictModeUtils; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; @@ -209,7 +210,7 @@ final class Constraints { // roaming and out of service. boolean result = !PhoneNumberUtils.isEmergencyNumber(numberToCheck) - && !PhoneNumberUtils.isLocalEmergencyNumber(context, numberToCheck); + && !PhoneNumberHelper.isLocalEmergencyNumber(context, numberToCheck); LogUtil.i("Constraints.isNotEmergencyNumber", String.valueOf(result)); return result; } diff --git a/java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java b/java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java new file mode 100644 index 000000000..178a7b21d --- /dev/null +++ b/java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +package com.android.dialer.oem; + +import android.content.Context; +import android.telephony.PhoneNumberUtils; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** Provides access to hidden APIs in {@link android.telephony.PhoneNumberUtils}. */ +public final class PhoneNumberUtilsAccessor { + + /** + * Checks if a given number is an emergency number for the country that the user is in. + * + * @param subId the subscription ID of the SIM + * @param number the number to check + * @param context the specific context which the number should be checked against + * @return true if the specified number is an emergency number for the country the user is + * currently in. + */ + public static boolean isLocalEmergencyNumber(Context context, int subId, String number) { + try { + Method method = + PhoneNumberUtils.class.getMethod( + "isLocalEmergencyNumber", Context.class, int.class, String.class); + return (boolean) method.invoke(null, context, subId, number); + + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } +} diff --git a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java index e1051951e..33a94ea74 100644 --- a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java +++ b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java @@ -25,6 +25,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.telecom.PhoneAccountHandle; import android.telephony.PhoneNumberUtils; +import android.telephony.SubscriptionInfo; import android.telephony.TelephonyManager; import android.text.BidiFormatter; import android.text.TextDirectionHeuristics; @@ -34,10 +35,13 @@ import com.android.dialer.common.LogUtil; import com.android.dialer.compat.CompatUtils; import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.oem.MotorolaUtils; +import com.android.dialer.oem.PhoneNumberUtilsAccessor; import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtilComponent; import com.android.dialer.telecom.TelecomUtil; +import com.google.common.base.Optional; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; public class PhoneNumberHelper { @@ -138,6 +142,39 @@ public class PhoneNumberHelper { } /** + * An enhanced version of {@link PhoneNumberUtils#isLocalEmergencyNumber(Context, String)}. + * + * <p>This methods supports checking the number for all SIMs. + * + * @param context the context which the number should be checked against + * @param number the number to tbe checked + * @return true if the specified number is an emergency number for any SIM in the device. + */ + @SuppressWarnings("Guava") + public static boolean isLocalEmergencyNumber(Context context, String number) { + List<PhoneAccountHandle> phoneAccountHandles = + TelecomUtil.getSubscriptionPhoneAccounts(context); + + // If the number of phone accounts with a subscription is no greater than 1, only one SIM is + // installed in the device. We hand over the job to PhoneNumberUtils#isLocalEmergencyNumber. + if (phoneAccountHandles.size() <= 1) { + return PhoneNumberUtils.isLocalEmergencyNumber(context, number); + } + + for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) { + Optional<SubscriptionInfo> subscriptionInfo = + TelecomUtil.getSubscriptionInfo(context, phoneAccountHandle); + if (subscriptionInfo.isPresent() + && PhoneNumberUtilsAccessor.isLocalEmergencyNumber( + context, subscriptionInfo.get().getSubscriptionId(), number)) { + return true; + } + } + + return false; + } + + /** * Returns true if the given number is the number of the configured voicemail. To be able to * mock-out this, it is not a static method. */ diff --git a/java/com/android/incallui/CallerInfoAsyncQuery.java b/java/com/android/incallui/CallerInfoAsyncQuery.java index 335895220..87dcc4f40 100644 --- a/java/com/android/incallui/CallerInfoAsyncQuery.java +++ b/java/com/android/incallui/CallerInfoAsyncQuery.java @@ -35,13 +35,13 @@ import android.provider.ContactsContract.Directory; import android.support.annotation.MainThread; import android.support.annotation.RequiresPermission; import android.support.annotation.WorkerThread; -import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.phonenumbercache.CachedNumberLookupService; import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo; import com.android.dialer.phonenumbercache.ContactInfoHelper; import com.android.dialer.phonenumbercache.PhoneNumberCache; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.strictmode.StrictModeUtils; import java.io.IOException; import java.io.InputStream; @@ -166,7 +166,7 @@ public class CallerInfoAsyncQuery { cw.countryIso = info.countryIso; // check to see if these are recognized numbers, and use shortcuts if we can. - if (PhoneNumberUtils.isLocalEmergencyNumber(context, info.phoneNumber)) { + if (PhoneNumberHelper.isLocalEmergencyNumber(context, info.phoneNumber)) { cw.event = EVENT_EMERGENCY_NUMBER; } else if (info.isVoiceMailNumber()) { cw.event = EVENT_VOICEMAIL_NUMBER; |