summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Rambo Wang <rambowang@google.com> 2020-03-11 20:00:24 -0700
committer Rambo Wang <rambowang@google.com> 2020-03-13 18:55:03 +0000
commitccc118ec9b2d121d3f96b5c1247227ae9c7d5a8b (patch)
treea615ed26cf1476e0af7c52f2f7c52e803619c151
parent6945c01f1ab27f820ca822fc8cc53e09d6ab344b (diff)
CellularDataService: mCallbackMap is not thread safe
The HashMap object mCallbackMap in CellularDataService is a shared resource between DataService's handler thread and CellularDataService's handler thread. The update operations (put and remove) has synchronization issue. This CL fixes the issue by letting CellularDataService shares the looper/handler thread of DataService (but keeping its own handler). And thus all the operations of mCallbackMap are handled serializally in DataService's handler thread. One alternative solution is to move all operations of the mCallbackMap into CellularDataService's handler thread to make it thread-safe. But it's difficult for close() method which need to clear mCallbackMap and shutdown the handler thread. The other alternative solution is to replace HashMap with ConcurrentHashMap for mCallbackMap. This do make mCallbackMap thread-safe but do not change the fact that it is still a shared resource between two threads. Bug: 151103522 Test: atest FrameworksTelephonyTests Merged-In: I7f5a507c2a79c7c77c5c2d7d3be147af80dc9f69 Change-Id: I7f5a507c2a79c7c77c5c2d7d3be147af80dc9f69 (cherry picked from commit ccf29801e2cbd48842ea91194453e50ae14125a3)
-rw-r--r--telephony/java/android/telephony/NetworkService.java3
-rw-r--r--telephony/java/android/telephony/data/DataService.java3
2 files changed, 6 insertions, 0 deletions
diff --git a/telephony/java/android/telephony/NetworkService.java b/telephony/java/android/telephony/NetworkService.java
index 87d94bfda662..c75de42707a6 100644
--- a/telephony/java/android/telephony/NetworkService.java
+++ b/telephony/java/android/telephony/NetworkService.java
@@ -234,6 +234,9 @@ public abstract class NetworkService extends Service {
* this method to facilitate the creation of {@link NetworkServiceProvider} instances. The system
* will call this method after binding the network service for each active SIM slot id.
*
+ * This methead is guaranteed to be invoked in {@link NetworkService}'s internal handler thread
+ * whose looper can be retrieved with {@link Looper.myLooper()} when override this method.
+ *
* @param slotIndex SIM slot id the network service associated with.
* @return Network service object. Null if failed to create the provider (e.g. invalid slot
* index)
diff --git a/telephony/java/android/telephony/data/DataService.java b/telephony/java/android/telephony/data/DataService.java
index 6c4e7ce51ebf..f56bbe13051c 100644
--- a/telephony/java/android/telephony/data/DataService.java
+++ b/telephony/java/android/telephony/data/DataService.java
@@ -458,6 +458,9 @@ public abstract class DataService extends Service {
* this method to facilitate the creation of {@link DataServiceProvider} instances. The system
* will call this method after binding the data service for each active SIM slot id.
*
+ * This methead is guaranteed to be invoked in {@link DataService}'s internal handler thread
+ * whose looper can be retrieved with {@link Looper.myLooper()} when override this method.
+ *
* @param slotIndex SIM slot id the data service associated with.
* @return Data service object. Null if failed to create the provider (e.g. invalid slot index)
*/