summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Chien <markchien@google.com>2018-07-17 05:49:09 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-07-17 05:49:09 +0000
commit6e35b2c596c20b724c36fed3dde6687d44635d35 (patch)
tree35603bba6237fce653f8e1e3249384309133c212
parent600aeb124ba9bdb5c16da802dd1c85a4265ed1d8 (diff)
parent1d64e03f916817c5fc89f214db1ffeec526ec611 (diff)
Merge "Remove SimChangeListener from Tethering"
-rw-r--r--services/core/java/com/android/server/connectivity/Tethering.java13
-rw-r--r--services/core/java/com/android/server/connectivity/tethering/SimChangeListener.java79
-rw-r--r--tests/net/java/com/android/server/connectivity/tethering/SimChangeListenerTest.java132
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();
- }
-}