Merge "Fix a Sms7BitEncodingTranslator threading issue, since translate() method can easily race when called by multiple threads." am: 02b664649a am: 1609733fae
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1360883 Change-Id: Ia8d0608b3ef8291030a8131b732dee2eff2c8745
This commit is contained in:
@@ -65,13 +65,7 @@ public class Sms7BitEncodingTranslator {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mIs7BitTranslationTableLoaded) {
|
ensure7BitTranslationTableLoaded();
|
||||||
mTranslationTableCommon = new SparseIntArray();
|
|
||||||
mTranslationTableGSM = new SparseIntArray();
|
|
||||||
mTranslationTableCDMA = new SparseIntArray();
|
|
||||||
load7BitTranslationTableFromXml();
|
|
||||||
mIs7BitTranslationTableLoaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((mTranslationTableCommon != null && mTranslationTableCommon.size() > 0) ||
|
if ((mTranslationTableCommon != null && mTranslationTableCommon.size() > 0) ||
|
||||||
(mTranslationTableGSM != null && mTranslationTableGSM.size() > 0) ||
|
(mTranslationTableGSM != null && mTranslationTableGSM.size() > 0) ||
|
||||||
@@ -115,6 +109,8 @@ public class Sms7BitEncodingTranslator {
|
|||||||
*/
|
*/
|
||||||
int translation = -1;
|
int translation = -1;
|
||||||
|
|
||||||
|
ensure7BitTranslationTableLoaded();
|
||||||
|
|
||||||
if (mTranslationTableCommon != null) {
|
if (mTranslationTableCommon != null) {
|
||||||
translation = mTranslationTableCommon.get(c, -1);
|
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
|
* Load the whole translation table file from the framework resource
|
||||||
* encoded in XML.
|
* encoded in XML.
|
||||||
|
|||||||
Reference in New Issue
Block a user