OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / hardware / ril / mock-ril / src / js / simulated_icc.js
1 /**
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * Simulated Icc
19  */
20 function Icc() {
21
22     var MCC = '310';
23     var MNC = '260';
24     var MSN = '123456789';
25     var IMEI = '123456789012345';
26     var IMEISV = '00';
27
28     function RilAppStatus(type, state, persoState, aidPtr, appLabelPtr, pin1R, curPin1, curPin2) {
29         this.appType = type;
30         this.appState = state;
31         this.persoSubstate = persoState;
32         this.aid = aidPtr;
33         this.appLabel = appLabelPtr;
34         this.pin1Replaced = pin1R;
35         this.pin1 = curPin1;
36         this.pint2 = curPin2;
37     }
38
39     function RilCardStatus() {
40         this.cardState = CARDSTATE_PRESENT;
41         this.universalPinState = PINSTATE_UNKNOWN;
42         this.gsmUmtsSubscriptionAppIndex = 0;
43         this.cdmaSubscriptionAppIndex = CARD_MAX_APPS;
44         this.numApplications = 1;
45         this.applications = new Array(CARD_MAX_APPS);
46
47         // Initialize application status
48         for (i = 0; i < CARD_MAX_APPS; i++) {
49             var app = new RilAppStatus(APPTYPE_UNKNOWN, APPSTATE_UNKNOWN, PERSOSUBSTATE_UNKNOWN,
50                                        null, null, 0, PINSTATE_UNKNOWN, PINSTATE_UNKNOWN);
51             this.applications[i] = app;
52         }
53
54         // set gsm application status.
55         var gsmApp = new RilAppStatus(APPTYPE_SIM, APPSTATE_READY, PERSOSUBSTATE_READY, null, null,
56                                      0, PINSTATE_UNKNOWN, PINSTATE_UNKNOWN);
57         this.applications[this.gsmUmtsSubscriptionAppIndex] = gsmApp;
58     }
59
60     var cardStatus = new RilCardStatus();
61
62     // The result returned by the request handlers
63     var result = new Object();
64
65     this.rilRequestGetSimStatus = function(req) { // 1
66         print('Icc: rilRequestGetSimStatus');
67
68         var rsp = new Object();
69         rsp.cardStatus = cardStatus;
70
71         result.responseProtobuf = rilSchema[packageNameAndSeperator +
72                                  'RspGetSimStatus'].serialize(rsp);
73         return result;
74     }
75
76     this.rilRequestEnterSimPin = function(req) { // 2
77         print('Icc: rilRequestEnterSimPin req.data.pin=' + req.data.pin);
78
79         var rsp = new Object();
80         rsp.retriesRemaining = 3;
81         result.responseProtobuf = rilSchema[packageNameAndSeperator +
82                                  'RspEnterSimPin'].serialize(rsp);
83         return result;
84     }
85
86     this.rilRequestGetImsi = function(req) { // 11
87         print('Icc: rilRequestGetImsi');
88
89         var rsp = new Object();
90         rsp.strings = new Array();
91         rsp.strings[0] = MCC + MNC + MSN;
92         result.responseProtobuf = rilSchema[packageNameAndSeperator +
93                                  'RspStrings'].serialize(rsp);
94         return result;
95     }
96
97     this.rilRequestOperator = function(req) { // 22
98         print('Icc: rilRequestOperator');
99
100         var rsp = new Object();
101         rsp.longAlphaOns = 'Mock-Ril long Alpha Ons';
102         rsp.shortAlphaOns = 'Mock-Ril';
103         rsp.mccMnc = MCC + MNC;
104         result.responseProtobuf = rilSchema[packageNameAndSeperator +
105                                  'RspOperator'].serialize(rsp);
106         return result;
107     }
108
109     this.rilRequestGetImei = function(req) { // 38
110         print('Icc: rilRequestGetImei');
111
112         var rsp = new Object();
113         rsp.strings = new Array();
114         rsp.strings[0] = IMEI;
115         result.responseProtobuf = rilSchema[packageNameAndSeperator +
116                                  'RspStrings'].serialize(rsp);
117         return result;
118     }
119
120     this.rilRequestGetImeisv = function(req) { // 39
121         print('Icc: rilRequestGetImeisv');
122
123         var rsp = new Object();
124         rsp.strings = new Array();
125         rsp.strings[0] = IMEISV;
126         result.responseProtobuf = rilSchema[packageNameAndSeperator +
127                                  'RspStrings'].serialize(rsp);
128         return result;
129     }
130
131     /**
132      * Process the request
133      */
134     this.process = function(req) {
135         try {
136             // print('Icc E: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
137
138             // Assume the result will be true, successful and nothing to return
139             result.sendResponse = true;
140             result.rilErrCode = RIL_E_SUCCESS;
141             result.responseProtobuf = emptyProtobuf;
142
143             try {
144                 result = (this.simDispatchTable[req.reqNum]).call(this, req);
145             } catch (err) {
146                 print('Icc: Unknown reqNum=' + req.reqNum);
147                 result.rilErrCode = RIL_E_REQUEST_NOT_SUPPORTED;
148             }
149
150             if (result.sendResponse) {
151                 sendRilRequestComplete(result.rilErrCode, req.reqNum,
152                         req.token, result.responseProtobuf);
153             }
154
155             // print('Icc X: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
156         } catch (err) {
157             print('Icc X: Exception req.reqNum=' +
158                     req.reqNum + ' req.token=' + req.token + ' err=' + err);
159         }
160     }
161
162     print('Icc: constructor E');
163     this.simDispatchTable = new Array();
164     this.simDispatchTable[RIL_REQUEST_GET_SIM_STATUS] = this.rilRequestGetSimStatus; // 1
165     this.simDispatchTable[RIL_REQUEST_ENTER_SIM_PIN] = this.rilRequestEnterSimPin; // 2
166     this.simDispatchTable[RIL_REQUEST_GET_IMSI] = this.rilRequestGetImsi; // 11
167     this.simDispatchTable[RIL_REQUEST_OPERATOR] = this.rilRequestOperator; // 22
168     this.simDispatchTable[RIL_REQUEST_GET_IMEI] = this.rilRequestGetImei; // 38
169     this.simDispatchTable[RIL_REQUEST_GET_IMEISV] = this.rilRequestGetImeisv; // 39
170     print('Icc: constructor X');
171 }
172
173 // The simulated sim instance and its associated Worker
174 var simulatedIcc = new Icc();
175 var simulatedIccWorker = new Worker(function (req) {
176     simulatedIcc.process(req);
177 });
178 simulatedIccWorker.run();
179
180 /**
181  * Optional tests
182  */
183 if (false) {
184     include("simulated_icc_tests.js");
185 }