|
1 /* |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Listens Bluetooth SIM Access Profile (BT SAP) and publishes |
|
15 * text when BT SAP is activated. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <aidevstaplgres.rsg> |
|
21 #include <centralrepository.h> |
|
22 #include <BTSapDomainPSKeys.h> |
|
23 #include <StringLoader.h> |
|
24 #include <featmgr.h> |
|
25 #include "aibtsappublisher.h" |
|
26 #include "aiprioritizer.h" |
|
27 #include "ainwidpriorities.h" |
|
28 |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 CAiBTSAPPublisher::CAiBTSAPPublisher() |
|
33 : CActive( CActive::EPriorityStandard ) |
|
34 { |
|
35 CActiveScheduler::Add( this ); |
|
36 } |
|
37 |
|
38 |
|
39 void CAiBTSAPPublisher::ConstructL() |
|
40 { |
|
41 //if platform doesn't support BTSAP, there is no reason |
|
42 //to create this object. |
|
43 if( !FeatureManager::FeatureSupported( KFeatureIdBtSap ) ) |
|
44 { |
|
45 User::Leave( KErrNotSupported ); |
|
46 } |
|
47 } |
|
48 |
|
49 |
|
50 CAiBTSAPPublisher* CAiBTSAPPublisher::NewL() |
|
51 { |
|
52 CAiBTSAPPublisher* self = new( ELeave ) CAiBTSAPPublisher; |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 CAiBTSAPPublisher::~CAiBTSAPPublisher() |
|
61 { |
|
62 Cancel(); |
|
63 iPubSub.Close(); |
|
64 } |
|
65 |
|
66 |
|
67 void CAiBTSAPPublisher::ResumeL() |
|
68 { |
|
69 Cancel(); |
|
70 |
|
71 iPubSub.Close(); |
|
72 //attach to BTSAP key. |
|
73 User::LeaveIfError( iPubSub.Attach( KPSUidBluetoothSapConnectionState, |
|
74 KBTSapConnectionState ) ); |
|
75 |
|
76 iFirstPublish = ETrue; |
|
77 |
|
78 //subscribe to get notification when key changes. |
|
79 iPubSub.Subscribe( iStatus ); |
|
80 SetActive(); |
|
81 } |
|
82 |
|
83 |
|
84 void CAiBTSAPPublisher::Subscribe( MAiContentObserver& /*aObserver*/, |
|
85 CHsContentPublisher& aExtension, |
|
86 MAiPublishPrioritizer& aPrioritizer, |
|
87 MAiPublisherBroadcaster& aBroadcaster ) |
|
88 { |
|
89 iExtension = &aExtension; |
|
90 iPrioritizer = &aPrioritizer; |
|
91 iBroadcaster = &aBroadcaster; |
|
92 } |
|
93 |
|
94 |
|
95 void CAiBTSAPPublisher::RefreshL( TBool aClean ) |
|
96 { |
|
97 iSuccess = EFalse; |
|
98 |
|
99 if ( iSuspended ) |
|
100 { |
|
101 return; |
|
102 } |
|
103 |
|
104 if( aClean ) |
|
105 { |
|
106 iPrioritizer->TryToCleanL( *iBroadcaster, |
|
107 EAiDeviceStatusContentNetworkIdentity, |
|
108 EAiBTSAP ); |
|
109 } |
|
110 |
|
111 //Get BTSAP state |
|
112 TInt sapState( 0 ); |
|
113 TInt err = RProperty::Get( KPSUidBluetoothSapConnectionState, |
|
114 KBTSapConnectionState, |
|
115 sapState ); |
|
116 |
|
117 //If key is not found, it is treated same way as the BTSAP is not on. |
|
118 if( err == KErrNotFound ) |
|
119 { |
|
120 err = KErrNone; |
|
121 sapState = EBTSapNotConnected; |
|
122 } |
|
123 |
|
124 User::LeaveIfError( err ); |
|
125 |
|
126 if( sapState == EBTSapConnected ) |
|
127 { |
|
128 iPrioritizer->TryToPublishL( *iBroadcaster, |
|
129 EAiDeviceStatusContentNetworkIdentity, |
|
130 R_ACTIVEIDLE_BT_SIM_ACCESS_PROFILE_STRING, |
|
131 EAiBTSAP ); |
|
132 iSuccess = ETrue; |
|
133 } |
|
134 |
|
135 else if( !iFirstPublish ) |
|
136 { |
|
137 //BTSAP is not anymore active, call clean. |
|
138 iPrioritizer->TryToCleanL( *iBroadcaster, |
|
139 EAiDeviceStatusContentNetworkIdentity, |
|
140 EAiBTSAP ); |
|
141 } |
|
142 iFirstPublish = EFalse; |
|
143 } |
|
144 |
|
145 |
|
146 void CAiBTSAPPublisher::RunL() |
|
147 { |
|
148 if( iStatus.Int() == KErrNone ) |
|
149 { |
|
150 //PS key changed, refresh publisher. |
|
151 RefreshL( ETrue ); |
|
152 iPubSub.Subscribe( iStatus ); |
|
153 SetActive(); |
|
154 } |
|
155 } |
|
156 |
|
157 |
|
158 void CAiBTSAPPublisher::DoCancel() |
|
159 { |
|
160 iPubSub.Cancel(); |
|
161 } |
|
162 |
|
163 |
|
164 TInt CAiBTSAPPublisher::RunError( TInt /*aError*/ ) |
|
165 { |
|
166 iPubSub.Cancel(); |
|
167 //failed to publish, lets however ignore it |
|
168 return KErrNone; |
|
169 } |
|
170 |
|
171 |
|
172 TBool CAiBTSAPPublisher::RefreshL( TInt aContentId, TBool aClean ) |
|
173 { |
|
174 if ( aContentId == EAiDeviceStatusContentNetworkIdentity ) |
|
175 { |
|
176 iSuspended = EFalse; |
|
177 |
|
178 RefreshL( aClean ); |
|
179 |
|
180 if ( iSuccess ) |
|
181 { |
|
182 return ETrue; |
|
183 } |
|
184 } |
|
185 |
|
186 return EFalse; |
|
187 } |
|
188 |
|
189 TBool CAiBTSAPPublisher::SuspendL( TInt aContentId, TBool /*aClean*/ ) |
|
190 { |
|
191 if ( aContentId == EAiDeviceStatusContentNetworkIdentity ) |
|
192 { |
|
193 iSuspended = ETrue; |
|
194 |
|
195 return ETrue; |
|
196 } |
|
197 |
|
198 return EFalse; |
|
199 } |
|
200 |
|
201 TBool CAiBTSAPPublisher::RefreshContentWithPriorityL( TInt aContentId, |
|
202 TInt aPriority ) |
|
203 { |
|
204 if( aContentId == EAiDeviceStatusContentNetworkIdentity && |
|
205 aPriority == EAiBTSAP ) |
|
206 { |
|
207 RefreshL( EFalse ); |
|
208 if( iSuccess ) |
|
209 { |
|
210 return ETrue; |
|
211 } |
|
212 } |
|
213 return EFalse; |
|
214 } |