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

Commit 9f246bd9 authored by markchien's avatar markchien
Browse files

Some cleanups for Tethering

Bug: 126481523
Test: -build, flash, boot
      -FrameworksNetTests

Change-Id: I904646efa87eb5434124c7828aca4ab09c5dc38e
parent c6506743
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2617,7 +2617,7 @@ public class ConnectivityManager {

    /**
     * Start listening to tethering change events. Any new added callback will receive the last
     * tethering status right away. If callback is registered when tethering loses its upstream or
     * tethering status right away. If callback is registered when tethering has no upstream or
     * disabled, {@link OnTetheringEventCallback#onUpstreamChanged} will immediately be called
     * with a null argument. The same callback object cannot be registered twice.
     *
+9 −12
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseIntArray;

import com.android.internal.annotations.VisibleForTesting;
@@ -231,7 +230,7 @@ public class EntitlementManager {

    private void handleNotifyUpstream(boolean isCellular) {
        if (DBG) {
            Log.d(TAG, "notifyUpstream: " + isCellular
            mLog.i("notifyUpstream: " + isCellular
                    + ", mCellularUpstreamPermitted: " + mCellularUpstreamPermitted
                    + ", mNeedReRunProvisioningUi: " + mNeedReRunProvisioningUi);
        }
@@ -294,7 +293,7 @@ public class EntitlementManager {
     * masterHandler to avoid race conditions.
     */
    public void reevaluateSimCardProvisioning() {
        if (DBG) Log.d(TAG, "reevaluateSimCardProvisioning");
        if (DBG) mLog.i("reevaluateSimCardProvisioning");

        if (!mHandler.getLooper().isCurrentThread()) {
            // Except for test, this log should not appear in normal flow.
@@ -351,7 +350,7 @@ public class EntitlementManager {
     * @param type tethering type from ConnectivityManager.TETHERING_{@code *}
     */
    protected void runSilentTetherProvisioning(int type) {
        if (DBG) Log.d(TAG, "runSilentTetherProvisioning: " + type);
        if (DBG) mLog.i("runSilentTetherProvisioning: " + type);
        // For silent provisioning, settings would stop tethering when entitlement fail.
        ResultReceiver receiver = buildProxyReceiver(type,
                false/* notifyFail */, null);
@@ -382,7 +381,7 @@ public class EntitlementManager {

    @VisibleForTesting
    protected void runUiTetherProvisioning(int type, ResultReceiver receiver) {
        if (DBG) Log.d(TAG, "runUiTetherProvisioning: " + type);
        if (DBG) mLog.i("runUiTetherProvisioning: " + type);

        Intent intent = new Intent(Settings.ACTION_TETHER_PROVISIONING);
        intent.putExtra(EXTRA_ADD_TETHER_TYPE, type);
@@ -428,7 +427,7 @@ public class EntitlementManager {
                || mCellularPermitted.indexOfValue(TETHER_ERROR_NO_ERROR) > -1);

        if (DBG) {
            Log.d(TAG, "Cellular permission change from " + oldPermitted
            mLog.i("Cellular permission change from " + oldPermitted
                    + " to " + mCellularUpstreamPermitted);
        }

@@ -453,10 +452,8 @@ public class EntitlementManager {
     * @param resultCode Provisioning result
     */
    protected void addDownstreamMapping(int type, int resultCode) {
        if (DBG) {
            Log.d(TAG, "addDownstreamMapping: " + type + ", result: " + resultCode
        mLog.i("addDownstreamMapping: " + type + ", result: " + resultCode
                + " ,TetherTypeRequested: " + mCurrentTethers.contains(type));
        }
        if (!mCurrentTethers.contains(type)) return;

        mCellularPermitted.put(type, resultCode);
@@ -468,7 +465,7 @@ public class EntitlementManager {
     * @param type tethering type from ConnectivityManager.TETHERING_{@code *}
     */
    protected void removeDownstreamMapping(int type) {
        if (DBG) Log.d(TAG, "removeDownstreamMapping: " + type);
        mLog.i("removeDownstreamMapping: " + type);
        mCellularPermitted.delete(type);
        evaluateCellularPermission();
    }
@@ -617,7 +614,7 @@ public class EntitlementManager {
     */
    private int updateEntitlementCacheValue(int type, int resultCode) {
        if (DBG) {
            Log.d(TAG, "updateEntitlementCacheValue: " + type + ", result: " + resultCode);
            mLog.i("updateEntitlementCacheValue: " + type + ", result: " + resultCode);
        }
        if (resultCode == TETHER_ERROR_NO_ERROR) {
            mEntitlementCacheValue.put(type, resultCode);
+12 −12
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ public class TetheringConfigurationTest {
        mMockContext = new MockContext(mContext);
    }

    private TetheringConfiguration getTetheringConfiguration(int[] legacyTetherUpstreamTypes) {
    private TetheringConfiguration getTetheringConfiguration(int... legacyTetherUpstreamTypes) {
        when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(
                legacyTetherUpstreamTypes);
        return new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
@@ -143,13 +143,13 @@ public class TetheringConfigurationTest {
    public void testDunFromTelephonyManagerMeansDun() {
        when(mTelephonyManager.getTetherApnRequired()).thenReturn(true);

        final TetheringConfiguration cfgWifi = getTetheringConfiguration(new int[]{TYPE_WIFI});
        final TetheringConfiguration cfgWifi = getTetheringConfiguration(TYPE_WIFI);
        final TetheringConfiguration cfgMobileWifiHipri = getTetheringConfiguration(
                new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI});
                TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI);
        final TetheringConfiguration cfgWifiDun = getTetheringConfiguration(
                new int[]{TYPE_WIFI, TYPE_MOBILE_DUN});
                TYPE_WIFI, TYPE_MOBILE_DUN);
        final TetheringConfiguration cfgMobileWifiHipriDun = getTetheringConfiguration(
                new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN});
                TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN);

        for (TetheringConfiguration cfg : Arrays.asList(cfgWifi, cfgMobileWifiHipri,
                cfgWifiDun, cfgMobileWifiHipriDun)) {
@@ -167,20 +167,20 @@ public class TetheringConfigurationTest {
    public void testDunNotRequiredFromTelephonyManagerMeansNoDun() {
        when(mTelephonyManager.getTetherApnRequired()).thenReturn(false);

        final TetheringConfiguration cfgWifi = getTetheringConfiguration(new int[]{TYPE_WIFI});
        final TetheringConfiguration cfgWifi = getTetheringConfiguration(TYPE_WIFI);
        final TetheringConfiguration cfgMobileWifiHipri = getTetheringConfiguration(
                new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI});
                TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI);
        final TetheringConfiguration cfgWifiDun = getTetheringConfiguration(
                new int[]{TYPE_WIFI, TYPE_MOBILE_DUN});
                TYPE_WIFI, TYPE_MOBILE_DUN);
        final TetheringConfiguration cfgWifiMobile = getTetheringConfiguration(
                new int[]{TYPE_WIFI, TYPE_MOBILE});
                TYPE_WIFI, TYPE_MOBILE);
        final TetheringConfiguration cfgWifiHipri = getTetheringConfiguration(
                new int[]{TYPE_WIFI, TYPE_MOBILE_HIPRI});
                TYPE_WIFI, TYPE_MOBILE_HIPRI);
        final TetheringConfiguration cfgMobileWifiHipriDun = getTetheringConfiguration(
                new int[]{TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN});
                TYPE_MOBILE, TYPE_WIFI, TYPE_MOBILE_HIPRI, TYPE_MOBILE_DUN);

        String msg;
        // TYPE_MOBILE_DUN should not be present in all of the combinations.
        // TYPE_MOBILE_DUN should be present in none of the combinations.
        // TYPE_WIFI should not be affected.
        for (TetheringConfiguration cfg : Arrays.asList(cfgWifi, cfgMobileWifiHipri, cfgWifiDun,
                cfgWifiMobile, cfgWifiHipri, cfgMobileWifiHipriDun)) {