WapPushTestpublic class WapPushTest extends android.test.ServiceTestCase This is a simple framework for a test of a Service. See {@link android.test.ServiceTestCase
ServiceTestCase} for more information on how to write and extend service tests.
To run this test, you can type:
adb shell am instrument -w \
-e class com.android.smspush.unitTests.WapPushTest \
com.android.smspush.unitTests/android.test.InstrumentationTestRunner |
Fields Summary |
---|
private static final String | LOG_TAG | private static final boolean | LOCAL_LOGV | private static final int | TIME_WAIT | protected int | mAppIdValue | protected String | mAppIdName | protected int | mContentTypeValue | protected String | mContentTypeName | protected String | mPackageName | protected String | mClassName | protected byte[] | mGsmHeader | protected byte[] | mUserDataHeader | protected byte[] | mWspHeader | protected byte[] | mMessageBody | protected int | mWspHeaderStart | protected int | mWspHeaderLen | protected int | mWspContentTypeStart | final int[] | OMA_APPLICATION_ID_VALUESOMA application ID in binary form
http://www.openmobilealliance.org/tech/omna/omna-push-app-id.aspx | final String[] | OMA_APPLICATION_ID_NAMESOMA application ID in string form
http://www.openmobilealliance.org/tech/omna/omna-push-app-id.aspx | final int[] | OMA_CONTENT_TYPE_VALUESOMA content type in binary form
http://www.openmobilealliance.org/tech/omna/omna-wsp-content-type.aspx | final String[] | OMA_CONTENT_TYPE_NAMESOMA content type in string form
http://www.openmobilealliance.org/tech/omna/omna-wsp-content-type.aspx | private IDataVerify | mIVerify | android.content.ServiceConnection | mConn | private com.android.internal.telephony.IWapPushManager | mWapPush |
Constructors Summary |
---|
public WapPushTest()Main WapPushManager test module constructor
super(WapPushManager.class);
mClassName = this.getClass().getName();
mPackageName = this.getClass().getPackage().getName();
|
Methods Summary |
---|
android.content.Intent | createIntent(int pduType, int tranId)
Intent intent = new Intent();
intent.putExtra("transactionId", tranId);
intent.putExtra("pduType", pduType);
intent.putExtra("header", mGsmHeader);
intent.putExtra("data", mMessageBody);
// intent.putExtra("contentTypeParameters", null);
return intent;
| protected byte[] | createPDU(int testNum)
byte[] array = null;
// byte[] wsp = null;
switch (testNum) {
// sample pdu
case 1:
byte[] array1 = {
(byte) 0x00, // TID
(byte) 0x06, // Type = wap push
(byte) 0x00, // Length to be set later.
// Content-Type
(byte) 0x03, (byte) 0x02,
(byte) ((mContentTypeValue >> 8) & 0xff),
(byte) (mContentTypeValue & 0xff),
// Application-id
(byte) 0xaf, (byte) 0x02,
(byte) ((mAppIdValue >> 8) & 0xff),
(byte) (mAppIdValue& 0xff)
};
array1[2] = (byte) (array1.length - 3);
mWspHeader = array1;
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length + 7;
mWspHeaderLen = array1.length;
break;
// invalid wsp header
case 2:
byte[] array2 = {
(byte) 0x00, // invalid data
};
mWspHeader = array2;
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length;
mWspHeaderLen = array2.length;
break;
// random wsp header
case 3:
Random rd = new Random();
int arrSize = 150 + rd.nextInt(100);
byte[] array3 = new byte[arrSize];
int hdrEncodeLen;
array3[0] = (byte) 0x0;
array3[1] = (byte) 0x6;
hdrEncodeLen = encodeUint32(array3.length, null, 2);
hdrEncodeLen = encodeUint32(array3.length - hdrEncodeLen - 2, array3, 2);
array3[hdrEncodeLen + 2] = (byte) 0x3;
array3[hdrEncodeLen + 3] = (byte) 0x2;
array3[hdrEncodeLen + 4] = (byte) ((mContentTypeValue >> 8) & 0xff);
array3[hdrEncodeLen + 5] = (byte) (mContentTypeValue & 0xff);
createRandomWspHeader(array3, rd, hdrEncodeLen + 6, false);
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length + hdrEncodeLen + 6;
mWspHeaderLen = array3.length;
Log.d(LOG_TAG, "mContentTypeValue = " + mContentTypeValue
+ "(" + Integer.toHexString(mContentTypeValue) + ")");
mWspHeader = array3;
break;
// random wsp header w/o appid
case 4:
rd = new Random();
arrSize = 150 + rd.nextInt(100);
array3 = new byte[arrSize];
array3[0] = (byte) 0x0;
array3[1] = (byte) 0x6;
hdrEncodeLen = encodeUint32(array3.length, null, 2);
hdrEncodeLen = encodeUint32(array3.length - hdrEncodeLen - 2, array3, 2);
array3[hdrEncodeLen + 2] = (byte) 0x3;
array3[hdrEncodeLen + 3] = (byte) 0x2;
array3[hdrEncodeLen + 4] = (byte) ((mContentTypeValue >> 8) & 0xff);
array3[hdrEncodeLen + 5] = (byte) (mContentTypeValue & 0xff);
createRandomWspHeader(array3, rd, hdrEncodeLen + 6, true);
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length + hdrEncodeLen + 6;
mWspHeaderLen = array3.length;
Log.d(LOG_TAG, "mContentTypeValue = " + mContentTypeValue
+ "(" + Integer.toHexString(mContentTypeValue) + ")");
mWspHeader = array3;
break;
// random wsp header w/ random appid string
case 5:
rd = new Random();
arrSize = 150 + rd.nextInt(100);
array3 = new byte[arrSize];
array3[0] = (byte) 0x0;
array3[1] = (byte) 0x6;
hdrEncodeLen = encodeUint32(array3.length, null, 2);
hdrEncodeLen = encodeUint32(array3.length - hdrEncodeLen - 2, array3, 2);
array3[hdrEncodeLen + 2] = (byte) 0x3;
array3[hdrEncodeLen + 3] = (byte) 0x2;
array3[hdrEncodeLen + 4] = (byte) ((mContentTypeValue >> 8) & 0xff);
array3[hdrEncodeLen + 5] = (byte) (mContentTypeValue & 0xff);
createRandomWspHeaderStrAppId(array3, rd, hdrEncodeLen + 6, true);
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length + hdrEncodeLen + 6;
mWspHeaderLen = array3.length;
Log.d(LOG_TAG, "mContentTypeValue = " + mContentTypeValue
+ "(" + Integer.toHexString(mContentTypeValue) + ")");
mWspHeader = array3;
break;
// random wsp header w/ OMA appid string
case 6:
rd = new Random();
arrSize = 150 + rd.nextInt(100);
array3 = new byte[arrSize];
array3[0] = (byte) 0x0;
array3[1] = (byte) 0x6;
hdrEncodeLen = encodeUint32(array3.length, null, 2);
hdrEncodeLen = encodeUint32(array3.length - hdrEncodeLen - 2, array3, 2);
array3[hdrEncodeLen + 2] = (byte) 0x3;
array3[hdrEncodeLen + 3] = (byte) 0x2;
array3[hdrEncodeLen + 4] = (byte) ((mContentTypeValue >> 8) & 0xff);
array3[hdrEncodeLen + 5] = (byte) (mContentTypeValue & 0xff);
createRandomWspHeaderStrAppId(array3, rd, hdrEncodeLen + 6, false);
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length + hdrEncodeLen + 6;
mWspHeaderLen = array3.length;
Log.d(LOG_TAG, "mContentTypeValue = " + mContentTypeValue
+ "(" + Integer.toHexString(mContentTypeValue) + ")");
mWspHeader = array3;
break;
// random wsp header w/ OMA content type
case 7:
rd = new Random();
arrSize = 150 + rd.nextInt(100);
array3 = new byte[arrSize];
array3[0] = (byte) 0x0;
array3[1] = (byte) 0x6;
hdrEncodeLen = encodeUint32(array3.length, null, 2);
hdrEncodeLen = encodeUint32(array3.length - hdrEncodeLen - 2, array3, 2);
// encode content type
int contentLen = mContentTypeName.length();
int next = 2 + hdrEncodeLen;
mWspContentTypeStart = mGsmHeader.length + mUserDataHeader.length + next;
// next += encodeUint32(contentLen, array3, next);
int i;
Log.d(LOG_TAG, "mContentTypeName = " + mContentTypeName
+ ", contentLen = " + contentLen);
for (i = 0; i < contentLen; i++) {
array3[next + i] = (byte) mContentTypeName.charAt(i);
}
array3[next + i] = (byte) 0x0;
createRandomWspHeader(array3, rd, next + contentLen + 1, false);
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length
+ next + contentLen + 1;
mWspHeaderLen = array3.length;
mWspHeader = array3;
break;
// random wsp header w/ OMA content type, OMA app ID
case 8:
rd = new Random();
arrSize = 150 + rd.nextInt(100);
array3 = new byte[arrSize];
array3[0] = (byte) 0x0;
array3[1] = (byte) 0x6;
hdrEncodeLen = encodeUint32(array3.length, null, 2);
hdrEncodeLen = encodeUint32(array3.length - hdrEncodeLen - 2, array3, 2);
// encode content type
contentLen = mContentTypeName.length();
next = 2 + hdrEncodeLen;
mWspContentTypeStart = mGsmHeader.length + mUserDataHeader.length + next;
// next += encodeUint32(contentLen, array3, next);
Log.d(LOG_TAG, "mContentTypeName = " + mContentTypeName
+ ", contentLen = " + contentLen);
for (i = 0; i < contentLen; i++) {
array3[next + i] = (byte) mContentTypeName.charAt(i);
}
array3[next + i] = (byte) 0x0;
createRandomWspHeaderStrAppId(array3, rd, next + contentLen + 1, false);
mWspHeaderStart = mGsmHeader.length + mUserDataHeader.length
+ next + contentLen + 1;
mWspHeaderLen = array3.length;
mWspHeader = array3;
break;
default:
return null;
}
array = new byte[mGsmHeader.length + mUserDataHeader.length + mWspHeader.length
+ mMessageBody.length];
System.arraycopy(mGsmHeader, 0, array, 0, mGsmHeader.length);
System.arraycopy(mUserDataHeader, 0, array,
mGsmHeader.length, mUserDataHeader.length);
System.arraycopy(mWspHeader, 0, array,
mGsmHeader.length + mUserDataHeader.length, mWspHeader.length);
System.arraycopy(mMessageBody, 0, array,
mGsmHeader.length + mUserDataHeader.length + mWspHeader.length,
mMessageBody.length);
return array;
| protected void | createRandomWspHeader(byte[] arr, java.util.Random rd, int headerStart, boolean noAppId)Generate Random WSP header with integer application ID
boolean appIdAdded = false;
Log.d(LOG_TAG, "headerStart = " + headerStart + ", appId = " + mAppIdValue
+ "(" + Integer.toHexString(mAppIdValue) + ")");
Log.d(LOG_TAG, "random arr length:" + arr.length);
String typename[] = new String[] { "short int", "long int", "string", "uint32"};
while (!appIdAdded) {
int type;
int index = headerStart;
int len = arr.length;
int i;
boolean addAppid = false;
int tmpVal = 0;
int tmpVal2 = 0;
while (true) {
int add;
/*
* field name
* 0: short int
* 1: long int
* 2: text
* (no uint for param value)
*/
type = rd.nextInt(3);
switch (type) {
case 0: // header short integer
if (index > 100 && !appIdAdded) addAppid = true;
add = 1;
break;
case 1: // header long int
add = 1 + rd.nextInt(29);
break;
default: // header string
add = 2 + rd.nextInt(10);
break;
}
if (index + add >= len) break;
// fill header name
switch (type) {
case 0: // header short integer
if (!addAppid) {
do {
arr[index] = (byte) (0x80 | rd.nextInt(128));
} while (arr[index] == (byte) 0xaf);
} else {
Log.d(LOG_TAG, "appId added.");
arr[index] = (byte) 0xaf;
// if noAppId case, appId fld must be decieved.
if (noAppId) arr[index]++;
}
break;
case 1: // header long int
arr[index] = (byte) (add - 1);
tmpVal2 = 0;
for (i = 1; i < add; i++) {
tmpVal = rd.nextInt(255);
tmpVal2 = (tmpVal2 << 8) | tmpVal;
arr[index + i] = (byte) tmpVal;
}
// don't set application id
if (tmpVal2 == 0x2f) arr[index + 1]++;
break;
default: // header string
for (i = 0; i < add - 1; i++) {
tmpVal = rd.nextInt(127);
if (tmpVal < 32) tmpVal= (32 + tmpVal);
arr[index + i] = (byte) tmpVal;
}
arr[index + i] = (byte) 0x0;
break;
}
if (LOCAL_LOGV) {
Log.d(LOG_TAG, "field name index:" + index);
Log.d(LOG_TAG, "type:" + typename[type] + ", add:" + add);
if (type != 2) {
for (i = index; i< index + add; i++) {
System.out.print(Integer.toHexString(0xff & arr[i]));
System.out.print(' ");
}
} else {
System.out.print(Integer.toHexString(0xff & arr[index]));
System.out.print(' ");
String str = new String(arr, index + 1, add - 2);
for (i = 0; i < str.length(); i++) {
System.out.print(str.charAt(i));
System.out.print(' ");
}
}
System.out.print('\n");
}
index += add;
/*
* field value
* 0: short int
* 1: long int
* 2: text
* 3: uint
*/
if (addAppid) {
type = 1;
} else {
type = rd.nextInt(4);
}
switch (type) {
case 0: // header short integer
add = 1;
break;
case 1: // header long int
if (addAppid) {
int bit = 1;
int topBit = 0;
for (i = 0; i < 31; i++) {
if ((mAppIdValue & bit) > 0) topBit = i;
bit = (bit << 1);
}
add = 2 + topBit/8;
} else {
add = 1 + rd.nextInt(29);
}
break;
case 2: // header string
add = 2 + rd.nextInt(10);
break;
default: // uint32
add = 6;
}
if (index + add >= len) break;
// fill field value
switch (type) {
case 0: // header short int
arr[index] = (byte) (0x80 | rd.nextInt(128));
break;
case 1: // header long int
if (addAppid) {
addAppid = false;
appIdAdded = true;
arr[index] = (byte) (add - 1);
tmpVal = mAppIdValue;
for (i = add; i > 1; i--) {
arr[index + i - 1] = (byte) (tmpVal & 0xff);
tmpVal = (tmpVal >> 8);
}
} else {
arr[index] = (byte) (add - 1);
for (i = 1; i < add; i++) {
arr[index + i] = (byte) rd.nextInt(255);
}
}
break;
case 2:// header string
for (i = 0; i < add - 1; i++) {
tmpVal = rd.nextInt(127);
if (tmpVal < 32) tmpVal= (32 + tmpVal);
arr[index + i] = (byte) tmpVal;
}
arr[index + i] = (byte) 0x0;
break;
default: // header uvarint
arr[index] = (byte) 31;
tmpVal = rd.nextInt(0x0FFFFFFF);
add = 1 + encodeUint32(tmpVal, null, index + 1);
encodeUint32(tmpVal, arr, index + 1);
break;
}
if (LOCAL_LOGV) {
Log.d(LOG_TAG, "field value index:" + index);
Log.d(LOG_TAG, "type:" + typename[type] + ", add:" + add);
if (type != 2) {
for (i = index; i< index + add; i++) {
System.out.print(Integer.toHexString(0xff & arr[i]));
System.out.print(' ");
}
} else {
System.out.print(Integer.toHexString(0xff & arr[index]));
System.out.print(' ");
String str = new String(arr, index + 1, add - 2);
for (i = 0; i < str.length(); i++) {
System.out.print(str.charAt(i));
System.out.print(' ");
}
}
System.out.print('\n");
}
index += add;
}
if (noAppId) break;
}
Log.d(LOG_TAG, HexDump.dumpHexString(arr));
| protected void | createRandomWspHeaderStrAppId(byte[] arr, java.util.Random rd, int headerStart, boolean randomStr)Generate Random WSP header with string application ID
boolean appIdAdded = false;
Log.d(LOG_TAG, "random arr length:" + arr.length);
String typename[] = new String[] { "short int", "long int", "string", "uint32"};
while (!appIdAdded) {
int type;
int index = headerStart;
int len = arr.length;
int i;
boolean addAppid = false;
int tmpVal = 0;
int tmpVal2 = 0;
while (true) {
int add;
/*
* field name
* 0: short int
* 1: long int
* 2: text
* (no uint for param value)
*/
type = rd.nextInt(3);
switch (type) {
case 0: // header short integer
if (index > 100 && !appIdAdded) addAppid = true;
add = 1;
break;
case 1: // header long int
add = 1 + rd.nextInt(29);
break;
default: // header string
add = 2 + rd.nextInt(10);
break;
}
if (index + add >= len) break;
// fill header name
switch (type) {
case 0: // header short integer
if (!addAppid) {
do {
arr[index] = (byte) (0x80 | rd.nextInt(128));
} while (arr[index] == (byte) 0xaf);
} else {
Log.d(LOG_TAG, "appId added.");
arr[index] = (byte) 0xaf;
}
break;
case 1: // header long int
arr[index] = (byte) (add - 1);
tmpVal2 = 0;
for (i = 1; i < add; i++) {
tmpVal = rd.nextInt(255);
tmpVal2 = (tmpVal2 << 8) | tmpVal;
arr[index + i] = (byte) tmpVal;
}
// don't set application id
if (tmpVal2 == 0x2f) arr[index + 1]++;
break;
default: // header string
for (i = 0; i < add - 1; i++) {
tmpVal = rd.nextInt(127);
if (tmpVal < 32) tmpVal= (32 + tmpVal);
arr[index + i] = (byte) tmpVal;
}
arr[index + i] = (byte) 0x0;
break;
}
if (LOCAL_LOGV) {
Log.d(LOG_TAG, "field name index:" + index);
Log.d(LOG_TAG, "type:" + typename[type] + ", add:" + add);
if (type != 2) {
for (i = index; i < index + add; i++) {
System.out.print(Integer.toHexString(0xff & arr[i]));
System.out.print(' ");
}
} else {
System.out.print(Integer.toHexString(0xff & arr[index]));
System.out.print(' ");
String str = new String(arr, index + 1, add - 2);
for (i = 0; i < str.length(); i++) {
System.out.print(str.charAt(i));
System.out.print(' ");
}
}
System.out.print('\n");
}
index += add;
/*
* field value
* 0: short int
* 1: long int
* 2: text
* 3: uint
*/
if (addAppid) {
type = 2;
} else {
type = rd.nextInt(4);
}
switch (type) {
case 0: // header short integer
add = 1;
break;
case 1: // header long int
add = 1 + rd.nextInt(29);
break;
case 2: // header string
if (addAppid) {
if (randomStr) {
add = 1 + rd.nextInt(10);
byte[] randStr= new byte[add];
for (i = 0; i < add; i++) {
tmpVal = rd.nextInt(127);
if (tmpVal < 32) tmpVal= (32 + tmpVal);
randStr[i] = (byte) tmpVal;
}
mAppIdName = new String(randStr);
}
add = mAppIdName.length() + 1;
} else {
add = 2 + rd.nextInt(10);
}
break;
default: // uint32
add = 6;
}
if (index + add >= len) break;
// fill field value
switch (type) {
case 0: // header short int
arr[index] = (byte) (0x80 | rd.nextInt(128));
break;
case 1: // header long int
arr[index] = (byte) (add - 1);
for (i = 1; i < add; i++)
arr[index + i] = (byte) rd.nextInt(255);
break;
case 2:// header string
if (addAppid) {
addAppid = false;
appIdAdded = true;
for (i = 0; i < add - 1; i++) {
arr[index + i] = (byte) (mAppIdName.charAt(i));
}
Log.d(LOG_TAG, "mAppIdName added [" + mAppIdName + "]");
} else {
for (i = 0; i < add - 1; i++) {
tmpVal = rd.nextInt(127);
if (tmpVal < 32) tmpVal= (32 + tmpVal);
arr[index + i] = (byte) tmpVal;
}
}
arr[index + i] = (byte) 0x0;
break;
default: // header uvarint
arr[index] = (byte) 31;
tmpVal = rd.nextInt(0x0FFFFFFF);
add = 1 + encodeUint32(tmpVal, null, index + 1);
encodeUint32(tmpVal, arr, index + 1);
break;
}
if (LOCAL_LOGV) {
Log.d(LOG_TAG, "field value index:" + index);
Log.d(LOG_TAG, "type:" + typename[type] + ", add:" + add);
if (type != 2) {
for (i = index; i < index + add; i++) {
System.out.print(Integer.toHexString(0xff & arr[i]));
System.out.print(' ");
}
} else {
System.out.print(Integer.toHexString(0xff & arr[index]));
System.out.print(' ");
String str = new String(arr, index + 1, add - 2);
for (i = 0; i < str.length(); i++) {
System.out.print(str.charAt(i));
System.out.print(' ");
}
}
System.out.print('\n");
}
index += add;
}
}
Log.d(LOG_TAG, "headerStart = " + headerStart + ", mAppIdName = " + mAppIdName);
Log.d(LOG_TAG, HexDump.dumpHexString(arr));
| public int | dispatchWapPdu(byte[] pdu, com.android.internal.telephony.IWapPushManager wapPushMan)Copied from WapPushOverSms.
The code flow is not changed from the original.
if (false) Log.d(LOG_TAG, "Rx: " + IccUtils.bytesToHexString(pdu));
int index = 0;
int transactionId = pdu[index++] & 0xFF;
int pduType = pdu[index++] & 0xFF;
int headerLength = 0;
if ((pduType != WspTypeDecoder.PDU_TYPE_PUSH) &&
(pduType != WspTypeDecoder.PDU_TYPE_CONFIRMED_PUSH)) {
if (false) Log.w(LOG_TAG, "Received non-PUSH WAP PDU. Type = " + pduType);
return Intents.RESULT_SMS_HANDLED;
}
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
/**
* Parse HeaderLen(unsigned integer).
* From wap-230-wsp-20010705-a section 8.1.2
* The maximum size of a uintvar is 32 bits.
* So it will be encoded in no more than 5 octets.
*/
if (pduDecoder.decodeUintvarInteger(index) == false) {
if (false) Log.w(LOG_TAG, "Received PDU. Header Length error.");
return Intents.RESULT_SMS_GENERIC_ERROR;
}
headerLength = (int) pduDecoder.getValue32();
index += pduDecoder.getDecodedDataLength();
int headerStartIndex = index;
/**
* Parse Content-Type.
* From wap-230-wsp-20010705-a section 8.4.2.24
*
* Content-type-value = Constrained-media | Content-general-form
* Content-general-form = Value-length Media-type
* Media-type = (Well-known-media | Extension-Media) *(Parameter)
* Value-length = Short-length | (Length-quote Length)
* Short-length = <Any octet 0-30> (octet <= WAP_PDU_SHORT_LENGTH_MAX)
* Length-quote = <Octet 31> (WAP_PDU_LENGTH_QUOTE)
* Length = Uintvar-integer
*/
if (pduDecoder.decodeContentType(index) == false) {
if (false) Log.w(LOG_TAG, "Received PDU. Header Content-Type error.");
return Intents.RESULT_SMS_GENERIC_ERROR;
}
String mimeType = pduDecoder.getValueString();
long binaryContentType = pduDecoder.getValue32();
index += pduDecoder.getDecodedDataLength();
byte[] header = new byte[headerLength];
System.arraycopy(pdu, headerStartIndex, header, 0, header.length);
byte[] intentData;
if (mimeType != null && mimeType.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO)) {
intentData = pdu;
} else {
int dataIndex = headerStartIndex + headerLength;
intentData = new byte[pdu.length - dataIndex];
System.arraycopy(pdu, dataIndex, intentData, 0, intentData.length);
}
/**
* Seek for application ID field in WSP header.
* If application ID is found, WapPushManager substitute the message
* processing. Since WapPushManager is optional module, if WapPushManager
* is not found, legacy message processing will be continued.
*/
if (pduDecoder.seekXWapApplicationId(index, index + headerLength - 1)) {
index = (int) pduDecoder.getValue32();
pduDecoder.decodeXWapApplicationId(index);
String wapAppId = pduDecoder.getValueString();
if (wapAppId == null) {
wapAppId = Integer.toString((int) pduDecoder.getValue32());
}
String contentType = ((mimeType == null) ?
Long.toString(binaryContentType) : mimeType);
if (false) Log.v(LOG_TAG, "appid found: " + wapAppId + ":" + contentType);
try {
boolean processFurther = true;
// IWapPushManager wapPushMan = mWapConn.getWapPushManager();
if (wapPushMan == null) {
if (false) Log.w(LOG_TAG, "wap push manager not found!");
} else {
Intent intent = new Intent();
intent.putExtra("transactionId", transactionId);
intent.putExtra("pduType", pduType);
intent.putExtra("header", header);
intent.putExtra("data", intentData);
intent.putExtra("contentTypeParameters",
pduDecoder.getContentParameters());
int procRet = wapPushMan.processMessage(wapAppId, contentType, intent);
if (false) Log.v(LOG_TAG, "procRet:" + procRet);
if ((procRet & WapPushManagerParams.MESSAGE_HANDLED) > 0
&& (procRet & WapPushManagerParams.FURTHER_PROCESSING) == 0) {
processFurther = false;
}
}
if (!processFurther) {
return Intents.RESULT_SMS_HANDLED;
}
} catch (RemoteException e) {
if (false) Log.w(LOG_TAG, "remote func failed...");
}
}
if (false) Log.v(LOG_TAG, "fall back to existing handler");
return Activity.RESULT_OK;
| protected int | encodeShortInt(int sintVal, byte[] arr, int start)
int encodeLen = 0;
if (sintVal >= 0x80) return encodeLen;
encodeLen = 1;
arr[start] = (byte) (sintVal | 0x80);
return encodeLen;
| protected int | encodeUint32(int uint32Val, byte[] arr, int start)
int bit = 1;
int topbit = 0;
int encodeLen;
int tmpVal;
assertTrue(uint32Val >= 0);
for (int i = 0; i < 31; i++) {
if ((bit & uint32Val) > 0) topbit = i;
bit = (bit << 1);
}
encodeLen = topbit/7 + 1;
if (arr == null) return encodeLen;
//Log.d(LOG_TAG, "uint32Val = " + Integer.toHexString(uint32Val) + ", topbit = "
// + topbit + ", encodeLen = " + encodeLen);
tmpVal = uint32Val;
for (int i = encodeLen - 1; i >= 0; i--) {
long val = 0;
if (i < encodeLen - 1) val = 0x80;
val |= tmpVal & 0x7f;
arr[start + i] = (byte) (val & 0xFF);
tmpVal = (tmpVal >> 7);
}
return encodeLen;
| protected java.lang.String | getContentTypeName(int ctypeVal)
int i;
for (i = 0; i < OMA_CONTENT_TYPE_VALUES.length; i++) {
if (ctypeVal == OMA_CONTENT_TYPE_VALUES[i]) {
return OMA_CONTENT_TYPE_NAMES[i];
}
}
return null;
| com.android.internal.telephony.IWapPushManager | getInterface()
if (mWapPush != null) return mWapPush;
Intent startIntent = new Intent();
startIntent.setClass(getContext(), WapPushManager.class);
IBinder service = bindService(startIntent);
mWapPush = IWapPushManager.Stub.asInterface(service);
return mWapPush;
| IDataVerify | getVerifyInterface()
while (mIVerify == null) {
// wait for the activity receive data.
try {
Thread.sleep(TIME_WAIT);
} catch (InterruptedException e) {}
}
return mIVerify;
| protected boolean | isContentTypeMapped(int ctypeVal)
int i;
for (i = 0; i < OMA_CONTENT_TYPE_VALUES.length; i++) {
if (ctypeVal == OMA_CONTENT_TYPE_VALUES[i]) return true;
}
return false;
| protected byte[] | retrieveWspBody()
byte[] array = new byte[mWspHeader.length + mMessageBody.length];
System.arraycopy(mWspHeader, 0, array, 0, mWspHeader.length);
System.arraycopy(mMessageBody, 0, array, mWspHeader.length, mMessageBody.length);
return array;
| public void | setUp()Initialize the verifier
try {
super.setUp();
// get verifier
getContext().bindService(new Intent(IDataVerify.class.getName()),
mConn, Context.BIND_AUTO_CREATE);
} catch (Exception e) {
Log.w(LOG_TAG, "super exception");
}
// Log.d(LOG_TAG, "test setup");
| public void | testAddPackage0()Add sqlite injection test
String inject = "' union select 0,'com.android.settings','com.android.settings.Settings',0,0,0--";
// insert new data
IWapPushManager iwapman = getInterface();
try {
assertFalse(iwapman.addPackage(
inject,
Integer.toString(mContentTypeValue),
mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, true, true));
} catch (RemoteException e) {
assertTrue(false);
}
| public void | testAddPackage1()Add package test
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
utAddPackage(true, true);
mAppIdValue += 10;
utAddPackage(true, false);
mContentTypeValue += 20;
utAddPackage(false, true);
mContentTypeValue += 20;
utAddPackage(false, false);
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
// clean up data
try {
IWapPushManager iwapman = getInterface();
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
mAppIdValue += 10;
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
mContentTypeValue += 20;
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
mContentTypeValue += 20;
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
| public void | testAddPackage2()Add duprecated package test.
try {
IWapPushManager iwapman = getInterface();
// set up data
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName, 0,
false, false);
iwapman.addPackage(Integer.toString(mAppIdValue + 10),
Integer.toString(mContentTypeValue), mPackageName, mClassName, 0,
false, false);
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue + 10), mPackageName, mClassName, 0,
false, false);
assertFalse(iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName, 0,
false, false));
assertFalse(iwapman.addPackage(Integer.toString(mAppIdValue + 10),
Integer.toString(mContentTypeValue), mPackageName, mClassName, 0,
false, false));
assertFalse(iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue + 10), mPackageName, mClassName, 0,
false, false));
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
iwapman.deletePackage(Integer.toString(mAppIdValue + 10),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue + 10), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
| public void | testDecoder1()WspTypeDecoder test, normal pdu
boolean res;
int originalAppIdValue = mAppIdValue;
Random rd = new Random();
for (int i = 0; i < 10; i++) {
mAppIdValue = rd.nextInt(0xFFFF);
byte[] pdu = createPDU(1);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.seekXWapApplicationId(mWspHeaderStart,
mWspHeaderStart + mWspHeaderLen - 1);
assertTrue(res);
int index = (int) pduDecoder.getValue32();
res = pduDecoder.decodeXWapApplicationId(index);
assertTrue(res);
Log.d(LOG_TAG, "mAppIdValue: " + mAppIdValue
+ ", val: " + pduDecoder.getValue32());
assertTrue(mAppIdValue == (int) pduDecoder.getValue32());
}
mAppIdValue = originalAppIdValue;
| public void | testDecoder2()WspTypeDecoder test, no header
boolean res;
int originalAppIdValue = mAppIdValue;
Random rd = new Random();
mAppIdValue = rd.nextInt(0xFFFF);
byte[] pdu = createPDU(2);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.seekXWapApplicationId(mWspHeaderStart,
mWspHeaderStart + mWspHeaderLen - 1);
assertFalse(res);
mAppIdValue = originalAppIdValue;
| public void | testDecoder3()WspTypeDecoder test, decode appid test
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
Random rd = new Random();
for (int i = 0; i < 100; i++) {
mAppIdValue = rd.nextInt(0x0FFFFFFF);
mContentTypeValue = rd.nextInt(0x0FFF);
byte[] pdu = createPDU(3);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.seekXWapApplicationId(mWspHeaderStart,
mWspHeaderStart + mWspHeaderLen - 1);
assertTrue(res);
int index = (int) pduDecoder.getValue32();
res = pduDecoder.decodeXWapApplicationId(index);
assertTrue(res);
Log.d(LOG_TAG, "mAppIdValue: " + mAppIdValue
+ ", val: " + pduDecoder.getValue32());
assertTrue(mAppIdValue == (int) pduDecoder.getValue32());
}
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
| public void | testDecoder4()WspTypeDecoder test, no appid test
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
Random rd = new Random();
for (int i = 0; i < 100; i++) {
mAppIdValue = rd.nextInt(0x0FFFFFFF);
mContentTypeValue = rd.nextInt(0x0FFF);
byte[] pdu = createPDU(4);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.seekXWapApplicationId(mWspHeaderStart,
mWspHeaderStart + mWspHeaderLen - 1);
assertFalse(res);
}
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
| public void | testDecoder5()WspTypeDecoder test, decode string appid test
boolean res;
String originalAppIdName = mAppIdName;
int originalContentTypeValue = mContentTypeValue;
Random rd = new Random();
for (int i = 0; i < 10; i++) {
mAppIdValue = rd.nextInt(0x0FFFFFFF);
mContentTypeValue = rd.nextInt(0x0FFF);
byte[] pdu = createPDU(5);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.seekXWapApplicationId(mWspHeaderStart,
mWspHeaderStart + mWspHeaderLen - 1);
assertTrue(res);
int index = (int) pduDecoder.getValue32();
res = pduDecoder.decodeXWapApplicationId(index);
assertTrue(res);
Log.d(LOG_TAG, "mAppIdValue: [" + mAppIdName + "], val: ["
+ pduDecoder.getValueString() + "]");
assertTrue(mAppIdName.equals(pduDecoder.getValueString()));
}
mAppIdName = originalAppIdName;
mContentTypeValue = originalContentTypeValue;
| public void | testDecoder6()WspTypeDecoder test, decode string appid test
boolean res;
String originalAppIdName = mAppIdName;
int originalContentTypeValue = mContentTypeValue;
Random rd = new Random();
for (int i = 0; i < OMA_APPLICATION_ID_NAMES.length; i++) {
mAppIdName = OMA_APPLICATION_ID_NAMES[i];
mContentTypeValue = rd.nextInt(0x0FFF);
byte[] pdu = createPDU(6);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.seekXWapApplicationId(mWspHeaderStart,
mWspHeaderStart + mWspHeaderLen - 1);
assertTrue(res);
int index = (int) pduDecoder.getValue32();
res = pduDecoder.decodeXWapApplicationId(index);
assertTrue(res);
Log.d(LOG_TAG, "mAppIdValue: [" + mAppIdName + "], val: ["
+ pduDecoder.getValueString() + "]");
assertTrue(mAppIdName.equals(pduDecoder.getValueString()));
}
mAppIdName = originalAppIdName;
mContentTypeValue = originalContentTypeValue;
| public void | testDecoder7()WspTypeDecoder test, decode OMA content type
boolean res;
String originalAppIdName = mAppIdName;
int originalContentTypeValue = mContentTypeValue;
Random rd = new Random();
for (int i = 0; i < OMA_CONTENT_TYPE_NAMES.length; i++) {
mContentTypeName = OMA_CONTENT_TYPE_NAMES[i];
byte[] pdu = createPDU(7);
WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
res = pduDecoder.decodeContentType(mWspContentTypeStart);
assertTrue(res);
Log.d(LOG_TAG, "mContentTypeName: [" + mContentTypeName + "], val: ["
+ pduDecoder.getValueString() + "]");
assertTrue(mContentTypeName.equals(pduDecoder.getValueString()));
}
mAppIdName = originalAppIdName;
mContentTypeValue = originalContentTypeValue;
| public void | testDeletePackage1()Deleting package test
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
// set up data
try {
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
mAppIdValue += 10;
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
mContentTypeValue += 20;
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
mContentTypeValue += 20;
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
} catch (RemoteException e) {
assertTrue(false);
}
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
utDeletePackage();
mAppIdValue += 10;
utDeletePackage();
mContentTypeValue += 20;
utDeletePackage();
mContentTypeValue += 20;
utDeletePackage();
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
| public void | testDeletePackage2()Deleting invalid package test
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
try {
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
assertFalse(iwapman.deletePackage(Integer.toString(mAppIdValue + 10),
Integer.toString(mContentTypeValue), mPackageName, mClassName));
assertFalse(iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue + 20), mPackageName, mClassName));
assertFalse(iwapman.deletePackage(Integer.toString(mAppIdValue + 10),
Integer.toString(mContentTypeValue + 20), mPackageName, mClassName));
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
| public void | testIntegration1()Integration test 1, simple case
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
String originalAppIdName = mAppIdName;
String originalContentTypeName = mContentTypeName;
String originalClassName = mClassName;
byte[] originalMessageBody = mMessageBody;
Random rd = new Random();
mMessageBody = new byte[100 + rd.nextInt(100)];
rd.nextBytes(mMessageBody);
byte[] pdu = createPDU(1);
byte[] wappushPdu = retrieveWspBody();
mClassName = "com.android.smspush.unitTests.ReceiverActivity";
// Phone dummy = new DummyPhone(getContext());
// Phone gsm = PhoneFactory.getGsmPhone();
// GSMPhone gsm = new GSMPhone(getContext(), new SimulatedCommands(), null, true);
// WapPushOverSms dispatcher = new WapPushOverSms(dummy, null);
try {
// set up data
IWapPushManager iwapman = getInterface();
IDataVerify dataverify = getVerifyInterface();
dataverify.resetData();
if (isContentTypeMapped(mContentTypeValue)) {
// content type is mapped
mContentTypeName = getContentTypeName(mContentTypeValue);
Log.d(LOG_TAG, "mContentTypeValue mapping "
+ mContentTypeName + ":" + mContentTypeValue);
} else {
mContentTypeName = Integer.toString(mContentTypeValue);
}
iwapman.addPackage(Integer.toString(mAppIdValue),
mContentTypeName, mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_ACTIVITY, false, false);
dispatchWapPdu(wappushPdu, iwapman);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
mContentTypeName, mPackageName, mClassName);
assertTrue(dataverify.verifyData(mMessageBody));
} catch (RemoteException e) {
}
mClassName = originalClassName;
mAppIdName = originalAppIdName;
mContentTypeName = originalContentTypeName;
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
mMessageBody = originalMessageBody;
| public void | testIntegration2()Integration test 2, random mAppIdValue(int), all OMA content type
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
String originalAppIdName = mAppIdName;
String originalContentTypeName = mContentTypeName;
String originalClassName = mClassName;
byte[] originalMessageBody = mMessageBody;
Random rd = new Random();
IWapPushManager iwapman = getInterface();
IDataVerify dataverify = getVerifyInterface();
mClassName = "com.android.smspush.unitTests.ReceiverActivity";
for (int i = 0; i < OMA_CONTENT_TYPE_NAMES.length; i++) {
mContentTypeName = OMA_CONTENT_TYPE_NAMES[i];
mAppIdValue = rd.nextInt(0x0FFFFFFF);
mMessageBody = new byte[100 + rd.nextInt(100)];
rd.nextBytes(mMessageBody);
byte[] pdu = createPDU(7);
byte[] wappushPdu = retrieveWspBody();
try {
dataverify.resetData();
// set up data
iwapman.addPackage(Integer.toString(mAppIdValue),
mContentTypeName, mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_ACTIVITY, false, false);
dispatchWapPdu(wappushPdu, iwapman);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
mContentTypeName, mPackageName, mClassName);
if (mContentTypeName.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO)) {
assertTrue(dataverify.verifyData(wappushPdu));
} else {
assertTrue(dataverify.verifyData(mMessageBody));
}
} catch (RemoteException e) {
}
}
mClassName = originalClassName;
mAppIdName = originalAppIdName;
mContentTypeName = originalContentTypeName;
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
mMessageBody = originalMessageBody;
| public void | testIntegration3()Integration test 3, iterate OmaApplication ID, random binary content type
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
String originalAppIdName = mAppIdName;
String originalContentTypeName = mContentTypeName;
String originalClassName = mClassName;
byte[] originalMessageBody = mMessageBody;
Random rd = new Random();
IWapPushManager iwapman = getInterface();
IDataVerify dataverify = getVerifyInterface();
mClassName = "com.android.smspush.unitTests.ReceiverService";
for (int i = 0; i < OMA_APPLICATION_ID_NAMES.length; i++) {
mAppIdName = OMA_APPLICATION_ID_NAMES[i];
mContentTypeValue = rd.nextInt(0x0FFF);
mMessageBody = new byte[100 + rd.nextInt(100)];
rd.nextBytes(mMessageBody);
byte[] pdu = createPDU(6);
byte[] wappushPdu = retrieveWspBody();
try {
dataverify.resetData();
// set up data
if (isContentTypeMapped(mContentTypeValue)) {
// content type is mapped to integer value
mContentTypeName = getContentTypeName(mContentTypeValue);
Log.d(LOG_TAG, "mContentTypeValue mapping "
+ mContentTypeValue + ":" + mContentTypeName);
} else {
mContentTypeName = Integer.toString(mContentTypeValue);
}
iwapman.addPackage(mAppIdName,
mContentTypeName, mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, false, false);
dispatchWapPdu(wappushPdu, iwapman);
// clean up data
iwapman.deletePackage(mAppIdName,
mContentTypeName, mPackageName, mClassName);
if (mContentTypeName.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO)) {
assertTrue(dataverify.verifyData(wappushPdu));
} else {
assertTrue(dataverify.verifyData(mMessageBody));
}
} catch (RemoteException e) {
}
}
mClassName = originalClassName;
mAppIdName = originalAppIdName;
mContentTypeName = originalContentTypeName;
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
mMessageBody = originalMessageBody;
| public void | testIntegration4()Integration test 4, iterate OmaApplication ID, Oma content type
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
String originalAppIdName = mAppIdName;
String originalContentTypeName = mContentTypeName;
String originalClassName = mClassName;
byte[] originalMessageBody = mMessageBody;
Random rd = new Random();
IWapPushManager iwapman = getInterface();
IDataVerify dataverify = getVerifyInterface();
mClassName = "com.android.smspush.unitTests.ReceiverService";
for (int i = 0; i < OMA_APPLICATION_ID_NAMES.length
+ OMA_CONTENT_TYPE_NAMES.length; i++) {
mAppIdName = OMA_APPLICATION_ID_NAMES[rd.nextInt(OMA_APPLICATION_ID_NAMES.length)];
int contIndex = rd.nextInt(OMA_CONTENT_TYPE_NAMES.length);
mContentTypeName = OMA_CONTENT_TYPE_NAMES[contIndex];
mMessageBody = new byte[100 + rd.nextInt(100)];
rd.nextBytes(mMessageBody);
byte[] pdu = createPDU(8);
byte[] wappushPdu = retrieveWspBody();
try {
dataverify.resetData();
// set up data
iwapman.addPackage(mAppIdName,
mContentTypeName, mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, false, false);
dispatchWapPdu(wappushPdu, iwapman);
// clean up data
iwapman.deletePackage(mAppIdName,
mContentTypeName, mPackageName, mClassName);
if (mContentTypeName.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO)) {
assertTrue(dataverify.verifyData(wappushPdu));
} else {
assertTrue(dataverify.verifyData(mMessageBody));
}
} catch (RemoteException e) {
}
}
mClassName = originalClassName;
mAppIdName = originalAppIdName;
mContentTypeName = originalContentTypeName;
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
mMessageBody = originalMessageBody;
| public void | testIntegration5()Integration test 5, iterate binary OmaApplication ID, Oma binary content type
boolean res;
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
String originalAppIdName = mAppIdName;
String originalContentTypeName = mContentTypeName;
String originalClassName = mClassName;
byte[] originalMessageBody = mMessageBody;
Random rd = new Random();
IWapPushManager iwapman = getInterface();
IDataVerify dataverify = getVerifyInterface();
mClassName = "com.android.smspush.unitTests.ReceiverService";
for (int i = 0; i < OMA_APPLICATION_ID_VALUES.length +
OMA_CONTENT_TYPE_VALUES.length; i++) {
mAppIdValue = OMA_APPLICATION_ID_VALUES[rd.nextInt(
OMA_APPLICATION_ID_VALUES.length)];
mContentTypeValue =
OMA_CONTENT_TYPE_VALUES[rd.nextInt(OMA_CONTENT_TYPE_VALUES.length)];
mMessageBody = new byte[100 + rd.nextInt(100)];
rd.nextBytes(mMessageBody);
byte[] pdu = createPDU(3);
byte[] wappushPdu = retrieveWspBody();
try {
dataverify.resetData();
// set up data
if (isContentTypeMapped(mContentTypeValue)) {
// content type is mapped to integer value
mContentTypeName = getContentTypeName(mContentTypeValue);
Log.d(LOG_TAG, "mContentTypeValue mapping "
+ mContentTypeValue + ":" + mContentTypeName);
} else {
mContentTypeName = Integer.toString(mContentTypeValue);
}
iwapman.addPackage(Integer.toString(mAppIdValue),
mContentTypeName, mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, false, false);
dispatchWapPdu(wappushPdu, iwapman);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
mContentTypeName, mPackageName, mClassName);
if (mContentTypeName.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO)) {
assertTrue(dataverify.verifyData(wappushPdu));
} else {
assertTrue(dataverify.verifyData(mMessageBody));
}
} catch (RemoteException e) {
}
}
mClassName = originalClassName;
mAppIdName = originalAppIdName;
mContentTypeName = originalContentTypeName;
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
mMessageBody = originalMessageBody;
| public void | testProcessMsg1()Message processing test, start activity
byte[] pdu = createPDU(1);
int headerLen = pdu.length -
(mGsmHeader.length + mUserDataHeader.length + mMessageBody.length);
int pduType = 6;
int tranId = 0;
String originalPackageName = mPackageName;
String originalClassName = mClassName;
try {
mClassName = "com.android.smspush.unitTests.ReceiverActivity";
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_ACTIVITY, false, false);
assertTrue((iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId))
& WapPushManagerParams.MESSAGE_HANDLED) ==
WapPushManagerParams.MESSAGE_HANDLED);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mPackageName = originalPackageName;
mClassName = originalClassName;
| public void | testProcessMsg2()Message processing test, start service
byte[] pdu = createPDU(1);
int headerLen = pdu.length - (mGsmHeader.length +
mUserDataHeader.length + mMessageBody.length);
int pduType = 6;
int tranId = 0;
String originalPackageName = mPackageName;
String originalClassName = mClassName;
try {
mClassName = "com.android.smspush.unitTests.ReceiverService";
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, false, false);
assertTrue((iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId))
& WapPushManagerParams.MESSAGE_HANDLED) ==
WapPushManagerParams.MESSAGE_HANDLED);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mPackageName = originalPackageName;
mClassName = originalClassName;
| public void | testProcessMsg3()Message processing test, no signature
byte[] pdu = createPDU(1);
int headerLen = pdu.length -
(mGsmHeader.length + mUserDataHeader.length + mMessageBody.length);
int pduType = 6;
int tranId = 0;
String originalPackageName = mPackageName;
String originalClassName = mClassName;
try {
mPackageName = "com.android.development";
mClassName = "com.android.development.Development";
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, true, false);
assertFalse((iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId))
& WapPushManagerParams.MESSAGE_HANDLED) ==
WapPushManagerParams.MESSAGE_HANDLED);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mPackageName = originalPackageName;
mClassName = originalClassName;
| public void | testProcessMsg4()Message processing test, received body data verification test
byte[] originalMessageBody = mMessageBody;
mMessageBody = new byte[] {
(byte) 0xee,
(byte) 0xff,
(byte) 0xee,
(byte) 0xff,
(byte) 0xee,
(byte) 0xff,
(byte) 0xee,
(byte) 0xff,
(byte) 0xee,
(byte) 0xff,
(byte) 0xee,
(byte) 0xff,
};
byte[] pdu = createPDU(1);
int headerLen = pdu.length -
(mGsmHeader.length + mUserDataHeader.length + mMessageBody.length);
int pduType = 6;
int tranId = 0;
String originalPackageName = mPackageName;
String originalClassName = mClassName;
try {
IWapPushManager iwapman = getInterface();
IDataVerify dataverify = getVerifyInterface();
dataverify.resetData();
// set up data
mClassName = "com.android.smspush.unitTests.ReceiverActivity";
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_ACTIVITY, false, false);
iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId));
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
assertTrue(dataverify.verifyData(mMessageBody));
// set up data
dataverify.resetData();
mClassName = "com.android.smspush.unitTests.ReceiverService";
mMessageBody = new byte[] {
(byte) 0xaa,
(byte) 0xbb,
(byte) 0x11,
(byte) 0x22,
(byte) 0xaa,
(byte) 0xbb,
(byte) 0x11,
(byte) 0x22,
(byte) 0xaa,
(byte) 0xbb,
(byte) 0x11,
(byte) 0x22,
(byte) 0xaa,
(byte) 0xbb,
(byte) 0x11,
(byte) 0x22,
(byte) 0xaa,
(byte) 0xbb,
(byte) 0x11,
(byte) 0x22,
(byte) 0xaa,
(byte) 0xbb,
(byte) 0x11,
(byte) 0x22,
};
pdu = createPDU(1);
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, false, false);
iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId));
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
// Log.d(LOG_TAG, HexDump.dumpHexString(mMessageBody));
assertTrue(dataverify.verifyData(mMessageBody));
} catch (RemoteException e) {
assertTrue(false);
}
mPackageName = originalPackageName;
mClassName = originalClassName;
mMessageBody = originalMessageBody;
| public void | testProcessMsg5()Message processing test, send invalid sms data
byte[] pdu = createPDU(2);
int headerLen = pdu.length -
(mGsmHeader.length + mUserDataHeader.length + mMessageBody.length);
int pduType = 6;
int tranId = 0;
String originalPackageName = mPackageName;
String originalClassName = mClassName;
try {
mClassName = "com.android.smspush.unitTests.ReceiverActivity";
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_ACTIVITY, false, false);
assertTrue((iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId))
& WapPushManagerParams.MESSAGE_HANDLED) ==
WapPushManagerParams.MESSAGE_HANDLED);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mPackageName = originalPackageName;
mClassName = originalClassName;
| public void | testProcessMsg6()Message processing test, no receiver application
byte[] pdu = createPDU(1);
int headerLen = pdu.length -
(mGsmHeader.length + mUserDataHeader.length + mMessageBody.length);
int pduType = 6;
int tranId = 0;
String originalPackageName = mPackageName;
String originalClassName = mClassName;
try {
mClassName = "com.android.smspush.unitTests.NoReceiver";
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_ACTIVITY, false, false);
assertFalse((iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId))
& WapPushManagerParams.MESSAGE_HANDLED) ==
WapPushManagerParams.MESSAGE_HANDLED);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
// set up data
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, false, false);
assertFalse((iwapman.processMessage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
createIntent(pduType, tranId))
& WapPushManagerParams.MESSAGE_HANDLED) ==
WapPushManagerParams.MESSAGE_HANDLED);
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mPackageName = originalPackageName;
mClassName = originalClassName;
| public void | testUpdatePackage1()Updating package test
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
// set up data
try {
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
mAppIdValue += 10;
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
mContentTypeValue += 20;
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
mContentTypeValue += 20;
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
} catch (RemoteException e) {
assertTrue(false);
}
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
utUpdatePackage(false, false);
mAppIdValue += 10;
utUpdatePackage(false, true);
mContentTypeValue += 20;
utUpdatePackage(true, false);
mContentTypeValue += 20;
utUpdatePackage(true, true);
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
// clean up data
try {
IWapPushManager iwapman = getInterface();
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
mAppIdValue += 10;
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
mContentTypeValue += 20;
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
mContentTypeValue += 20;
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
} catch (RemoteException e) {
assertTrue(false);
}
mAppIdValue = originalAppIdValue;
mContentTypeValue = originalContentTypeValue;
| public void | testUpdatePackage2()Updating invalid package test
int originalAppIdValue = mAppIdValue;
int originalContentTypeValue = mContentTypeValue;
try {
// set up data
IWapPushManager iwapman = getInterface();
iwapman.addPackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName,
0, false, false);
assertFalse(iwapman.updatePackage(
Integer.toString(mAppIdValue + 10),
Integer.toString(mContentTypeValue),
mPackageName, mClassName, 0, false, false));
assertFalse(iwapman.updatePackage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue + 10),
mPackageName, mClassName, 0, false, false));
assertTrue(iwapman.updatePackage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName + "dummy_data", mClassName, 0, false, false));
assertTrue(iwapman.updatePackage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName + "dummy_data", 0, false, false));
// clean up data
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName, mClassName);
iwapman.deletePackage(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue), mPackageName,
mClassName + "dummy_data");
} catch (RemoteException e) {
assertTrue(false);
}
| protected void | utAddPackage(boolean need_sig, boolean more_proc)
IWapPushManager iwapman = getInterface();
// insert new data
try {
assertTrue(iwapman.addPackage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, need_sig, more_proc));
} catch (RemoteException e) {
assertTrue(false);
}
// verify the data
WapPushManager wpman = getService();
assertTrue(wpman.verifyData(Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, need_sig, more_proc));
| protected void | utDeletePackage()
IWapPushManager iwapman = getInterface();
try {
assertTrue(iwapman.deletePackage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName));
} catch (RemoteException e) {
assertTrue(false);
}
// verify the data
WapPushManager wpman = getService();
assertTrue(!wpman.isDataExist(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName));
| protected void | utUpdatePackage(boolean need_sig, boolean more_proc)
IWapPushManager iwapman = getInterface();
// insert new data
try {
assertTrue(iwapman.updatePackage(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, need_sig, more_proc));
} catch (RemoteException e) {
assertTrue(false);
}
// verify the data
WapPushManager wpman = getService();
assertTrue(wpman.verifyData(
Integer.toString(mAppIdValue),
Integer.toString(mContentTypeValue),
mPackageName, mClassName,
WapPushManagerParams.APP_TYPE_SERVICE, need_sig, more_proc));
|
|