aboutsummaryrefslogtreecommitdiff
path: root/tests/telephonytests/src/com/android/internal/telephony/gsm/UsimDataDownloadTest.java.broken
blob: 9fbb86c26488a660b1c2a39de15e1c05381dc1c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.gsm;

import android.os.HandlerThread;
import android.test.AndroidTestCase;
import com.android.telephony.Rlog;

import java.nio.charset.Charset;

/**
 * Test SMS-PP data download to UICC.
 * Uses test messages from 3GPP TS 31.124 section 27.22.5.
 */
public class UsimDataDownloadTest extends AndroidTestCase {
    private static final String TAG = "UsimDataDownloadTest";

    class TestHandlerThread extends HandlerThread {
        private UsimDataDownloadHandler mHandler;

        TestHandlerThread() {
            super("TestHandlerThread");
        }

        @Override
        protected void onLooperPrepared() {
            synchronized (this) {
                mHandler = new UsimDataDownloadHandler(mCi, 0);
                notifyAll();
            }
        }

        UsimDataDownloadHandler getHandler() {
            synchronized (this) {
                while (mHandler == null) {
                    try {
                        wait();
                    } catch (InterruptedException ignored) {}
                }
                return mHandler;
            }
        }
    }

    private UsimDataDownloadCommands mCi;
    private TestHandlerThread mHandlerThread;
    UsimDataDownloadHandler mHandler;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mCi = new UsimDataDownloadCommands(mContext);
        mHandlerThread = new TestHandlerThread();
        mHandlerThread.start();
        mHandler = mHandlerThread.getHandler();
        Rlog.d(TAG, "mHandler is constructed");
    }

    @Override
    protected void tearDown() throws Exception {
        mHandlerThread.quit();
        super.tearDown();
    }

    // SMS-PP Message 3.1.1
    private static final byte[] SMS_PP_MESSAGE_3_1_1 = {
            // Service center address
            0x09, (byte) 0x91, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0xf8,

            0x04, 0x04, (byte) 0x91, 0x21, 0x43, 0x7f, 0x16, (byte) 0x89, 0x10, 0x10, 0x00, 0x00,
            0x00, 0x00, 0x0d, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61,
            0x67, 0x65, 0x20, 0x31
    };

    // SMS-PP Download Envelope 3.1.1
    private static final String SMS_PP_ENVELOPE_3_1_1 = "d12d8202838106099111223344556677f88b1c04"
            + "049121437f16891010000000000d546573744d6573736167652031";

    // SMS-PP Message 3.1.5
    private static final byte[] SMS_PP_MESSAGE_3_1_5 = {
            // Service center address
            0x09, (byte) 0x91, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0xf8,

            0x44, 0x04, (byte) 0x91, 0x21, 0x43, 0x7f, (byte) 0xf6, (byte) 0x89, 0x10, 0x10, 0x00,
            0x00, 0x00, 0x00, 0x1e, 0x02, 0x70, 0x00, 0x00, 0x19, 0x00, 0x0d, 0x00, 0x00,
            0x00, 0x00, (byte) 0xbf, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
            (byte) 0xdc, (byte) 0xdc, (byte) 0xdc, (byte) 0xdc, (byte) 0xdc, (byte) 0xdc,
            (byte) 0xdc, (byte) 0xdc, (byte) 0xdc, (byte) 0xdc
    };

    // SMS-PP Download Envelope 3.1.5
    private static final String SMS_PP_ENVELOPE_3_1_5 = "d13e8202838106099111223344556677f88b2d44"
            + "049121437ff6891010000000001e0270000019000d00000000bfff00000000000100"
            + "dcdcdcdcdcdcdcdcdcdc";

    public void testDataDownloadMessage1() {
        SmsMessage message = SmsMessage.createFromPdu(SMS_PP_MESSAGE_3_1_1);
        assertTrue("message is SMS-PP data download", message.isUsimDataDownload());

        mCi.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_1, 0x90, 0x00, "");
        mCi.expectAcknowledgeGsmSms(true, 0);
        mHandler.startDataDownload(message);
        mCi.assertExpectedMethodsCalled();

        mCi.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_1, 0x90, 0x00, "0123456789");
        mCi.expectAcknowledgeGsmSmsWithPdu(true, "00077f16050123456789");
        mHandler.startDataDownload(message);
        mCi.assertExpectedMethodsCalled();

        mCi.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_1, 0x62, 0xff, "0123456789abcdef");
        mCi.expectAcknowledgeGsmSmsWithPdu(false, "00d5077f16080123456789abcdef");
        mHandler.startDataDownload(message);
        mCi.assertExpectedMethodsCalled();
    }

    public void testDataDownloadMessage5() {
        SmsMessage message = SmsMessage.createFromPdu(SMS_PP_MESSAGE_3_1_5);
        assertTrue("message is SMS-PP data download", message.isUsimDataDownload());

        mCi.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_5, 0x90, 0x00, "9876543210");
        mCi.expectAcknowledgeGsmSmsWithPdu(true, "00077ff6059876543210");
        mHandler.startDataDownload(message);
        mCi.assertExpectedMethodsCalled();

        mCi.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_5, 0x93, 0x00, "");
        mCi.expectAcknowledgeGsmSms(false, 0xd4);   // SIM toolkit busy
        mHandler.startDataDownload(message);
        mCi.assertExpectedMethodsCalled();
    }
}