1 /* |
|
2 * Copyright (c) 2009-2010 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: Implements geotagging 3AM timer |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hwrmpowerstatesdkpskeys.h> |
|
19 #include "clocationgeotagtimerao.h" |
|
20 #include "locationmanagerdebug.h" |
|
21 |
|
22 //Time at which the geotagging should be triggered( 3.00 AM ) |
|
23 const TInt GEOTAGGING_TIME_IN_HOURS = 3; |
|
24 //Hour specified in minutes |
|
25 const TInt HOUR_VALUE_IN_MINUTES = 60; |
|
26 //Hour specified in seconds |
|
27 const TInt HOUR_VALUE_IN_SECONDS = 3600; |
|
28 |
|
29 // -------------------------------------------------------------------------- |
|
30 // CLocationGeoTagTimerAO::CLocationGeoTagTimerAO |
|
31 // -------------------------------------------------------------------------- |
|
32 // |
|
33 CLocationGeoTagTimerAO::CLocationGeoTagTimerAO(CMdESession& aMdeSession, |
|
34 MGeoTaggerObserver& aObserver): |
|
35 CTimer( EPriorityLow ), |
|
36 iGeoTagger(NULL), |
|
37 iMdeSession(aMdeSession), |
|
38 iObserver(aObserver) |
|
39 { |
|
40 |
|
41 } |
|
42 |
|
43 // -------------------------------------------------------------------------- |
|
44 // CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO |
|
45 // -------------------------------------------------------------------------- |
|
46 // |
|
47 CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO() |
|
48 { |
|
49 LOG ("CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO(), begin"); |
|
50 if(iGeoTagger) |
|
51 { |
|
52 delete iGeoTagger; |
|
53 iGeoTagger = NULL; |
|
54 } |
|
55 LOG ("CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO(), end"); |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CLocationGeoTagTimerAO::NewL |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CLocationGeoTagTimerAO* CLocationGeoTagTimerAO::NewL(CMdESession& aMdeSession, |
|
63 MGeoTaggerObserver& aObserver) |
|
64 { |
|
65 CLocationGeoTagTimerAO* self = |
|
66 new( ELeave ) CLocationGeoTagTimerAO(aMdeSession, aObserver); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop(); //self |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // CLocationGeoTagTimerAO::ConstructL |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 void CLocationGeoTagTimerAO::ConstructL() |
|
80 { |
|
81 LOG ("CLocationGeoTagTimerAO::ConstructL(), begin"); |
|
82 CActiveScheduler::Add(this); |
|
83 CTimer::ConstructL(); |
|
84 LOG ("CLocationGeoTagTimerAO::ConstructL(), end"); |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CLocationGeoTagTimerAO::StartTimer |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 void CLocationGeoTagTimerAO::StartTimer() |
|
92 { |
|
93 LOG ("CLocationGeoTagTimerAO::StartTimer(), begin"); |
|
94 if(!IsActive()) |
|
95 { |
|
96 TTime hometime; |
|
97 hometime.HomeTime(); |
|
98 |
|
99 //Get the current time in Hour,Minute, Second |
|
100 TDateTime currentDateTime = hometime.DateTime(); |
|
101 TInt currentHr = currentDateTime.Hour(); |
|
102 TInt currentMin = currentDateTime.Minute(); |
|
103 TInt currentSec = currentDateTime.Second(); |
|
104 |
|
105 //3 AM in seconds |
|
106 TInt targetTimeInSeconds = GEOTAGGING_TIME_IN_HOURS * HOUR_VALUE_IN_SECONDS; |
|
107 TInt timeDifference = 0; |
|
108 |
|
109 //Find the time difference in seconds between current time to 3.00 AM |
|
110 //Either on same day or next day. |
|
111 if ( currentHr < GEOTAGGING_TIME_IN_HOURS ) |
|
112 { |
|
113 timeDifference = targetTimeInSeconds - |
|
114 ( ( currentHr * HOUR_VALUE_IN_SECONDS ) + ( currentMin * HOUR_VALUE_IN_MINUTES ) + currentSec ); |
|
115 } |
|
116 else |
|
117 { |
|
118 timeDifference = ( 24 * HOUR_VALUE_IN_SECONDS - ( |
|
119 ( currentHr * HOUR_VALUE_IN_SECONDS ) + ( currentMin * HOUR_VALUE_IN_MINUTES ) + currentSec ) ) + |
|
120 targetTimeInSeconds ; |
|
121 } |
|
122 |
|
123 //Add the time difference to current time to set the target time ( 3.00 AM ) |
|
124 TTimeIntervalSeconds interval( timeDifference ); |
|
125 TTime timeToSet; |
|
126 timeToSet.HomeTime(); |
|
127 timeToSet+= interval; |
|
128 |
|
129 |
|
130 At( timeToSet ); |
|
131 } |
|
132 LOG ("CLocationGeoTagTimerAO::StartTimer(), end"); |
|
133 } |
|
134 |
|
135 |
|
136 // -------------------------------------------------------------------------- |
|
137 // CLocationGeoTagTimerAO::RunL |
|
138 // -------------------------------------------------------------------------- |
|
139 // |
|
140 void CLocationGeoTagTimerAO::RunL( ) |
|
141 { |
|
142 LOG ("CLocationGeoTagTimerAO::RunL(), begin"); |
|
143 TInt status = iStatus.Int(); |
|
144 LOG1 ("Timedout error - %d", status); |
|
145 |
|
146 switch( status ) |
|
147 { |
|
148 case KErrNone: |
|
149 { |
|
150 // If battery is low, skip geotagging in the background |
|
151 // to save power especially if there is a lot of images |
|
152 // to be handled |
|
153 if( IsLowBattery() ) |
|
154 { |
|
155 StartTimer(); |
|
156 break; |
|
157 } |
|
158 //Trigger the reverse geocoding and start the timer again |
|
159 //Create the instance of geotagger class |
|
160 if(iGeoTagger != NULL) |
|
161 { |
|
162 delete iGeoTagger; |
|
163 iGeoTagger = NULL; |
|
164 } |
|
165 iGeoTagger = CGeoTagger::NewL( this, NULL ); |
|
166 iGeoTagger->CreateGeoTagsL(); |
|
167 LOG ("Started 3:00 AM geotagging."); |
|
168 break; |
|
169 } |
|
170 default: |
|
171 StartTimer(); |
|
172 break; |
|
173 } |
|
174 LOG ("CLocationGeoTagTimerAO::RunL(), end"); |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CLocationGeoTagTimerAO::GeoTaggingCompleted |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 void CLocationGeoTagTimerAO::GeoTaggingCompleted( const TInt aError ) |
|
182 { |
|
183 LOG ("CLocationGeoTagTimerAO::GeoTaggingCompleted(), begin"); |
|
184 StartTimer(); |
|
185 iObserver.GeoTaggingCompleted(aError); |
|
186 LOG ("CLocationGeoTagTimerAO::GeoTaggingCompleted(), end"); |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // CLocationGeoTagTimerAO::PendingGeoTagReqComplete |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 void CLocationGeoTagTimerAO::PendingGeoTagReqComplete( const TInt aError ) |
|
194 { |
|
195 LOG ("CLocationGeoTagTimerAO::PendingGeoTagReqComplete()"); |
|
196 // do nothing. |
|
197 iObserver.PendingGeoTagReqComplete(aError); |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // CLocationGeoTagTimerAO::GetCurrentRegisterNw() |
|
202 // ---------------------------------------------------------------------------- |
|
203 RMobilePhone::TMobilePhoneNetworkInfoV2& CLocationGeoTagTimerAO::GetCurrentRegisterNw() |
|
204 { |
|
205 LOG( "CLocationGeoTagTimerAO::GetCurrentRegisterNw ,begin" ); |
|
206 return iObserver.GetCurrentRegisterNw(); |
|
207 } |
|
208 |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // CLocationGeoTagTimerAO::IsRegisteredAtHomeNetwork() |
|
212 // ---------------------------------------------------------------------------- |
|
213 TBool CLocationGeoTagTimerAO::IsRegisteredAtHomeNetwork() |
|
214 { |
|
215 LOG( "CLocationGeoTagTimerAO::IsRegisteredAtHomeNetwork" ); |
|
216 return iObserver.IsRegisteredAtHomeNetwork(); |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // CLocationGeoTagTimerAO::GetHomeNetworkInfo() |
|
221 // ---------------------------------------------------------------------------- |
|
222 const RMobilePhone::TMobilePhoneNetworkInfoV1& |
|
223 CLocationGeoTagTimerAO::GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag) |
|
224 { |
|
225 LOG( "CLocationGeoTagTimerAO::GetHomeNetworkInfo" ); |
|
226 return iObserver.GetHomeNetworkInfo(aHomeNwInfoAvailableFlag); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CLocationGeoTagTimerAO::IsLowBattery() |
|
231 // ---------------------------------------------------------------------------- |
|
232 TBool CLocationGeoTagTimerAO::IsLowBattery() |
|
233 { |
|
234 LOG("CLocationGeoTagTimerAO::IsLowBattery()"); |
|
235 RProperty batteryProperty; |
|
236 TInt batteryStatus; |
|
237 |
|
238 TInt error = batteryProperty.Get(KPSUidHWRMPowerState, KHWRMBatteryStatus, batteryStatus); |
|
239 LOG1("CLocationGeoTagTimerAO::IsLowBattery() - battery status %d", batteryStatus ); |
|
240 if( error != KErrNone || batteryStatus == EBatteryStatusOk ) |
|
241 { |
|
242 return EFalse; |
|
243 } |
|
244 else |
|
245 { |
|
246 return ETrue; |
|
247 } |
|
248 } |
|
249 |
|
250 // End of file |
|
251 |
|