diff options
| author | 2018-07-16 19:54:26 +0800 | |
|---|---|---|
| committer | 2018-07-16 19:54:26 +0800 | |
| commit | 1d64e03f916817c5fc89f214db1ffeec526ec611 (patch) | |
| tree | 0b47ec64a9a011700f7d9716fb9a192cd89490b4 | |
| parent | 3c1604da8b04d9e43554dada977bbca54bbea313 (diff) | |
Remove SimChangeListener from Tethering
SimChangeListener is obsolete. It is replace by
ACTION_CARRIER_CONFIG_CHANGED.
Test: as follows
    - built, flashed, booted
    - runtest frameworks-net passes (with --no-hidden-api-checks)
    - tethering/hotspot on/off
Bug: 111490073
Change-Id: I82644ea136f43869a953a1f7b72dc489fe90f380
3 files changed, 0 insertions, 224 deletions
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 0230f75b8a91..d05311630ffb 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -115,7 +115,6 @@ import com.android.server.LocalServices;  import com.android.server.connectivity.tethering.IControlsTethering;  import com.android.server.connectivity.tethering.IPv6TetheringCoordinator;  import com.android.server.connectivity.tethering.OffloadController; -import com.android.server.connectivity.tethering.SimChangeListener;  import com.android.server.connectivity.tethering.TetherInterfaceStateMachine;  import com.android.server.connectivity.tethering.TetheringConfiguration;  import com.android.server.connectivity.tethering.TetheringDependencies; @@ -201,8 +200,6 @@ public class Tethering extends BaseNetworkObserver {      // into a single coherent structure.      private final HashSet<TetherInterfaceStateMachine> mForwardedDownstreams;      private final VersionedBroadcastListener mCarrierConfigChange; -    // TODO: Delete SimChangeListener; it's obsolete. -    private final SimChangeListener mSimChange;      private final TetheringDependencies mDeps;      private volatile TetheringConfiguration mConfig; @@ -252,14 +249,6 @@ public class Tethering extends BaseNetworkObserver {                      updateConfiguration();                      reevaluateSimCardProvisioning();                  }); -        // TODO: Remove SimChangeListener altogether. For now, we retain it -        // for logging purposes in case we need to debug something that might -        // be related to changing signals from ACTION_SIM_STATE_CHANGED to -        // ACTION_CARRIER_CONFIG_CHANGED. -        mSimChange = new SimChangeListener( -                mContext, smHandler, () -> { -                    mLog.log("OBSERVED SIM card change"); -                });          mStateReceiver = new StateReceiver(); @@ -1529,7 +1518,6 @@ public class Tethering extends BaseNetworkObserver {                      return;                  } -                mSimChange.startListening();                  mUpstreamNetworkMonitor.start(mDeps.getDefaultNetworkRequest());                  // TODO: De-duplicate with updateUpstreamWanted() below. @@ -1545,7 +1533,6 @@ public class Tethering extends BaseNetworkObserver {              public void exit() {                  mOffload.stop();                  mUpstreamNetworkMonitor.stop(); -                mSimChange.stopListening();                  notifyDownstreamsOfNewUpstreamIface(null);                  handleNewUpstreamNetworkState(null);              } diff --git a/services/core/java/com/android/server/connectivity/tethering/SimChangeListener.java b/services/core/java/com/android/server/connectivity/tethering/SimChangeListener.java deleted file mode 100644 index 33c9355ae64b..000000000000 --- a/services/core/java/com/android/server/connectivity/tethering/SimChangeListener.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - *      http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.connectivity.tethering; - -import static com.android.internal.telephony.IccCardConstants.INTENT_VALUE_ICC_LOADED; -import static com.android.internal.telephony.IccCardConstants.INTENT_KEY_ICC_STATE; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.util.VersionedBroadcastListener; -import android.net.util.VersionedBroadcastListener.IntentCallback; -import android.os.Handler; -import android.util.Log; - -import com.android.internal.telephony.TelephonyIntents; - -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - - -/** - * A utility class that runs the provided callback on the provided handler when - * observing a new SIM card having been loaded. - * - * @hide - */ -public class SimChangeListener extends VersionedBroadcastListener { -    private static final String TAG = SimChangeListener.class.getSimpleName(); -    private static final boolean DBG = false; - -    public SimChangeListener(Context ctx, Handler handler, Runnable onSimCardLoadedCallback) { -        super(TAG, ctx, handler, makeIntentFilter(), makeCallback(onSimCardLoadedCallback)); -    } - -    private static IntentFilter makeIntentFilter() { -        final IntentFilter filter = new IntentFilter(); -        filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); -        return filter; -    } - -    private static Consumer<Intent> makeCallback(Runnable onSimCardLoadedCallback) { -        return new Consumer<Intent>() { -            private boolean mSimNotLoadedSeen = false; - -            @Override -            public void accept(Intent intent) { -                final String state = intent.getStringExtra(INTENT_KEY_ICC_STATE); -                Log.d(TAG, "got Sim changed to state " + state + ", mSimNotLoadedSeen=" + -                        mSimNotLoadedSeen); - -                if (!INTENT_VALUE_ICC_LOADED.equals(state)) { -                    mSimNotLoadedSeen = true; -                    return; -                } - -                if (mSimNotLoadedSeen) { -                    mSimNotLoadedSeen = false; -                    onSimCardLoadedCallback.run(); -                } -            } -        }; -    } -} diff --git a/tests/net/java/com/android/server/connectivity/tethering/SimChangeListenerTest.java b/tests/net/java/com/android/server/connectivity/tethering/SimChangeListenerTest.java deleted file mode 100644 index f58ea7e9375f..000000000000 --- a/tests/net/java/com/android/server/connectivity/tethering/SimChangeListenerTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - *      http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.connectivity.tethering; - -import static com.android.internal.telephony.IccCardConstants.INTENT_VALUE_ICC_ABSENT; -import static com.android.internal.telephony.IccCardConstants.INTENT_VALUE_ICC_LOADED; -import static com.android.internal.telephony.IccCardConstants.INTENT_KEY_ICC_STATE; -import static com.android.internal.telephony.TelephonyIntents.ACTION_SIM_STATE_CHANGED; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.reset; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Looper; -import android.os.UserHandle; - -import android.support.test.filters.SmallTest; -import android.support.test.runner.AndroidJUnit4; - -import com.android.internal.util.test.BroadcastInterceptingContext; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; - - -@RunWith(AndroidJUnit4.class) -@SmallTest -public class SimChangeListenerTest { -    @Mock private Context mContext; -    private BroadcastInterceptingContext mServiceContext; -    private Handler mHandler; -    private SimChangeListener mSCL; -    private int mCallbackCount; - -    private void doCallback() { mCallbackCount++; } - -    private class MockContext extends BroadcastInterceptingContext { -        MockContext(Context base) { -            super(base); -        } -    } - -    @BeforeClass -    public static void setUpBeforeClass() throws Exception { -        if (Looper.myLooper() == null) { -            Looper.prepare(); -        } -    } - -    @Before public void setUp() throws Exception { -        MockitoAnnotations.initMocks(this); -        reset(mContext); -        mServiceContext = new MockContext(mContext); -        mHandler = new Handler(Looper.myLooper()); -        mCallbackCount = 0; -        mSCL = new SimChangeListener(mServiceContext, mHandler, () -> doCallback()); -    } - -    @After public void tearDown() throws Exception { -        if (mSCL != null) { -            mSCL.stopListening(); -            mSCL = null; -        } -    } - -    private void sendSimStateChangeIntent(String state) { -        final Intent intent = new Intent(ACTION_SIM_STATE_CHANGED); -        intent.putExtra(INTENT_KEY_ICC_STATE, state); -        mServiceContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); -    } - -    @Test -    public void testNotSeenFollowedBySeenCallsCallback() { -        mSCL.startListening(); - -        sendSimStateChangeIntent(INTENT_VALUE_ICC_ABSENT); -        sendSimStateChangeIntent(INTENT_VALUE_ICC_LOADED); -        assertEquals(1, mCallbackCount); - -        sendSimStateChangeIntent(INTENT_VALUE_ICC_ABSENT); -        sendSimStateChangeIntent(INTENT_VALUE_ICC_LOADED); -        assertEquals(2, mCallbackCount); - -        mSCL.stopListening(); -    } - -    @Test -    public void testNotListeningDoesNotCallback() { -        sendSimStateChangeIntent(INTENT_VALUE_ICC_ABSENT); -        sendSimStateChangeIntent(INTENT_VALUE_ICC_LOADED); -        assertEquals(0, mCallbackCount); - -        sendSimStateChangeIntent(INTENT_VALUE_ICC_ABSENT); -        sendSimStateChangeIntent(INTENT_VALUE_ICC_LOADED); -        assertEquals(0, mCallbackCount); -    } - -    @Test -    public void testSeenOnlyDoesNotCallback() { -        mSCL.startListening(); - -        sendSimStateChangeIntent(INTENT_VALUE_ICC_LOADED); -        assertEquals(0, mCallbackCount); - -        sendSimStateChangeIntent(INTENT_VALUE_ICC_LOADED); -        assertEquals(0, mCallbackCount); - -        mSCL.stopListening(); -    } -}  |