Merge tm-dev-plus-aosp-without-vendor@8763363

Bug: 236760014
Merged-In: I81c01202306d856f6f8f8b74a5a28d7c1011fcec
Change-Id: If491aeefb40d37249174a40dfe1e37a978addf73
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b25ff16..fffcdab 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -47,6 +47,7 @@
     <uses-permission android:name="android.permission.CALL_PHONE" />
     <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
 
     <!--  Optional features -->
     <uses-feature android:name="android.hardware.camera" android:required="false" />
diff --git a/src/com/android/messaging/util/MediaMetadataRetrieverWrapper.java b/src/com/android/messaging/util/MediaMetadataRetrieverWrapper.java
index b1078d1..1a93e9d 100644
--- a/src/com/android/messaging/util/MediaMetadataRetrieverWrapper.java
+++ b/src/com/android/messaging/util/MediaMetadataRetrieverWrapper.java
@@ -74,7 +74,7 @@
     public void release() {
         try {
             mRetriever.release();
-        } catch (RuntimeException e) {
+        } catch (RuntimeException | IOException e) {
             LogUtil.e(LogUtil.BUGLE_TAG, "MediaMetadataRetriever.release failed", e);
         }
     }
diff --git a/src/com/android/messaging/util/PhoneUtils.java b/src/com/android/messaging/util/PhoneUtils.java
index 671c65e..08889b8 100644
--- a/src/com/android/messaging/util/PhoneUtils.java
+++ b/src/com/android/messaging/util/PhoneUtils.java
@@ -26,7 +26,6 @@
 import android.net.ConnectivityManager;
 import android.provider.Settings;
 import android.provider.Telephony;
-import androidx.collection.ArrayMap;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.SmsManager;
 import android.telephony.SubscriptionInfo;
@@ -34,14 +33,18 @@
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 
+import androidx.collection.ArrayMap;
+import androidx.core.os.BuildCompat;
+
 import com.android.messaging.Factory;
 import com.android.messaging.R;
 import com.android.messaging.datamodel.data.ParticipantData;
 import com.android.messaging.sms.MmsSmsUtils;
+
 import com.google.i18n.phonenumbers.NumberParseException;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
 import com.google.i18n.phonenumbers.PhoneNumberUtil;
 import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -369,6 +372,9 @@
         @Override
         @SuppressWarnings("deprecation")
         public boolean isDataRoamingEnabled() {
+            if (BuildCompat.isAtLeastT()) {
+                return mTelephonyManager.isDataRoamingEnabled();
+            }
             boolean dataRoamingEnabled = false;
             final ContentResolver cr = mContext.getContentResolver();
             if (OsUtil.isAtLeastJB_MR1()) {
diff --git a/src/com/android/messaging/util/UriUtil.java b/src/com/android/messaging/util/UriUtil.java
index 6e39749..f92155f 100644
--- a/src/com/android/messaging/util/UriUtil.java
+++ b/src/com/android/messaging/util/UriUtil.java
@@ -49,6 +49,8 @@
     private static final String SCHEME_MMSTO = "smsto";
     public static final HashSet<String> SMS_MMS_SCHEMES = new HashSet<String>(
         Arrays.asList(SCHEME_SMS, SCHEME_MMS, SCHEME_SMSTO, SCHEME_MMSTO));
+    private static final String SCHEME_HTTP = "http";
+    private static final String SCHEME_HTTPS = "https";
 
     public static final String SCHEME_BUGLE = "bugle";
     public static final HashSet<String> SUPPORTED_SCHEME = new HashSet<String>(
@@ -98,8 +100,7 @@
     public static boolean isFileUri(final Uri uri) {
         return uri != null &&
                 uri.getScheme() != null &&
-                TextUtils.equals(uri.getScheme().trim().toLowerCase(),
-                        ContentResolver.SCHEME_FILE);
+                uri.getScheme().trim().toLowerCase().contains(ContentResolver.SCHEME_FILE);
     }
 
     /**
@@ -216,9 +217,10 @@
                 inputStream = context.getContentResolver().openInputStream(sourceUri);
             } else {
                 // The content is remote. Download it.
-                final URL url = new URL(sourceUri.toString());
-                final URLConnection ucon = url.openConnection();
-                inputStream = new BufferedInputStream(ucon.getInputStream());
+                inputStream = getInputStreamFromRemoteUri(sourceUri);
+                if (inputStream == null) {
+                    return null;
+                }
             }
             return persistContentToScratchSpace(inputStream);
         } catch (final Exception ex) {
@@ -235,6 +237,23 @@
         }
     }
 
+    @DoesNotRunOnMainThread
+    private static InputStream getInputStreamFromRemoteUri(final Uri sourceUri)
+            throws IOException {
+        if (isRemoteUri(sourceUri)) {
+            final URL url = new URL(sourceUri.toString());
+            final URLConnection ucon = url.openConnection();
+            return new BufferedInputStream(ucon.getInputStream());
+        } else {
+            return null;
+        }
+    }
+
+    private static boolean isRemoteUri(final Uri sourceUri) {
+        return sourceUri.getScheme().equals(SCHEME_HTTP)
+            || sourceUri.getScheme().equals(SCHEME_HTTPS);
+    }
+
     /**
      * Persist a piece of content from the given input stream, byte by byte to the specified
      * directory.
@@ -273,9 +292,10 @@
                 inputStream = context.getContentResolver().openInputStream(sourceUri);
             } else {
                 // The content is remote. Download it.
-                final URL url = new URL(sourceUri.toString());
-                final URLConnection ucon = url.openConnection();
-                inputStream = new BufferedInputStream(ucon.getInputStream());
+                inputStream = getInputStreamFromRemoteUri(sourceUri);
+                if (inputStream == null) {
+                    return null;
+                }
             }
             return persistContent(inputStream, outputDir, contentType);
         } catch (final Exception ex) {