Skip to content

Commit a436860

Browse files
Wink SavilleAndroid (Google) Code Review
authored andcommitted
Merge "Telephony: Remove coupling between phone and IccRecords"
2 parents 4de35e1 + 80198f2 commit a436860

15 files changed

+368
-252
lines changed

telephony/java/com/android/internal/telephony/AdnRecordCache.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public final class AdnRecordCache extends Handler implements IccConstants {
3434
//***** Instance Variables
3535

36-
PhoneBase phone;
36+
private IccFileHandler mFh;
3737
private UsimPhoneBookManager mUsimPhoneBookManager;
3838

3939
// Indexed by EF ID
@@ -56,9 +56,9 @@ public final class AdnRecordCache extends Handler implements IccConstants {
5656

5757

5858

59-
public AdnRecordCache(PhoneBase phone) {
60-
this.phone = phone;
61-
mUsimPhoneBookManager = new UsimPhoneBookManager(phone, this);
59+
public AdnRecordCache(IccFileHandler fh) {
60+
mFh = fh;
61+
mUsimPhoneBookManager = new UsimPhoneBookManager(mFh, this);
6262
}
6363

6464
//***** Called from SIMRecords
@@ -155,7 +155,7 @@ public void updateAdnByIndex(int efid, AdnRecord adn, int recordIndex, String pi
155155

156156
userWriteResponse.put(efid, response);
157157

158-
new AdnRecordLoader(phone).updateEF(adn, efid, extensionEF,
158+
new AdnRecordLoader(mFh).updateEF(adn, efid, extensionEF,
159159
recordIndex, pin2,
160160
obtainMessage(EVENT_UPDATE_ADN_DONE, efid, recordIndex, adn));
161161
}
@@ -233,7 +233,7 @@ public void updateAdnBySearch(int efid, AdnRecord oldAdn, AdnRecord newAdn,
233233

234234
userWriteResponse.put(efid, response);
235235

236-
new AdnRecordLoader(phone).updateEF(newAdn, efid, extensionEF,
236+
new AdnRecordLoader(mFh).updateEF(newAdn, efid, extensionEF,
237237
index, pin2,
238238
obtainMessage(EVENT_UPDATE_ADN_DONE, efid, index, newAdn));
239239
}
@@ -296,7 +296,7 @@ public void updateAdnBySearch(int efid, AdnRecord oldAdn, AdnRecord newAdn,
296296
return;
297297
}
298298

299-
new AdnRecordLoader(phone).loadAllFromEF(efid, extensionEf,
299+
new AdnRecordLoader(mFh).loadAllFromEF(efid, extensionEf,
300300
obtainMessage(EVENT_LOAD_ALL_ADN_LIKE_DONE, efid, 0));
301301
}
302302

telephony/java/com/android/internal/telephony/AdnRecordLoader.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020

2121
import android.os.AsyncResult;
2222
import android.os.Handler;
23+
import android.os.Looper;
2324
import android.os.Message;
2425
import android.util.Log;
2526

2627

2728
public class AdnRecordLoader extends Handler {
28-
static String LOG_TAG;
29+
final static String LOG_TAG = "RIL_AdnRecordLoader";
2930

3031
//***** Instance Variables
3132

32-
PhoneBase phone;
33+
private IccFileHandler mFh;
3334
int ef;
3435
int extensionEF;
3536
int pendingExtLoads;
@@ -56,13 +57,11 @@ public class AdnRecordLoader extends Handler {
5657

5758
//***** Constructor
5859

59-
public AdnRecordLoader(PhoneBase phone) {
60+
public AdnRecordLoader(IccFileHandler fh) {
6061
// The telephony unit-test cases may create AdnRecords
6162
// in secondary threads
62-
super(phone.getHandler().getLooper());
63-
64-
this.phone = phone;
65-
LOG_TAG = phone.getPhoneName();
63+
super(Looper.getMainLooper());
64+
mFh = fh;
6665
}
6766

6867
/**
@@ -77,7 +76,7 @@ public AdnRecordLoader(PhoneBase phone) {
7776
this.recordNumber = recordNumber;
7877
this.userResponse = response;
7978

80-
phone.mIccFileHandler.loadEFLinearFixed(
79+
mFh.loadEFLinearFixed(
8180
ef, recordNumber,
8281
obtainMessage(EVENT_ADN_LOAD_DONE));
8382

@@ -95,7 +94,7 @@ public AdnRecordLoader(PhoneBase phone) {
9594
this.extensionEF = extensionEF;
9695
this.userResponse = response;
9796

98-
phone.mIccFileHandler.loadEFLinearFixedAll(
97+
mFh.loadEFLinearFixedAll(
9998
ef,
10099
obtainMessage(EVENT_ADN_LOAD_ALL_DONE));
101100

@@ -122,7 +121,7 @@ public AdnRecordLoader(PhoneBase phone) {
122121
this.userResponse = response;
123122
this.pin2 = pin2;
124123

125-
phone.mIccFileHandler.getEFLinearRecordSize( ef,
124+
mFh.getEFLinearRecordSize( ef,
126125
obtainMessage(EVENT_EF_LINEAR_RECORD_SIZE_DONE, adn));
127126
}
128127

@@ -163,7 +162,7 @@ public AdnRecordLoader(PhoneBase phone) {
163162
ar.exception);
164163
}
165164

166-
phone.mIccFileHandler.updateEFLinearFixed(ef, recordNumber,
165+
mFh.updateEFLinearFixed(ef, recordNumber,
167166
data, pin2, obtainMessage(EVENT_UPDATE_RECORD_DONE));
168167

169168
pendingExtLoads = 1;
@@ -203,7 +202,7 @@ public AdnRecordLoader(PhoneBase phone) {
203202

204203
pendingExtLoads = 1;
205204

206-
phone.mIccFileHandler.loadEFLinearFixed(
205+
mFh.loadEFLinearFixed(
207206
extensionEF, adn.extRecord,
208207
obtainMessage(EVENT_EXT_RECORD_LOAD_DONE, adn));
209208
}
@@ -253,7 +252,7 @@ public AdnRecordLoader(PhoneBase phone) {
253252

254253
pendingExtLoads++;
255254

256-
phone.mIccFileHandler.loadEFLinearFixed(
255+
mFh.loadEFLinearFixed(
257256
extensionEF, adn.extRecord,
258257
obtainMessage(EVENT_EXT_RECORD_LOAD_DONE, adn));
259258
}

telephony/java/com/android/internal/telephony/IccCard.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,14 @@ public IccCard(PhoneBase phone, String logTag, Boolean is3gpp, Boolean dbg) {
185185
mPhone.mCM, mHandler, EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED, null);
186186
if (phone.mCM.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE
187187
&& phone instanceof CDMALTEPhone) {
188-
mIccRecords = new CdmaLteUiccRecords(phone);
189188
mIccFileHandler = new CdmaLteUiccFileHandler(this, "", mPhone.mCM);
189+
mIccRecords = new CdmaLteUiccRecords(this, mPhone.mContext, mPhone.mCM);
190190
} else {
191-
mIccRecords = is3gpp ? new SIMRecords(phone) : new RuimRecords(phone);
192191
// Correct aid will be set later (when GET_SIM_STATUS returns)
193192
mIccFileHandler = is3gpp ? new SIMFileHandler(this, "", mPhone.mCM) :
194193
new RuimFileHandler(this, "", mPhone.mCM);
194+
mIccRecords = is3gpp ? new SIMRecords(this, mPhone.mContext, mPhone.mCM) :
195+
new RuimRecords(this, mPhone.mContext, mPhone.mCM);
195196
}
196197
mPhone.mCM.registerForOffOrNotAvailable(mHandler, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
197198
mPhone.mCM.registerForOn(mHandler, EVENT_RADIO_ON, null);

telephony/java/com/android/internal/telephony/IccRecords.java

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.android.internal.telephony;
1818

19+
import android.content.Context;
1920
import android.os.AsyncResult;
2021
import android.os.Handler;
2122
import android.os.Message;
@@ -32,9 +33,16 @@ public abstract class IccRecords extends Handler implements IccConstants {
3233

3334
protected static final boolean DBG = true;
3435
// ***** Instance Variables
36+
protected boolean mDestroyed = false; // set to true once this object needs to be disposed of
37+
protected Context mContext;
38+
protected CommandsInterface mCi;
39+
protected IccFileHandler mFh;
40+
protected IccCard mParentCard;
3541

36-
protected PhoneBase phone;
3742
protected RegistrantList recordsLoadedRegistrants = new RegistrantList();
43+
protected RegistrantList mRecordsEventsRegistrants = new RegistrantList();
44+
protected RegistrantList mNewSmsRegistrants = new RegistrantList();
45+
protected RegistrantList mNetworkSelectionModeAutomaticRegistrants = new RegistrantList();
3846

3947
protected int recordsToLoad; // number of pending load requests
4048

@@ -71,6 +79,9 @@ public abstract class IccRecords extends Handler implements IccConstants {
7179

7280
// ***** Event Constants
7381
protected static final int EVENT_SET_MSISDN_DONE = 30;
82+
public static final int EVENT_MWI = 0;
83+
public static final int EVENT_CFI = 1;
84+
public static final int EVENT_SPN = 2;
7485

7586
public static final int EVENT_GET_ICC_RECORD_DONE = 100;
7687

@@ -91,15 +102,23 @@ public interface IccRecordLoaded {
91102
}
92103

93104
// ***** Constructor
94-
95-
public IccRecords(PhoneBase p) {
96-
this.phone = p;
105+
public IccRecords(IccCard card, Context c, CommandsInterface ci) {
106+
mContext = c;
107+
mCi = ci;
108+
mFh = card.getIccFileHandler();
109+
mParentCard = card;
97110
}
98111

99112
/**
100113
* Call when the IccRecords object is no longer going to be used.
101114
*/
102-
public abstract void dispose();
115+
public void dispose() {
116+
mDestroyed = true;
117+
mParentCard = null;
118+
mFh = null;
119+
mCi = null;
120+
mContext = null;
121+
}
103122

104123
protected abstract void onRadioOffOrNotAvailable();
105124
public abstract void onReady();
@@ -109,19 +128,51 @@ public AdnRecordCache getAdnCache() {
109128
return adnCache;
110129
}
111130

131+
public IccCard getIccCard() {
132+
return mParentCard;
133+
}
134+
112135
public void registerForRecordsLoaded(Handler h, int what, Object obj) {
136+
if (mDestroyed) {
137+
return;
138+
}
139+
113140
Registrant r = new Registrant(h, what, obj);
114141
recordsLoadedRegistrants.add(r);
115142

116143
if (recordsToLoad == 0 && recordsRequested == true) {
117144
r.notifyRegistrant(new AsyncResult(null, null, null));
118145
}
119146
}
120-
121147
public void unregisterForRecordsLoaded(Handler h) {
122148
recordsLoadedRegistrants.remove(h);
123149
}
124150

151+
public void registerForRecordsEvents(Handler h, int what, Object obj) {
152+
Registrant r = new Registrant (h, what, obj);
153+
mRecordsEventsRegistrants.add(r);
154+
}
155+
public void unregisterForRecordsEvents(Handler h) {
156+
mRecordsEventsRegistrants.remove(h);
157+
}
158+
159+
public void registerForNewSms(Handler h, int what, Object obj) {
160+
Registrant r = new Registrant (h, what, obj);
161+
mNewSmsRegistrants.add(r);
162+
}
163+
public void unregisterForNewSms(Handler h) {
164+
mNewSmsRegistrants.remove(h);
165+
}
166+
167+
public void registerForNetworkSelectionModeAutomatic(
168+
Handler h, int what, Object obj) {
169+
Registrant r = new Registrant (h, what, obj);
170+
mNetworkSelectionModeAutomaticRegistrants.add(r);
171+
}
172+
public void unregisterForNetworkSelectionModeAutomatic(Handler h) {
173+
mNetworkSelectionModeAutomaticRegistrants.remove(h);
174+
}
175+
125176
/**
126177
* Get the International Mobile Subscriber ID (IMSI) on a SIM
127178
* for GSM, UMTS and like networks. Default is null if IMSI is
@@ -163,7 +214,7 @@ public void setMsisdnNumber(String alphaTag, String number,
163214

164215
AdnRecord adn = new AdnRecord(msisdnTag, msisdn);
165216

166-
new AdnRecordLoader(phone).updateEF(adn, EF_MSISDN, EF_EXT1, 1, null,
217+
new AdnRecordLoader(mFh).updateEF(adn, EF_MSISDN, EF_EXT1, 1, null,
167218
obtainMessage(EVENT_SET_MSISDN_DONE, onComplete));
168219
}
169220

0 commit comments

Comments
 (0)