SmsCirChannelpublic class SmsCirChannel extends CirChannel implements com.android.im.engine.SmsService.SmsSendFailureCallback, com.android.im.engine.SmsService.SmsListener
Fields Summary |
---|
private String | mAddr | private int | mPort | private com.android.im.engine.SmsService | mSmsService |
Constructors Summary |
---|
protected SmsCirChannel(ImpsConnection connection)
super(connection);
ImpsConnectionConfig cfg = connection.getConfig();
mAddr = cfg.getSmsCirAddr();
mPort = cfg.getSmsCirPort();
|
Methods Summary |
---|
public void | connect()
if (mAddr == null || mAddr.length() == 0) {
throw new ImException(ImpsErrorInfo.UNKNOWN_SERVER,
"Invalid sms addr");
}
mSmsService = SystemService.getDefault().getSmsService();
mSmsService.addSmsListener(mAddr, mPort, this);
sendHelo();
| public void | onFailure(int errorCode)
mConnection.shutdownOnError(new ImErrorInfo(ImpsErrorInfo.NETWORK_ERROR,
"Could not establish SMS CIR channel"));
| public void | onIncomingSms(byte[] data)
// It's safe to assume that each character is encoded into 7-bit since
// all characters in CIR are in gsm 7-bit alphabet.
int lengthSeptets = data.length * 8 / 7;
int numPaddingBits = data.length * 8 % 7;
String s = GsmAlphabet.gsm7BitPackedToString(data, 0,
lengthSeptets, numPaddingBits);
// CIR format: WVCI <version> <session cookie>
if (!s.startsWith("WVCI")) {
// not a valid CIR, ignore.
return;
}
String[] fields = s.split(" ");
if (fields.length != 3) {
// Not a valid CIR, ignore
return;
}
String sessionCookie = mConnection.getSession().getCookie();
if (sessionCookie.equalsIgnoreCase(fields[2])) {
mConnection.sendPollingRequest();
}
| private void | sendHelo()
String data = "HELO " + mConnection.getSession().getID();
try {
byte[] bytes = GsmAlphabet.stringToGsm7BitPacked(data);
mSmsService.sendSms(mAddr, mPort, bytes, this);
} catch (EncodeException ignore) {
}
| public void | shutdown()
mSmsService.removeSmsListener(this);
|
|