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

Commit 633130f6 authored by Paul Hu's avatar Paul Hu Committed by Automerger Merge Worker
Browse files

Merge "Fix EntitlementManager issues" am: 14a8cf0f

Change-Id: I557ef0b3278aa72e34a2290c49dc3c8b82bceaf9
parents a5f7fcac 14a8cf0f
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.net.TetheringConstants.EXTRA_ADD_TETHER_TYPE;
import static android.net.TetheringConstants.EXTRA_PROVISION_CALLBACK;
import static android.net.TetheringConstants.EXTRA_PROVISION_CALLBACK;
import static android.net.TetheringConstants.EXTRA_RUN_PROVISION;
import static android.net.TetheringConstants.EXTRA_RUN_PROVISION;
import static android.net.TetheringManager.TETHERING_BLUETOOTH;
import static android.net.TetheringManager.TETHERING_BLUETOOTH;
import static android.net.TetheringManager.TETHERING_ETHERNET;
import static android.net.TetheringManager.TETHERING_INVALID;
import static android.net.TetheringManager.TETHERING_INVALID;
import static android.net.TetheringManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_WIFI;
import static android.net.TetheringManager.TETHERING_WIFI;
@@ -537,6 +538,7 @@ public class EntitlementManager {
    private static boolean isValidDownstreamType(int type) {
    private static boolean isValidDownstreamType(int type) {
        switch (type) {
        switch (type) {
            case TETHERING_BLUETOOTH:
            case TETHERING_BLUETOOTH:
            case TETHERING_ETHERNET:
            case TETHERING_USB:
            case TETHERING_USB:
            case TETHERING_WIFI:
            case TETHERING_WIFI:
                return true;
                return true;
@@ -650,6 +652,11 @@ public class EntitlementManager {


    private void handleRequestLatestTetheringEntitlementValue(int downstream,
    private void handleRequestLatestTetheringEntitlementValue(int downstream,
            ResultReceiver receiver, boolean showEntitlementUi) {
            ResultReceiver receiver, boolean showEntitlementUi) {
        if (!isValidDownstreamType(downstream)) {
            receiver.send(TETHER_ERROR_ENTITLEMENT_UNKNOWN, null);
            return;
        }

        final TetheringConfiguration config = mFetcher.fetchTetheringConfiguration();
        final TetheringConfiguration config = mFetcher.fetchTetheringConfiguration();
        if (!isTetherProvisioningRequired(config)) {
        if (!isTetherProvisioningRequired(config)) {
            receiver.send(TETHER_ERROR_NO_ERROR, null);
            receiver.send(TETHER_ERROR_NO_ERROR, null);
+32 −0
Original line number Original line Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.server.connectivity.tethering;
package com.android.server.connectivity.tethering;


import static android.net.TetheringManager.TETHERING_BLUETOOTH;
import static android.net.TetheringManager.TETHERING_BLUETOOTH;
import static android.net.TetheringManager.TETHERING_ETHERNET;
import static android.net.TetheringManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_WIFI;
import static android.net.TetheringManager.TETHERING_WIFI;
import static android.net.TetheringManager.TETHERING_WIFI_P2P;
import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
import static android.net.TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
@@ -353,6 +355,20 @@ public final class EntitlementManagerTest {
        callbackTimeoutHelper(mCallbacklatch);
        callbackTimeoutHelper(mCallbacklatch);
        assertEquals(0, mEnMgr.uiProvisionCount);
        assertEquals(0, mEnMgr.uiProvisionCount);
        mEnMgr.reset();
        mEnMgr.reset();
        // 8. Test get value for invalid downstream type.
        mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR;
        receiver = new ResultReceiver(null) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode);
                mCallbacklatch.countDown();
            }
        };
        mEnMgr.requestLatestTetheringEntitlementResult(TETHERING_WIFI_P2P, receiver, true);
        mLooper.dispatchAll();
        callbackTimeoutHelper(mCallbacklatch);
        assertEquals(0, mEnMgr.uiProvisionCount);
        mEnMgr.reset();
    }
    }


    void callbackTimeoutHelper(final CountDownLatch latch) throws Exception {
    void callbackTimeoutHelper(final CountDownLatch latch) throws Exception {
@@ -471,6 +487,22 @@ public final class EntitlementManagerTest {
        mLooper.dispatchAll();
        mLooper.dispatchAll();
        assertEquals(0, mEnMgr.uiProvisionCount);
        assertEquals(0, mEnMgr.uiProvisionCount);
        assertEquals(3, mEnMgr.silentProvisionCount);
        assertEquals(3, mEnMgr.silentProvisionCount);
        assertFalse(mEnMgr.isCellularUpstreamPermitted());
        mEnMgr.reset();
        // 7. start ui provisioning, upstream is mobile, downstream is ethernet
        mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR;
        mEnMgr.startProvisioningIfNeeded(TETHERING_ETHERNET, true);
        mLooper.dispatchAll();
        assertEquals(1, mEnMgr.uiProvisionCount);
        assertEquals(0, mEnMgr.silentProvisionCount);
        assertTrue(mEnMgr.isCellularUpstreamPermitted());
        mEnMgr.reset();
        // 8. downstream is invalid
        mEnMgr.fakeEntitlementResult = TETHER_ERROR_NO_ERROR;
        mEnMgr.startProvisioningIfNeeded(TETHERING_WIFI_P2P, true);
        mLooper.dispatchAll();
        assertEquals(0, mEnMgr.uiProvisionCount);
        assertEquals(0, mEnMgr.silentProvisionCount);
        mEnMgr.reset();
        mEnMgr.reset();
    }
    }