Revert "Replace the usage of UidRange"

Revert "Add shims for NetworkRequest"

Revert submission 1626206-replaceUidRange

Reason for revert: Breaking build - b/183106405
Reverted Changes:
I0b79c73e8:Add shims for NetworkRequest
I4bc0daf5a:Replace the usage of UidRange
I4e5aec6ef:Replace the usage of UidRange
I107c329d4:Expose uids related APIs in NetworkRequest and Net...

Change-Id: I6290429db1c8e787f8138b55b98fd92a74ac6402
diff --git a/framework/src/android/net/NetworkCapabilities.java b/framework/src/android/net/NetworkCapabilities.java
index ba9f21b..058f3c9 100644
--- a/framework/src/android/net/NetworkCapabilities.java
+++ b/framework/src/android/net/NetworkCapabilities.java
@@ -32,7 +32,6 @@
 import android.os.Process;
 import android.text.TextUtils;
 import android.util.ArraySet;
-import android.util.Range;
 import android.util.proto.ProtoOutputStream;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -154,7 +153,7 @@
             setTransportInfo(null);
         }
         mSignalStrength = nc.mSignalStrength;
-        mUids = (nc.mUids == null) ? null : new ArraySet<>(nc.mUids);
+        setUids(nc.mUids); // Will make the defensive copy
         setAdministratorUids(nc.getAdministratorUids());
         mOwnerUid = nc.mOwnerUid;
         mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
@@ -1459,8 +1458,9 @@
      * @hide
      */
     public @NonNull NetworkCapabilities setSingleUid(int uid) {
-        mUids = new ArraySet<>(1);
-        mUids.add(new UidRange(uid, uid));
+        final ArraySet<UidRange> identity = new ArraySet<>(1);
+        identity.add(new UidRange(uid, uid));
+        setUids(identity);
         return this;
     }
 
@@ -1469,8 +1469,12 @@
      * This makes a copy of the set so that callers can't modify it after the call.
      * @hide
      */
-    public @NonNull NetworkCapabilities setUids(@Nullable Set<Range<Integer>> uids) {
-        mUids = UidRange.fromIntRanges(uids);
+    public @NonNull NetworkCapabilities setUids(Set<UidRange> uids) {
+        if (null == uids) {
+            mUids = null;
+        } else {
+            mUids = new ArraySet<>(uids);
+        }
         return this;
     }
 
@@ -1479,19 +1483,8 @@
      * This returns a copy of the set so that callers can't modify the original object.
      * @hide
      */
-    public @Nullable Set<Range<Integer>> getUids() {
-        return UidRange.toIntRanges(mUids);
-    }
-
-    /**
-     * Get the list of UIDs this network applies to.
-     * This returns a copy of the set so that callers can't modify the original object.
-     * @hide
-     */
-    public @Nullable Set<UidRange> getUidRanges() {
-        if (mUids == null) return null;
-
-        return new ArraySet<>(mUids);
+    public @Nullable Set<UidRange> getUids() {
+        return null == mUids ? null : new ArraySet<>(mUids);
     }
 
     /**
diff --git a/framework/src/android/net/NetworkRequest.java b/framework/src/android/net/NetworkRequest.java
index 4ebbf06..dbe3ecc 100644
--- a/framework/src/android/net/NetworkRequest.java
+++ b/framework/src/android/net/NetworkRequest.java
@@ -45,7 +45,6 @@
 import android.os.Parcelable;
 import android.os.Process;
 import android.text.TextUtils;
-import android.util.Range;
 import android.util.proto.ProtoOutputStream;
 
 import java.util.Arrays;
@@ -278,11 +277,11 @@
          * Set the watched UIDs for this request. This will be reset and wiped out unless
          * the calling app holds the CHANGE_NETWORK_STATE permission.
          *
-         * @param uids The watched UIDs as a set of {@code Range<Integer>}, or null for everything.
+         * @param uids The watched UIDs as a set of UidRanges, or null for everything.
          * @return The builder to facilitate chaining.
          * @hide
          */
-        public Builder setUids(@Nullable Set<Range<Integer>> uids) {
+        public Builder setUids(Set<UidRange> uids) {
             mNetworkCapabilities.setUids(uids);
             return this;
         }
diff --git a/framework/src/android/net/UidRange.java b/framework/src/android/net/UidRange.java
index bc67c74..26518d3 100644
--- a/framework/src/android/net/UidRange.java
+++ b/framework/src/android/net/UidRange.java
@@ -20,11 +20,8 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.UserHandle;
-import android.util.ArraySet;
-import android.util.Range;
 
 import java.util.Collection;
-import java.util.Set;
 
 /**
  * An inclusive range of UIDs.
@@ -152,32 +149,4 @@
         }
         return false;
     }
-
-    /**
-     *  Convert a set of {@code Range<Integer>} to a set of {@link UidRange}.
-     */
-    @Nullable
-    public static ArraySet<UidRange> fromIntRanges(@Nullable Set<Range<Integer>> ranges) {
-        if (null == ranges) return null;
-
-        final ArraySet<UidRange> uids = new ArraySet<>();
-        for (Range<Integer> range : ranges) {
-            uids.add(new UidRange(range.getLower(), range.getUpper()));
-        }
-        return uids;
-    }
-
-    /**
-     *  Convert a set of {@link UidRange} to a set of {@code Range<Integer>}.
-     */
-    @Nullable
-    public static ArraySet<Range<Integer>> toIntRanges(@Nullable Set<UidRange> ranges) {
-        if (null == ranges) return null;
-
-        final ArraySet<Range<Integer>> uids = new ArraySet<>();
-        for (UidRange range : ranges) {
-            uids.add(new Range<Integer>(range.start, range.stop));
-        }
-        return uids;
-    }
 }