Let formatInOriginalFormat to return raw_input for invalid phone
numbers.

Bug: 5412333
Change-Id: I029e6b19ca1e07098971b9622f9d0e83a3259b8c
diff --git a/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java b/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java
index 745fb7d..230b8bf 100644
--- a/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java
+++ b/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java
@@ -1216,7 +1216,8 @@
    * Formats a phone number using the original phone number format that the number is parsed from.
    * The original format is embedded in the country_code_source field of the PhoneNumber object
    * passed in. If such information is missing, the number will be formatted into the NATIONAL
-   * format by default.
+   * format by default. When the number is an invalid number, the method returns the raw input when
+   * it is available.
    *
    * @param number  the phone number that needs to be formatted in its original number format
    * @param regionCallingFrom  the region whose IDD needs to be prefixed if the original number
@@ -1224,6 +1225,9 @@
    * @return  the formatted phone number in its original number format
    */
   public String formatInOriginalFormat(PhoneNumber number, String regionCallingFrom) {
+    if (number.hasRawInput() && !isValidNumber(number)) {
+      return number.getRawInput();
+    }
     if (!number.hasCountryCodeSource()) {
       return format(number, PhoneNumberFormat.NATIONAL);
     }