Fix Keyboard.getKey as thread safe
This is a follow up of Id962e670. Change-Id: I9e8542bff9e8faf57f934051fe612463c99ad61f
This commit is contained in:
parent
e9a86e2cdb
commit
8f6c603b3b
1 changed files with 13 additions and 11 deletions
|
@ -185,19 +185,21 @@ public class Keyboard {
|
|||
if (code == CODE_UNSPECIFIED) {
|
||||
return null;
|
||||
}
|
||||
final int index = mKeyCache.indexOfKey(code);
|
||||
if (index >= 0) {
|
||||
return mKeyCache.valueAt(index);
|
||||
}
|
||||
|
||||
for (final Key key : mKeys) {
|
||||
if (key.mCode == code) {
|
||||
mKeyCache.put(code, key);
|
||||
return key;
|
||||
synchronized (mKeyCache) {
|
||||
final int index = mKeyCache.indexOfKey(code);
|
||||
if (index >= 0) {
|
||||
return mKeyCache.valueAt(index);
|
||||
}
|
||||
|
||||
for (final Key key : mKeys) {
|
||||
if (key.mCode == code) {
|
||||
mKeyCache.put(code, key);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
mKeyCache.put(code, null);
|
||||
return null;
|
||||
}
|
||||
mKeyCache.put(code, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasKey(Key aKey) {
|
||||
|
|
Loading…
Reference in a new issue