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

Commit 5cbd1a75 authored by junyulai's avatar junyulai
Browse files

Add getAllCollapsedRatTypes to NetworkTemplate

This is a partial cherry-pick of ag/10293594

Test: TH
Bug: 129082217

Merged-In: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
Change-Id: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
parent 5063505f
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.ROAMING_YES;
import static android.net.wifi.WifiInfo.sanitizeSsid;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
@@ -52,6 +53,8 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

@@ -489,6 +492,32 @@ public class NetworkTemplate implements Parcelable {
        }
    }

    /**
     * Return all supported collapsed RAT types that could be returned by
     * {@link #getCollapsedRatType(int)}.
     */
    @NonNull
    public static final int[] getAllCollapsedRatTypes() {
        final int[] ratTypes = TelephonyManager.getAllNetworkTypes();
        final HashSet<Integer> collapsedRatTypes = new HashSet<>();
        for (final int ratType : ratTypes) {
            collapsedRatTypes.add(NetworkTemplate.getCollapsedRatType(ratType));
        }
        // Ensure that unknown type is returned.
        collapsedRatTypes.add(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        return toIntArray(collapsedRatTypes);
    }

    @NonNull
    private static int[] toIntArray(@NonNull Collection<Integer> list) {
        final int[] array = new int[list.size()];
        int i = 0;
        for (final Integer item : list) {
            array[i++] = item;
        }
        return array;
    }

    /**
     * Check if matches Wi-Fi network template.
     */