|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ssmsimstatusobserver.h" |
|
17 #include "ssmuiproviderdll.h" |
|
18 #include "ssmdebug.h" |
|
19 #include "startupdomainpskeys.h" |
|
20 #include <ssm/ssmstatemanager.h> |
|
21 |
|
22 #include <e32property.h> |
|
23 #include <ssm/ssmstates.hrh> |
|
24 #include <ssm/startupreason.h> |
|
25 |
|
26 /** |
|
27 * Allocates and returns a new SIM status observer. |
|
28 * |
|
29 * Uses the parameters provided by the SSM UI provider DLL for object construction. |
|
30 * |
|
31 * @publishedPartner |
|
32 * @released |
|
33 */ |
|
34 EXPORT_C MSsmUtility* CSsmSimStatusObserver::NewL() |
|
35 { |
|
36 CSsmSimStatusObserver* self = new (ELeave) CSsmSimStatusObserver(); |
|
37 return static_cast<MSsmUtility*>(self); |
|
38 } |
|
39 |
|
40 /** |
|
41 * Frees any resources allocated to this object. |
|
42 * |
|
43 * @internalComponent |
|
44 */ |
|
45 CSsmSimStatusObserver::~CSsmSimStatusObserver() |
|
46 { |
|
47 Deque(); |
|
48 iSimAdaptation.Close(); |
|
49 iSimStatusProperty.Close(); |
|
50 } |
|
51 |
|
52 /** |
|
53 * Initialises this object |
|
54 * |
|
55 * @internalComponent |
|
56 */ |
|
57 void CSsmSimStatusObserver::InitializeL() |
|
58 { |
|
59 TInt err = iSimAdaptation.Connect(); |
|
60 if(KErrNone != err) |
|
61 { |
|
62 DEBUGPRINT2A("CSsmSimStatusObserver error connecting to SIM adaptation: %d", err); |
|
63 User::Leave(err); |
|
64 } |
|
65 } |
|
66 |
|
67 /** |
|
68 * Starts requesting notification for SIM events. |
|
69 * |
|
70 * @internalComponent |
|
71 */ |
|
72 void CSsmSimStatusObserver::StartL() |
|
73 { |
|
74 iSimAdaptation.NotifySimEvent(iSimEventPckg, iStatus); |
|
75 SetActive(); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Destroys this object and frees any resources |
|
80 * allocated to it. |
|
81 * |
|
82 * @internalComponent |
|
83 */ |
|
84 void CSsmSimStatusObserver::Release() |
|
85 { |
|
86 delete this; |
|
87 } |
|
88 |
|
89 /** |
|
90 * CActive::RunL() implementation |
|
91 * |
|
92 * @internalComponent |
|
93 */ |
|
94 void CSsmSimStatusObserver::RunL() |
|
95 { |
|
96 if(KErrNone != iStatus.Int()) |
|
97 { |
|
98 DEBUGPRINT2A("CSsmSimStatusObserver RunL status error: %d", iStatus.Int()); |
|
99 User::Leave(iStatus.Int()); |
|
100 } |
|
101 // The adaptation will have queued any events, so we shouldn't miss any while we handle this event |
|
102 switch(iSimEventPckg()) |
|
103 { |
|
104 case ESsmSimUsable: |
|
105 RequestSimStatusChangeL(ESimUsable); |
|
106 break; |
|
107 case ESsmSimReadable: |
|
108 RequestSimStatusChangeL(ESimReadable); |
|
109 break; |
|
110 case ESsmSimNotReady: |
|
111 RequestSimStatusChangeL(ESimNotReady); |
|
112 break; |
|
113 case ESsmSimRemoved: |
|
114 RequestSimStatusChangeL(ESimNotPresent); |
|
115 break; |
|
116 default: |
|
117 DEBUGPRINT2A("CSsmSimStatusObserver unknown SIM event: %d", iSimEventPckg()); |
|
118 User::Leave(KErrNotSupported); |
|
119 break; |
|
120 } |
|
121 // Re-request notification |
|
122 iSimAdaptation.NotifySimEvent(iSimEventPckg, iStatus); |
|
123 SetActive(); |
|
124 } |
|
125 |
|
126 /** |
|
127 * Requests a change to the SIM status system wide property. |
|
128 * |
|
129 * @internalComponent |
|
130 */ |
|
131 void CSsmSimStatusObserver::RequestSimStatusChangeL(TPSSimStatus aSimStatus) |
|
132 { |
|
133 DEBUGPRINT2A("CSsmSimStatusObserver SIM status change: %d", aSimStatus); |
|
134 RSsmStateManager ssm; |
|
135 User::LeaveIfError(ssm.Connect()); |
|
136 CleanupClosePushL(ssm); |
|
137 const TUint KStartupSimSecurityStatusKey = {CSsmUiSpecific::SimStatusPropertyKey()}; |
|
138 TSsmSwp swpInfo(KStartupSimSecurityStatusKey, aSimStatus); |
|
139 User::LeaveIfError(ssm.RequestSwpChange(swpInfo)); |
|
140 CleanupStack::PopAndDestroy(&ssm); |
|
141 } |
|
142 |
|
143 /** |
|
144 * Cancels the outstanding notification request for this observer. |
|
145 * |
|
146 * @internalComponent |
|
147 */ |
|
148 void CSsmSimStatusObserver::DoCancel() |
|
149 { |
|
150 iSimAdaptation.NotifyCancel(); |
|
151 } |
|
152 |
|
153 /** |
|
154 * CActive::RunError implementation |
|
155 * |
|
156 * @internalComponent |
|
157 */ |
|
158 TInt CSsmSimStatusObserver::RunError(TInt aError) |
|
159 { |
|
160 DEBUGPRINT2A("CSsmSimStatusObserver RunError received error: %d", aError); |
|
161 return aError; |
|
162 } |
|
163 |
|
164 /** |
|
165 * Constructs this object using the parameters provided by the SSM UI provider DLL. |
|
166 * |
|
167 * @internalComponent |
|
168 */ |
|
169 CSsmSimStatusObserver::CSsmSimStatusObserver() |
|
170 : CActive(EPriorityNormal) |
|
171 { |
|
172 CActiveScheduler::Add(this); |
|
173 } |
|
174 |