diff options
author | markchien <markchien@google.com> | 2019-09-30 14:40:57 +0800 |
---|---|---|
committer | Mark Chien <markchien@google.com> | 2019-11-30 10:03:08 +0000 |
commit | 0df2ebc43de508980c096346a7f70a0653779361 (patch) | |
tree | bc3ac3a9888ca89e010e0244836c105c7b0ffed0 /services/net/java | |
parent | d8676d99ff7bfb69c11d5db2abd206002ec54cee (diff) |
[Tether07] Migrate Tethering into module
Now tethering would be run in dedicated service.
TetheringManager is the interface used to communicate with
TetheringService. The new call flow would be: ConnectivityManager
-> ConnectivityService -> TetheringManager -> TetheringService.
Note: the return value of #tether(), #untether() and #setUsbTethering()
APIs would always be no error. Client can use #getLastTetherError()
or #getTetheredIfaces or listen tether state change to check
status of corresponding interface.
Bug: 136040414
Bug: 144742179
Test: -build, flash, boot
-atest TetheringTests
-atest FrameworksNetTests
Change-Id: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
Merged-In: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
Diffstat (limited to 'services/net/java')
-rw-r--r-- | services/net/java/android/net/util/VersionedBroadcastListener.java | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/services/net/java/android/net/util/VersionedBroadcastListener.java b/services/net/java/android/net/util/VersionedBroadcastListener.java deleted file mode 100644 index 107c40495f9e..000000000000 --- a/services/net/java/android/net/util/VersionedBroadcastListener.java +++ /dev/null @@ -1,109 +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 android.net.util; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Handler; -import android.util.Log; - -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - - -/** - * A utility class that runs the provided callback on the provided handler when - * intents matching the provided filter arrive. Intents received by a stale - * receiver are safely ignored. - * - * Calls to startListening() and stopListening() must happen on the same thread. - * - * @hide - */ -public class VersionedBroadcastListener { - private static final boolean DBG = false; - - public interface IntentCallback { - public void run(Intent intent); - } - - private final String mTag; - private final Context mContext; - private final Handler mHandler; - private final IntentFilter mFilter; - private final Consumer<Intent> mCallback; - private final AtomicInteger mGenerationNumber; - private BroadcastReceiver mReceiver; - - public VersionedBroadcastListener(String tag, Context ctx, Handler handler, - IntentFilter filter, Consumer<Intent> callback) { - mTag = tag; - mContext = ctx; - mHandler = handler; - mFilter = filter; - mCallback = callback; - mGenerationNumber = new AtomicInteger(0); - } - - public void startListening() { - if (DBG) Log.d(mTag, "startListening"); - if (mReceiver != null) return; - - mReceiver = new Receiver(mTag, mGenerationNumber, mCallback); - mContext.registerReceiver(mReceiver, mFilter, null, mHandler); - } - - public void stopListening() { - if (DBG) Log.d(mTag, "stopListening"); - if (mReceiver == null) return; - - mGenerationNumber.incrementAndGet(); - mContext.unregisterReceiver(mReceiver); - mReceiver = null; - } - - private static class Receiver extends BroadcastReceiver { - public final String tag; - public final AtomicInteger atomicGenerationNumber; - public final Consumer<Intent> callback; - // Used to verify this receiver is still current. - public final int generationNumber; - - public Receiver( - String tag, AtomicInteger atomicGenerationNumber, Consumer<Intent> callback) { - this.tag = tag; - this.atomicGenerationNumber = atomicGenerationNumber; - this.callback = callback; - generationNumber = atomicGenerationNumber.incrementAndGet(); - } - - @Override - public void onReceive(Context context, Intent intent) { - final int currentGenerationNumber = atomicGenerationNumber.get(); - - if (DBG) { - Log.d(tag, "receiver generationNumber=" + generationNumber + - ", current generationNumber=" + currentGenerationNumber); - } - if (generationNumber != currentGenerationNumber) return; - - callback.accept(intent); - } - } -} |