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

Commit 0ab66f6c authored by paulhu's avatar paulhu
Browse files

Fix EntitlementManager issues

1. Add TETHERING_ETHERNET to vaild downstream type. So starting
   ethernet tethering will do entitlement check as well.
2. Ignore request with invalid downstream type on
   handleRequestLatestTetheringEntitlementValue()

Bug: 152828758
Bug: 152828142
Test: atests TetheringTests CtsTetheringTest

Change-Id: Id0cb59cc4681f5ffbde7be54de05a05e46f0ffb8
parent bb387436
Loading
Loading
Loading
Loading
+7 −0
Original line number 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_RUN_PROVISION;
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_USB;
import static android.net.TetheringManager.TETHERING_WIFI;
@@ -537,6 +538,7 @@ public class EntitlementManager {
    private static boolean isValidDownstreamType(int type) {
        switch (type) {
            case TETHERING_BLUETOOTH:
            case TETHERING_ETHERNET:
            case TETHERING_USB:
            case TETHERING_WIFI:
                return true;
@@ -650,6 +652,11 @@ public class EntitlementManager {

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

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

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_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_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
@@ -353,6 +355,20 @@ public final class EntitlementManagerTest {
        callbackTimeoutHelper(mCallbacklatch);
        assertEquals(0, mEnMgr.uiProvisionCount);
        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 {
@@ -471,6 +487,22 @@ public final class EntitlementManagerTest {
        mLooper.dispatchAll();
        assertEquals(0, mEnMgr.uiProvisionCount);
        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();
    }