From c3f935b630910cb90e96da1484f02ef49f9e1013 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 6 Feb 2020 17:53:36 +0800 Subject: Include channel operation in synchronized area When application try to stress OMAPI by continuously open/close channels with multi-thread, there is possibility channel management is incorrect and result to no response. Bug: 148892905 Test: OMAPI works normal after multi-thread stress tests Change-Id: I530015ff20ed143a129024d6385fae9392a00a99 --- src/com/android/se/Terminal.java | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/com/android/se/Terminal.java b/src/com/android/se/Terminal.java index d21c323..521d696 100644 --- a/src/com/android/se/Terminal.java +++ b/src/com/android/se/Terminal.java @@ -247,22 +247,22 @@ public class Terminal { if (channel == null) { return; } - if (mIsConnected) { - try { - byte status = mSEHal.closeChannel((byte) channel.getChannelNumber()); - /* For Basic Channels, errors are expected. - * Underlying implementations use this call as an indication when there - * aren't any users actively using the channel, and the chip can go - * into low power state. - */ - if (!channel.isBasicChannel() && status != SecureElementStatus.SUCCESS) { - Log.e(mTag, "Error closing channel " + channel.getChannelNumber()); + synchronized (mLock) { + if (mIsConnected) { + try { + byte status = mSEHal.closeChannel((byte) channel.getChannelNumber()); + /* For Basic Channels, errors are expected. + * Underlying implementations use this call as an indication when there + * aren't any users actively using the channel, and the chip can go + * into low power state. + */ + if (!channel.isBasicChannel() && status != SecureElementStatus.SUCCESS) { + Log.e(mTag, "Error closing channel " + channel.getChannelNumber()); + } + } catch (RemoteException e) { + Log.e(mTag, "Exception in closeChannel() " + e); } - } catch (RemoteException e) { - Log.e(mTag, "Exception in closeChannel() " + e); } - } - synchronized (mLock) { mChannels.remove(channel.getChannelNumber(), channel); if (mChannels.get(channel.getChannelNumber()) != null) { Log.e(mTag, "Removing channel failed"); -- cgit v1.2.3