FileDocCategorySizeDatePackage
SmsCirChannel.javaAPI DocAndroid 1.5 API3347Wed May 06 22:42:46 BST 2009com.android.im.imps

SmsCirChannel

public 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 voidconnect()

        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 voidonFailure(int errorCode)

        mConnection.shutdownOnError(new ImErrorInfo(ImpsErrorInfo.NETWORK_ERROR,
                "Could not establish SMS CIR channel"));
    
public voidonIncomingSms(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 voidsendHelo()

        String data = "HELO " + mConnection.getSession().getID();
        try {
            byte[] bytes = GsmAlphabet.stringToGsm7BitPacked(data);
            mSmsService.sendSms(mAddr, mPort, bytes, this);
        } catch (EncodeException ignore) {
        }
    
public voidshutdown()

        mSmsService.removeSmsListener(this);