Fix a Sms7BitEncodingTranslator threading issue, since translate() method can easily race when called by multiple threads.
Bug: 160733170 Test: Sanity; Telephony unit tests; hard to reproduce Change-Id: If8347a27a79351e84060c9a35e1cc9efd468f7a0
This commit is contained in:
@@ -65,13 +65,7 @@ public class Sms7BitEncodingTranslator {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!mIs7BitTranslationTableLoaded) {
|
||||
mTranslationTableCommon = new SparseIntArray();
|
||||
mTranslationTableGSM = new SparseIntArray();
|
||||
mTranslationTableCDMA = new SparseIntArray();
|
||||
load7BitTranslationTableFromXml();
|
||||
mIs7BitTranslationTableLoaded = true;
|
||||
}
|
||||
ensure7BitTranslationTableLoaded();
|
||||
|
||||
if ((mTranslationTableCommon != null && mTranslationTableCommon.size() > 0) ||
|
||||
(mTranslationTableGSM != null && mTranslationTableGSM.size() > 0) ||
|
||||
@@ -115,6 +109,8 @@ public class Sms7BitEncodingTranslator {
|
||||
*/
|
||||
int translation = -1;
|
||||
|
||||
ensure7BitTranslationTableLoaded();
|
||||
|
||||
if (mTranslationTableCommon != null) {
|
||||
translation = mTranslationTableCommon.get(c, -1);
|
||||
}
|
||||
@@ -155,6 +151,18 @@ public class Sms7BitEncodingTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensure7BitTranslationTableLoaded() {
|
||||
synchronized (Sms7BitEncodingTranslator.class) {
|
||||
if (!mIs7BitTranslationTableLoaded) {
|
||||
mTranslationTableCommon = new SparseIntArray();
|
||||
mTranslationTableGSM = new SparseIntArray();
|
||||
mTranslationTableCDMA = new SparseIntArray();
|
||||
load7BitTranslationTableFromXml();
|
||||
mIs7BitTranslationTableLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the whole translation table file from the framework resource
|
||||
* encoded in XML.
|
||||
|
||||
Reference in New Issue
Block a user