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

Commit 6c5b0485 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6330721 from 449ab0c3 to mainline-release

Change-Id: Ic6ef0b772a9585f691076c9fdb09f015f08cfe70
parents 8f3db48a 449ab0c3
Loading
Loading
Loading
Loading
+14 −4
Original line number Original line Diff line number Diff line
@@ -29,7 +29,9 @@ import android.net.ScanResultInfoParcelable;
import android.net.StaticIpConfiguration;
import android.net.StaticIpConfiguration;
import android.net.apf.ApfCapabilities;
import android.net.apf.ApfCapabilities;
import android.net.ip.IIpClient;
import android.net.ip.IIpClient;
import android.util.Log;


import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
@@ -61,6 +63,8 @@ import java.util.StringJoiner;
 * @hide
 * @hide
 */
 */
public class ProvisioningConfiguration {
public class ProvisioningConfiguration {
    private static final String TAG = "ProvisioningConfiguration";

    // TODO: Delete this default timeout once those callers that care are
    // TODO: Delete this default timeout once those callers that care are
    // fixed to pass in their preferred timeout.
    // fixed to pass in their preferred timeout.
    //
    //
@@ -281,7 +285,7 @@ public class ProvisioningConfiguration {
            public InformationElementParcelable toStableParcelable() {
            public InformationElementParcelable toStableParcelable() {
                final InformationElementParcelable p = new InformationElementParcelable();
                final InformationElementParcelable p = new InformationElementParcelable();
                p.id = mId;
                p.id = mId;
                p.payload = mPayload.clone();
                p.payload = mPayload != null ? mPayload.clone() : null;
                return p;
                return p;
            }
            }


@@ -367,12 +371,18 @@ public class ProvisioningConfiguration {


        private static byte[] convertToByteArray(final ByteBuffer buffer) {
        private static byte[] convertToByteArray(final ByteBuffer buffer) {
            if (buffer == null) return null;
            if (buffer == null) return null;
            byte[] bytes = new byte[buffer.limit()];
            final byte[] bytes = new byte[buffer.limit()];
            final ByteBuffer copy = buffer.asReadOnlyBuffer();
            final ByteBuffer copy = buffer.asReadOnlyBuffer();
            try {
                copy.position(0);
                copy.get(bytes);
                copy.get(bytes);
            } catch (BufferUnderflowException e) {
                Log.wtf(TAG, "Buffer under flow exception should never happen.");
            } finally {
                return bytes;
                return bytes;
            }
            }
        }
        }
    }


