diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2011-03-15 12:05:37 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-03-15 12:05:37 -0700 |
commit | b8c5fe004dce258eeca5fbba1925b9b1f513d650 (patch) | |
tree | 072f272d690f23b1ecad0613c6b38f90f43bdc04 /telephony | |
parent | 36ca1d3a693f0a416e758bb52801a3381a34a605 (diff) | |
parent | a74887e87c720fd100f10b2e69a027c493036e20 (diff) | |
download | frameworks_base-b8c5fe004dce258eeca5fbba1925b9b1f513d650.zip frameworks_base-b8c5fe004dce258eeca5fbba1925b9b1f513d650.tar.gz frameworks_base-b8c5fe004dce258eeca5fbba1925b9b1f513d650.tar.bz2 |
am a74887e8: am 56c4c442: Merge "Lazy initialization must be synchronized to avoid parallel instances cretation."
* commit 'a74887e87c720fd100f10b2e69a027c493036e20':
Lazy initialization must be synchronized to avoid parallel instances cretation.
Diffstat (limited to 'telephony')
-rw-r--r-- | telephony/java/com/android/internal/telephony/cat/CatService.java | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/telephony/java/com/android/internal/telephony/cat/CatService.java b/telephony/java/com/android/internal/telephony/cat/CatService.java index 1e23e34..36059ad 100644 --- a/telephony/java/com/android/internal/telephony/cat/CatService.java +++ b/telephony/java/com/android/internal/telephony/cat/CatService.java @@ -118,6 +118,8 @@ public class CatService extends Handler implements AppInterface { private static IccRecords mIccRecords; // Service members. + // Protects singleton instance lazy initialization. + private static final Object sInstanceLock = new Object(); private static CatService sInstance; private CommandsInterface mCmdIf; private Context mContext; @@ -515,26 +517,28 @@ public class CatService extends Handler implements AppInterface { */ public static CatService getInstance(CommandsInterface ci, IccRecords ir, Context context, IccFileHandler fh, IccCard ic) { - if (sInstance == null) { - if (ci == null || ir == null || context == null || fh == null - || ic == null) { - return null; + synchronized (sInstanceLock) { + if (sInstance == null) { + if (ci == null || ir == null || context == null || fh == null + || ic == null) { + return null; + } + HandlerThread thread = new HandlerThread("Cat Telephony service"); + thread.start(); + sInstance = new CatService(ci, ir, context, fh, ic); + CatLog.d(sInstance, "NEW sInstance"); + } else if ((ir != null) && (mIccRecords != ir)) { + CatLog.d(sInstance, "Reinitialize the Service with SIMRecords"); + mIccRecords = ir; + + // re-Register for SIM ready event. + mIccRecords.registerForRecordsLoaded(sInstance, MSG_ID_ICC_RECORDS_LOADED, null); + CatLog.d(sInstance, "sr changed reinitialize and return current sInstance"); + } else { + CatLog.d(sInstance, "Return current sInstance"); } - HandlerThread thread = new HandlerThread("Cat Telephony service"); - thread.start(); - sInstance = new CatService(ci, ir, context, fh, ic); - CatLog.d(sInstance, "NEW sInstance"); - } else if ((ir != null) && (mIccRecords != ir)) { - CatLog.d(sInstance, "Reinitialize the Service with SIMRecords"); - mIccRecords = ir; - - // re-Register for SIM ready event. - mIccRecords.registerForRecordsLoaded(sInstance, MSG_ID_ICC_RECORDS_LOADED, null); - CatLog.d(sInstance, "sr changed reinitialize and return current sInstance"); - } else { - CatLog.d(sInstance, "Return current sInstance"); + return sInstance; } - return sInstance; } /** |