summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Deva <ganesh.deva_1@nxp.com>2020-07-22 19:31:06 +0530
committernxf24591 <nanjesh.s_1@nxp.com>2020-09-08 17:44:08 +0530
commitbacbd07ba01ccf1e4d88345b274fabc71fdc2c00 (patch)
tree2cd683ede914c9caf2525808b977642309db2a33
parent6a55c23b8d4c3cf0a0115e8824f868e7f1d30e8e (diff)
Strengthen the robustness of concurrent operations
1. Ensure the concurrent access to mChannels in Terminal.java is protected by the same lock instance 2. Move the remove operation of mSessions into synchronized block in method of Terminal.removeSession 3. Add synchronous block protection to mChannels.add operation in SecureElementService.java
-rwxr-xr-xsrc/com/android/se/SecureElementService.java8
-rwxr-xr-xsrc/com/android/se/Terminal.java15
2 files changed, 15 insertions, 8 deletions
diff --git a/src/com/android/se/SecureElementService.java b/src/com/android/se/SecureElementService.java
index e9a7b39..7f544e3 100755
--- a/src/com/android/se/SecureElementService.java
+++ b/src/com/android/se/SecureElementService.java
@@ -369,7 +369,9 @@ public final class SecureElementService extends Service {
Log.i(mTag, "Open basic channel success. Channel: "
+ channel.getChannelNumber());
- mChannels.add(channel);
+ synchronized (mLock) {
+ mChannels.add(channel);
+ }
return channel.new SecureElementChannel();
}
@@ -409,7 +411,9 @@ public final class SecureElementService extends Service {
Log.i(mTag, "openLogicalChannel() Success. Channel: "
+ channel.getChannelNumber());
- mChannels.add(channel);
+ synchronized (mLock) {
+ mChannels.add(channel);
+ }
return channel.new SecureElementChannel();
}
}
diff --git a/src/com/android/se/Terminal.java b/src/com/android/se/Terminal.java
index a6a074b..2153dac 100755
--- a/src/com/android/se/Terminal.java
+++ b/src/com/android/se/Terminal.java
@@ -386,11 +386,13 @@ public class Terminal {
/**
* Cleans up all the channels in use.
*/
- public synchronized void closeChannels() {
- Collection<Channel> col = mChannels.values();
- Channel[] channelList = col.toArray(new Channel[col.size()]);
- for (Channel channel : channelList) {
- channel.close();
+ public void closeChannels() {
+ synchronized (mLock) {
+ Collection<Channel> col = mChannels.values();
+ Channel[] channelList = col.toArray(new Channel[col.size()]);
+ for (Channel channel : channelList) {
+ channel.close();
+ }
}
}
@@ -1031,8 +1033,9 @@ public class Terminal {
}
}
}
- mSessions.remove(session);
+
synchronized (mLock) {
+ mSessions.remove(session);
if (mSessions.size() == 0) {
mDefaultApplicationSelectedOnBasicChannel = true;
}