25a619e5f1b448863f6a27dd4d273e8830034d13
[platform/framework/native/telephony.git] / src / FTelSimInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FTelSimInfo.cpp
19  * @brief       This is the implementation file for SimInfo class.
20  */
21
22 #include <FTelSimInfo.h>
23 #include <FBaseSysLog.h>
24 #include <FSec_AccessController.h>
25 #include "FTel_SimInfoImpl.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Security;
29
30 namespace Tizen { namespace Telephony
31 {
32 SimInfo::SimInfo(void)
33         : __pSimInfoImpl(null)
34 {
35 }
36
37 SimInfo::~SimInfo(void)
38 {
39         delete __pSimInfoImpl;
40 }
41
42 result
43 SimInfo::Construct(void)
44 {
45         SysAssertf(__pSimInfoImpl == null,
46                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
47
48         result r = E_SUCCESS;
49
50         __pSimInfoImpl = new (std::nothrow)_SimInfoImpl();
51         SysTryReturnResult(NID_TEL, __pSimInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
52
53         r = __pSimInfoImpl->Construct();
54
55         if (r != E_SUCCESS)
56         {
57                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
58                 delete __pSimInfoImpl;
59                 __pSimInfoImpl = null;
60         }
61
62         return r;
63 }
64
65 int
66 SimInfo::GetMnc(void) const
67 {
68         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
69
70         ClearLastResult();
71
72         int mnc = -1;
73         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
74
75         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, E_PRIVILEGE_DENIED,
76                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
77
78         mnc = __pSimInfoImpl->GetMnc();
79
80         r = GetLastResult();
81
82         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, r, "[%s] Propagating.", GetErrorMessage(r));
83
84         return mnc;
85 }
86
87 int
88 SimInfo::GetMcc(void) const
89 {
90         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
91
92         ClearLastResult();
93
94         int mcc = -1;
95         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
96
97         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, E_PRIVILEGE_DENIED,
98                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
99
100         mcc = __pSimInfoImpl->GetMcc();
101
102         r = GetLastResult();
103
104         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, r, "[%s] Propagating.", GetErrorMessage(r));
105
106         return mcc;
107 }
108
109 String
110 SimInfo::GetSpn(void) const
111 {
112         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
113
114         ClearLastResult();
115
116         String spn;
117         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
118
119         SysTryReturn(NID_TEL, r == E_SUCCESS, spn, E_PRIVILEGE_DENIED,
120                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
121
122         spn = __pSimInfoImpl->GetSpn();
123
124         r = GetLastResult();
125
126         SysTryReturn(NID_TEL, r == E_SUCCESS, spn, r, "[%s] Propagating.", GetErrorMessage(r));
127
128         return spn;
129 }
130
131 String
132 SimInfo::GetIccId(void) const
133 {
134         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
135
136         ClearLastResult();
137
138         String iccId;
139         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
140
141         SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, E_PRIVILEGE_DENIED,
142                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
143
144         iccId = __pSimInfoImpl->GetIccId();
145
146         r = GetLastResult();
147
148         SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, r, "[%s] Propagating.", GetErrorMessage(r));
149
150         return iccId;
151 }
152
153 String
154 SimInfo::GetOperatorName(void) const
155 {
156         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
157
158         ClearLastResult();
159
160         String operatorName;
161         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
162
163         SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, E_PRIVILEGE_DENIED,
164                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
165
166         operatorName = __pSimInfoImpl->GetOperatorName();
167
168         r = GetLastResult();
169
170         SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, r, "[%s] Propagating.", GetErrorMessage(r));
171
172         return operatorName;
173 }
174
175 String
176 SimInfo::GetPhoneNumber(void) const
177 {
178         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
179
180         ClearLastResult();
181
182         String phoneNumber;
183         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
184
185         SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, E_PRIVILEGE_DENIED,
186                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
187
188         phoneNumber = __pSimInfoImpl->GetPhoneNumber();
189
190         r = GetLastResult();
191
192         SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, r, "[%s] Propagating.", GetErrorMessage(r));
193
194         return phoneNumber;
195 }
196
197 String
198 SimInfo::GetImsi(void) const
199 {
200         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
201
202         ClearLastResult();
203
204         String imsi;
205
206         imsi = __pSimInfoImpl->GetImsi();
207
208         result r = GetLastResult();
209
210         if (r == E_PRIVILEGE_DENIED)
211         {
212                 SysLogException(NID_TEL, E_PRIVILEGE_DENIED,"[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
213         }
214         else if(r != E_SUCCESS)
215         {
216                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
217         }
218
219         return imsi;
220 }
221
222 bool
223 SimInfo::IsAvailable(void) const
224 {
225         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
226
227         ClearLastResult();
228
229         bool isAvailable = false;
230         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO);
231
232         SysTryReturn(NID_TEL, r == E_SUCCESS, isAvailable, E_PRIVILEGE_DENIED,
233                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
234
235         isAvailable = __pSimInfoImpl->IsAvailable();
236
237         return isAvailable;
238 }
239
240 } } // Tizen::Telephony