DO NOT MERGE: Update DownloadProvider for correct meteredness

This patch updates DownloadProvider to use the fixed meteredness hidden
APIs for OC-MR1. This corrects a bug where DownloadProvider would fail
to allow downloads to proceed when VPNs are connected, but the
underlying networks are metered.

Bug: 78644887
Test: Flashed on Walleye and tested.
Change-Id: I13c1bd6d7ab26489923329bc7985060228e9bb29
(cherry picked from commit b627002ea9dc2511bad6ea5e68f4248f36c4a3eb)
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 9c92005..d3ec568 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -725,7 +725,7 @@
         if (info.isRoaming() && !mInfo.isRoamingAllowed()) {
             throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "Network is roaming");
         }
-        if (mSystemFacade.isNetworkMetered(mNetwork)
+        if (mSystemFacade.isActiveNetworkMeteredForUid(mInfo.mUid)
                 && !mInfo.isMeteredAllowed(mInfoDelta.mTotalBytes)) {
             throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "Network is metered");
         }
diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java
index 1c2ba58..2d9b3a3 100644
--- a/src/com/android/providers/downloads/RealSystemFacade.java
+++ b/src/com/android/providers/downloads/RealSystemFacade.java
@@ -68,6 +68,12 @@
     }
 
     @Override
+    public boolean isActiveNetworkMeteredForUid(int uid) {
+        return mContext.getSystemService(ConnectivityManager.class)
+                .isActiveNetworkMeteredForUid(uid);
+    }
+
+    @Override
     public long getMaxBytesOverMobile() {
         final Long value = DownloadManager.getMaxBytesOverMobile(mContext);
         return (value == null) ? Long.MAX_VALUE : value;
diff --git a/src/com/android/providers/downloads/SystemFacade.java b/src/com/android/providers/downloads/SystemFacade.java
index 53d1404..dec0cb2 100644
--- a/src/com/android/providers/downloads/SystemFacade.java
+++ b/src/com/android/providers/downloads/SystemFacade.java
@@ -38,6 +38,8 @@
 
     public boolean isNetworkMetered(Network network);
 
+    public boolean isActiveNetworkMeteredForUid(int uid);
+
     /**
      * @return maximum size, in bytes, of downloads that may go over a mobile connection; or null if
      * there's no limit
diff --git a/tests/src/com/android/providers/downloads/FakeSystemFacade.java b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
index de483c7..aa7b8af 100644
--- a/tests/src/com/android/providers/downloads/FakeSystemFacade.java
+++ b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
@@ -102,6 +102,11 @@
     }
 
     @Override
+    public boolean isActiveNetworkMeteredForUid(int uid) {
+        return mIsMetered;
+    }
+
+    @Override
     public long getMaxBytesOverMobile() {
         return mMaxBytesOverMobile;
     }