    public boolean mEnableIPv4 = true;
    public boolean mEnableIPv4 = true;
    public boolean mEnableIPv6 = true;
    public boolean mEnableIPv6 = true;
+2 −1
Original line number Original line Diff line number Diff line
@@ -1591,7 +1591,8 @@ public class NetworkMonitor extends StateMachine {
                DEFAULT_TCP_POLLING_INTERVAL_MS);
                DEFAULT_TCP_POLLING_INTERVAL_MS);
    }
    }


    private URL[] makeCaptivePortalFallbackUrls() {
    @VisibleForTesting
    URL[] makeCaptivePortalFallbackUrls() {
        try {
        try {
            final String firstUrl = mDependencies.getSetting(mContext, CAPTIVE_PORTAL_FALLBACK_URL,
            final String firstUrl = mDependencies.getSetting(mContext, CAPTIVE_PORTAL_FALLBACK_URL,
                    null);
                    null);
+61 −14
Original line number Original line Diff line number Diff line
@@ -204,6 +204,8 @@ public class NetworkMonitorTest {
    private @Mock TcpSocketTracker mTst;
    private @Mock TcpSocketTracker mTst;
    private HashSet<WrappedNetworkMonitor> mCreatedNetworkMonitors;
    private HashSet<WrappedNetworkMonitor> mCreatedNetworkMonitors;
    private HashSet<BroadcastReceiver> mRegisteredReceivers;
    private HashSet<BroadcastReceiver> mRegisteredReceivers;
    private @Mock Context mMccContext;
    private @Mock Resources mMccResource;


    private static final int TEST_NETID = 4242;
    private static final int TEST_NETID = 4242;
    private static final String TEST_HTTP_URL = "http://www.google.com/gen_204";
    private static final String TEST_HTTP_URL = "http://www.google.com/gen_204";
@@ -418,6 +420,8 @@ public class NetworkMonitorTest {


        when(mResources.getString(anyInt())).thenReturn("");
        when(mResources.getString(anyInt())).thenReturn("");
        when(mResources.getStringArray(anyInt())).thenReturn(new String[0]);
        when(mResources.getStringArray(anyInt())).thenReturn(new String[0]);
        doReturn(mConfiguration).when(mResources).getConfiguration();
        when(mMccContext.getResources()).thenReturn(mMccResource);


        setFallbackUrl(TEST_FALLBACK_URL);
        setFallbackUrl(TEST_FALLBACK_URL);
        setOtherFallbackUrls(TEST_OTHER_FALLBACK_URL);
        setOtherFallbackUrls(TEST_OTHER_FALLBACK_URL);
@@ -594,20 +598,10 @@ public class NetworkMonitorTest {
                eq(android.Manifest.permission.ACCESS_FINE_LOCATION),  anyInt(), anyInt());
                eq(android.Manifest.permission.ACCESS_FINE_LOCATION),  anyInt(), anyInt());
        doReturn(new ContextWrapper(mContext)).when(mContext).createConfigurationContext(any());
        doReturn(new ContextWrapper(mContext)).when(mContext).createConfigurationContext(any());
        // Prepare CellInfo and check if the vote mechanism is working or not.
        // Prepare CellInfo and check if the vote mechanism is working or not.
        final CellInfoGsm cellInfoGsm1 = new CellInfoGsm();
        final CellInfoGsm cellInfoGsm2 = new CellInfoGsm();
        final CellInfoLte cellInfoLte = new CellInfoLte();
        final CellIdentityGsm cellIdentityGsm = makeCellIdentityGsm(
                0, 0, 0, 0, "460", "01", "", "");
        final CellIdentityLte cellIdentityLte = makeCellIdentityLte(
                0, 0, 0, 0, 0, "466", "01", "", "");
        cellInfoGsm1.setCellIdentity(cellIdentityGsm);
        cellInfoGsm2.setCellIdentity(cellIdentityGsm);
        cellInfoLte.setCellIdentity(cellIdentityLte);
        final List<CellInfo> cellList = new ArrayList<CellInfo>();
        final List<CellInfo> cellList = new ArrayList<CellInfo>();
        cellList.add(cellInfoGsm1);
        cellList.add(makeTestCellInfoGsm("460"));
        cellList.add(cellInfoGsm2);
        cellList.add(makeTestCellInfoGsm("460"));
        cellList.add(cellInfoLte);
        cellList.add(makeTestCellInfoLte("466"));
        doReturn(cellList).when(mTelephony).getAllCellInfo();
        doReturn(cellList).when(mTelephony).getAllCellInfo();
        // The count of 460 is 2 and the count of 466 is 1, so the getLocationMcc() should return
        // The count of 460 is 2 and the count of 466 is 1, so the getLocationMcc() should return
        // 460.
        // 460.
@@ -616,13 +610,66 @@ public class NetworkMonitorTest {
        // is enabled and the sim is not ready.
        // is enabled and the sim is not ready.
        doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc);
        doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc);
        doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephony).getSimState();
        doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephony).getSimState();
        doReturn(mConfiguration).when(mResources).getConfiguration();
        assertEquals(460,
        assertEquals(460,
                wnm.getContextByMccIfNoSimCardOrDefault().getResources().getConfiguration().mcc);
                wnm.getContextByMccIfNoSimCardOrDefault().getResources().getConfiguration().mcc);
        doReturn(false).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc);
        doReturn(false).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc);
        assertEquals(wnm.getContext(), wnm.getContextByMccIfNoSimCardOrDefault());
        assertEquals(wnm.getContext(), wnm.getContextByMccIfNoSimCardOrDefault());
    }
    }


    private CellInfoGsm makeTestCellInfoGsm(String mcc) throws Exception {
        final CellInfoGsm info = new CellInfoGsm();
        final CellIdentityGsm ci = makeCellIdentityGsm(0, 0, 0, 0, mcc, "01", "", "");
        info.setCellIdentity(ci);
        return info;
    }

    private CellInfoLte makeTestCellInfoLte(String mcc) throws Exception {
        final CellInfoLte info = new CellInfoLte();
        final CellIdentityLte ci = makeCellIdentityLte(0, 0, 0, 0, 0, mcc, "01", "", "");
        info.setCellIdentity(ci);
        return info;
    }

    @Test
    public void testMakeFallbackUrls() throws Exception {
        final WrappedNetworkMonitor wnm = makeNotMeteredNetworkMonitor();
        // Value exist in setting provider.
        URL[] urls = wnm.makeCaptivePortalFallbackUrls();
        assertEquals(urls[0].toString(), TEST_FALLBACK_URL);

        // Clear setting provider value. Verify it to get configuration from resource instead.
        setFallbackUrl(null);
        // Verify that getting resource with exception.
        when(mResources.getStringArray(R.array.config_captive_portal_fallback_urls))
                .thenThrow(Resources.NotFoundException.class);
        urls = wnm.makeCaptivePortalFallbackUrls();
        assertEquals(urls.length, 0);

        // Verify resource return 2 different URLs.
        doReturn(new String[] {"http://testUrl1.com", "http://testUrl2.com"}).when(mResources)
                .getStringArray(R.array.config_captive_portal_fallback_urls);
        urls = wnm.makeCaptivePortalFallbackUrls();
        assertEquals(urls.length, 2);
        assertEquals("http://testUrl1.com", urls[0].toString());
        assertEquals("http://testUrl2.com", urls[1].toString());

        // Value is expected to be replaced by location resource.
        doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc);

        final List<CellInfo> cellList = new ArrayList<CellInfo>();
        final int testMcc = 460;
        cellList.add(makeTestCellInfoGsm(Integer.toString(testMcc)));
        doReturn(cellList).when(mTelephony).getAllCellInfo();
        final Configuration config = mResources.getConfiguration();
        config.mcc = testMcc;
        doReturn(mMccContext).when(mContext).createConfigurationContext(eq(config));
        doReturn(new String[] {"http://testUrl3.com"}).when(mMccResource)
                .getStringArray(R.array.config_captive_portal_fallback_urls);
        urls = wnm.makeCaptivePortalFallbackUrls();
        assertEquals(urls.length, 1);
        assertEquals("http://testUrl3.com", urls[0].toString());
    }

    private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic,
    private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic,
            String mccStr, String mncStr, String alphal, String alphas)
            String mccStr, String mncStr, String alphal, String alphas)
            throws ReflectiveOperationException {
            throws ReflectiveOperationException {