Skip to content

Commit 3b16c9a

Browse files
John WangAndroid Git Automerger
authored andcommitted
am f838b7c: Merge "Support selectNetworkManually in LTEPhone." into ics-mr0
* commit 'f838b7c2b8c4f0f1c48f315f49fea340b2b10d83': Support selectNetworkManually in LTEPhone.
2 parents 9842daa + f838b7c commit 3b16c9a

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

telephony/java/com/android/internal/telephony/cdma/CDMALTEPhone.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818

1919
import android.content.ContentValues;
2020
import android.content.Context;
21+
import android.content.SharedPreferences;
2122
import android.database.SQLException;
2223
import android.net.Uri;
24+
import android.os.AsyncResult;
2325
import android.os.Message;
26+
import android.preference.PreferenceManager;
2427
import android.provider.Telephony;
2528
import android.util.Log;
2629

2730
import com.android.internal.telephony.CommandsInterface;
31+
import com.android.internal.telephony.OperatorInfo;
2832
import com.android.internal.telephony.Phone;
2933
import com.android.internal.telephony.PhoneNotifier;
3034
import com.android.internal.telephony.PhoneProxy;
@@ -41,12 +45,38 @@ public class CDMALTEPhone extends CDMAPhone {
4145
/** Secondary SMSDispatcher for 3GPP format messages. */
4246
SMSDispatcher m3gppSMS;
4347

48+
/**
49+
* Small container class used to hold information relevant to
50+
* the carrier selection process. operatorNumeric can be ""
51+
* if we are looking for automatic selection. operatorAlphaLong is the
52+
* corresponding operator name.
53+
*/
54+
private static class NetworkSelectMessage {
55+
public Message message;
56+
public String operatorNumeric;
57+
public String operatorAlphaLong;
58+
}
59+
4460
// Constructors
4561
public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) {
4662
super(context, ci, notifier, false);
4763
m3gppSMS = new GsmSMSDispatcher(this, mSmsStorageMonitor, mSmsUsageMonitor);
4864
}
4965

66+
@Override
67+
public void handleMessage (Message msg) {
68+
AsyncResult ar;
69+
Message onComplete;
70+
switch (msg.what) {
71+
// handle the select network completion callbacks.
72+
case EVENT_SET_NETWORK_MANUAL_COMPLETE:
73+
handleSetSelectNetwork((AsyncResult) msg.obj);
74+
break;
75+
default:
76+
super.handleMessage(msg);
77+
}
78+
}
79+
5080
@Override
5181
protected void initSstIcc() {
5282
mSST = new CdmaLteServiceStateTracker(this);
@@ -108,6 +138,58 @@ public DataState getDataConnectionState(String apnType) {
108138
return ret;
109139
}
110140

141+
@Override
142+
public void
143+
selectNetworkManually(OperatorInfo network,
144+
Message response) {
145+
// wrap the response message in our own message along with
146+
// the operator's id.
147+
NetworkSelectMessage nsm = new NetworkSelectMessage();
148+
nsm.message = response;
149+
nsm.operatorNumeric = network.getOperatorNumeric();
150+
nsm.operatorAlphaLong = network.getOperatorAlphaLong();
151+
152+
// get the message
153+
Message msg = obtainMessage(EVENT_SET_NETWORK_MANUAL_COMPLETE, nsm);
154+
155+
mCM.setNetworkSelectionModeManual(network.getOperatorNumeric(), msg);
156+
}
157+
158+
/**
159+
* Used to track the settings upon completion of the network change.
160+
*/
161+
private void handleSetSelectNetwork(AsyncResult ar) {
162+
// look for our wrapper within the asyncresult, skip the rest if it
163+
// is null.
164+
if (!(ar.userObj instanceof NetworkSelectMessage)) {
165+
if (DBG) Log.d(LOG_TAG, "unexpected result from user object.");
166+
return;
167+
}
168+
169+
NetworkSelectMessage nsm = (NetworkSelectMessage) ar.userObj;
170+
171+
// found the object, now we send off the message we had originally
172+
// attached to the request.
173+
if (nsm.message != null) {
174+
if (DBG) Log.d(LOG_TAG, "sending original message to recipient");
175+
AsyncResult.forMessage(nsm.message, ar.result, ar.exception);
176+
nsm.message.sendToTarget();
177+
}
178+
179+
// open the shared preferences editor, and write the value.
180+
// nsm.operatorNumeric is "" if we're in automatic.selection.
181+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
182+
SharedPreferences.Editor editor = sp.edit();
183+
editor.putString(NETWORK_SELECTION_KEY, nsm.operatorNumeric);
184+
editor.putString(NETWORK_SELECTION_NAME_KEY, nsm.operatorAlphaLong);
185+
186+
// commit and log the result.
187+
if (! editor.commit()) {
188+
Log.e(LOG_TAG, "failed to commit network selection preference");
189+
}
190+
191+
}
192+
111193
@Override
112194
public boolean updateCurrentCarrierInProvider() {
113195
if (mIccRecords != null) {

0 commit comments

Comments
 (0)