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

Commit b615166c authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 25279 into eclair

* changes:
  Added a field to track if the call is to a voicemail instance.
parents 82df16c6 60d45f0f
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ public class PhoneNumberUtils
            return uri.getSchemeSpecificPart();
        }

        // TODO: We don't check for SecurityException here (requires
        // READ_PHONE_STATE permission).
        if (scheme.equals("voicemail")) {
            return TelephonyManager.getDefault().getVoiceMailNumber();
        }
@@ -1178,6 +1180,35 @@ public class PhoneNumberUtils
        return (number.equals("112") || number.equals("911"));
    }

    /**
     * isVoiceMailNumber: checks a given number against the voicemail
     *   number provided by the RIL and SIM card. The caller must have
     *   the READ_PHONE_STATE credential.
     *
     * @param number the number to look up.
     * @return true if the number is in the list of voicemail. False
     * otherwise, including if the caller does not have the permission
     * to read the VM number.
     * @hide TODO: pending API Council approval
     */
    public static boolean isVoiceMailNumber(String number) {
        String vmNumber;

        try {
            vmNumber = TelephonyManager.getDefault().getVoiceMailNumber();
        } catch (SecurityException ex) {
            return false;
        }

        // Strip the separators from the number before comparing it
        // to the list.
        number = extractNetworkPortion(number);

        // compare tolerates null so we need to make sure that we
        // don't return true when both are null.
        return !TextUtils.isEmpty(number) && compare(number, vmNumber);
    }

    /**
     * Translates any alphabetic letters (i.e. [A-Za-z]) in the
     * specified phone number into the equivalent numeric digits,
+76 −29
Original line number Diff line number Diff line
@@ -101,13 +101,12 @@ public class CallerInfo {
    public boolean isCachedPhotoCurrent;

    private boolean mIsEmergency;

    // Don't keep checking VM if it's going to throw an exception for this proc.
    private static boolean sSkipVmCheck = false;
    private boolean mIsVoiceMail;

    public CallerInfo() {
        // TODO: Move all the basic initialization here?
        mIsEmergency = false;
        mIsVoiceMail = false;
    }

    /**
@@ -220,32 +219,15 @@ public class CallerInfo {
    public static CallerInfo getCallerInfo(Context context, String number) {
        if (TextUtils.isEmpty(number)) {
            return null;
        } else {
        }

        // Change the callerInfo number ONLY if it is an emergency number
        // or if it is the voicemail number.  If it is either, take a
        // shortcut and skip the query.
        if (PhoneNumberUtils.isEmergencyNumber(number)) {
            return new CallerInfo().markAsEmergency(context);
            } else {
                try {
                    if (!sSkipVmCheck && PhoneNumberUtils.compare(number,
                                TelephonyManager.getDefault().getVoiceMailNumber())) {
                        CallerInfo ci = new CallerInfo();

                        // Note we're setting the phone number here (refer to javadoc
                        // comments at the top of CallerInfo class).
                        ci.phoneNumber = TelephonyManager.getDefault().getVoiceMailAlphaTag();
                        // TODO: FIND ANOTHER ICON
                        //info.photoResource = android.R.drawable.badge_voicemail;
                        return ci;
                    }
                } catch (SecurityException ex) {
                    // Don't crash if this process doesn't have permission to
                    // retrieve VM number.  It's still allowed to look up caller info.
                    // But don't try it again.
                    sSkipVmCheck = true;
                }
            }
        } else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
            return new CallerInfo().markAsVoiceMail();
        }

        Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
@@ -303,6 +285,13 @@ public class CallerInfo {
        return mIsEmergency;
    }

    /**
     * @return true if the caller info is a voicemail number.
     */
    public boolean isVoiceMailNumber() {
        return mIsVoiceMail;
    }

    /**
     * Mark this CallerInfo as an emergency call.
     * @param context To lookup the localized 'Emergency Number' string.
@@ -323,6 +312,37 @@ public class CallerInfo {
        return this;
    }


    /**
     * Mark this CallerInfo as a voicemail call. The voicemail label
     * is obtained from the telephony manager. Caller must hold the
     * READ_PHONE_STATE permission otherwise the phoneNumber will be
     * set to null.
     * @return this instance.
     */
    // TODO: As in the emergency number handling, we end up writing a
    // string in the phone number field.
    /* package */ CallerInfo markAsVoiceMail() {
        mIsVoiceMail = true;

        try {
            String voiceMailLabel = TelephonyManager.getDefault().getVoiceMailAlphaTag();

            phoneNumber = voiceMailLabel;
        } catch (SecurityException se) {
            // Should never happen: if this process does not have
            // permission to retrieve VM tag, it should not have
            // permission to retrieve VM number and would not call
            // this method.
            // Leave phoneNumber untouched.
            Log.e(TAG, "Cannot access VoiceMail.", se);
        }
        // TODO: There is no voicemail picture?
        // FIXME: FIND ANOTHER ICON
        // photoResource = android.R.drawable.badge_voicemail;
        return this;
    }

    private static String normalize(String s) {
        if (s == null || s.length() > 0) {
            return s;
@@ -330,4 +350,31 @@ public class CallerInfo {
            return null;
        }
    }

    /**
     * @return a string debug representation of this instance.
     */
    public String toString() {
        return new StringBuilder(384)
                .append("\nname: " + name)
                .append("\nphoneNumber: " + phoneNumber)
                .append("\ncnapName: " + cnapName)
                .append("\nnumberPresentation: " + numberPresentation)
                .append("\nnamePresentation: " + namePresentation)
                .append("\ncontactExits: " + contactExists)
                .append("\nphoneLabel: " + phoneLabel)
                .append("\nnumberType: " + numberType)
                .append("\nnumberLabel: " + numberLabel)
                .append("\nphotoResource: " + photoResource)
                .append("\nperson_id: " + person_id)
                .append("\nneedUpdate: " + needUpdate)
                .append("\ncontactRefUri: " + contactRefUri)
                .append("\ncontactRingtoneUri: " + contactRefUri)
                .append("\nshouldSendToVoicemail: " + shouldSendToVoicemail)
                .append("\ncachedPhoto: " + cachedPhoto)
                .append("\nisCachedPhotoCurrent: " + isCachedPhotoCurrent)
                .append("\nemergency: " + mIsEmergency)
                .append("\nvoicemail " + mIsVoiceMail)
                .toString();
    }
}
+5 −32
Original line number Diff line number Diff line
@@ -47,9 +47,6 @@ public class CallerInfoAsyncQuery {

    private CallerInfoAsyncQueryHandler mHandler;

    // Don't keep checking VM if it's going to throw an exception for this proc.
    private static boolean sSkipVmCheck = false;

    /**
     * Interface for a CallerInfoAsyncQueryHandler result return.
     */
@@ -227,18 +224,7 @@ public class CallerInfoAsyncQuery {
                    // comments at the top of CallerInfo class).
                    mCallerInfo = new CallerInfo().markAsEmergency(mQueryContext);
                } else if (cw.event == EVENT_VOICEMAIL_NUMBER) {
                    mCallerInfo = new CallerInfo();
                    try {
                        // Note we're setting the phone number here (refer to javadoc
                        // comments at the top of CallerInfo class).
                        mCallerInfo.phoneNumber =
                                TelephonyManager.getDefault().getVoiceMailAlphaTag();
                    } catch (SecurityException ex) {
                        // Should never happen: if this process does not have
                        // permission to retrieve VM tag, it should not have
                        // permission to retrieve VM number and would not generate
                        // an EVENT_VOICEMAIL_NUMBER.  But if it happens, don't crash.
                    }
                    mCallerInfo = new CallerInfo().markAsVoiceMail();
                } else {
                    mCallerInfo = CallerInfo.getCallerInfo(mQueryContext, mQueryUri, cursor);
                    // Use the number entered by the user for display.
@@ -258,7 +244,7 @@ public class CallerInfoAsyncQuery {
            //notify the listener that the query is complete.
            if (cw.listener != null) {
                if (DBG) log("notifying listener: " + cw.listener.getClass().toString() +
                        " for token: " + token);
                             " for token: " + token + mCallerInfo);
                cw.listener.onQueryComplete(token, cw.cookie, mCallerInfo);
            }
        }
@@ -315,24 +301,11 @@ public class CallerInfoAsyncQuery {
        // check to see if these are recognized numbers, and use shortcuts if we can.
        if (PhoneNumberUtils.isEmergencyNumber(number)) {
            cw.event = EVENT_EMERGENCY_NUMBER;
        } else {
            String vmNumber = null;
            if (!sSkipVmCheck){
                try {
                    vmNumber = TelephonyManager.getDefault().getVoiceMailNumber();
                } catch (SecurityException ex) {
                    // Don't crash if this process doesn't have permission to
                    // retrieve VM number.  It's still allowed to look up caller info.
                    // But don't try it again.
                    sSkipVmCheck = true;
                }
            }
            if (PhoneNumberUtils.compare(number, vmNumber)) {
        } else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
            cw.event = EVENT_VOICEMAIL_NUMBER;
        } else {
            cw.event = EVENT_NEW_QUERY;
        }
        }

        c.mHandler.startQuery (token, cw, contactRef, null, null, null, null);

+5 −4
Original line number Diff line number Diff line
@@ -32,4 +32,5 @@
        android:targetPackage="com.android.telephonytest"
        android:label="Telephony unit tests InstrumentationRunner">
    </instrumentation>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class TelephonyUnitTestRunner extends InstrumentationTestRunner {
    public TestSuite getAllTests() {
        TestSuite suite = new InstrumentationTestSuite(this);
        suite.addTestSuite(com.android.telephonytest.unit.CallerInfoUnitTest.class);
        suite.addTestSuite(com.android.telephonytest.unit.PhoneNumberUtilsUnitTest.class);
        return suite;
    }

Loading