|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of background checker |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <FeatureControl.h> |
|
22 #include "iaupdatebgrefreshtimer.h" |
|
23 #include "iaupdatebgcontrollerfile.h" |
|
24 #include "iaupdatebgsoftnotification.h" |
|
25 #include "iaupdatebglogger.h" |
|
26 // LOCAL FUNCTION PROTOTYPES |
|
27 LOCAL_C TInt ThreadStartL(); |
|
28 LOCAL_C TBool IAUpdateEnabledL(); |
|
29 LOCAL_C void RemoveExistingSoftNotificationL(); |
|
30 |
|
31 //Const |
|
32 _LIT( KBackgroundChecker, "iaupdatebgchecker" ); |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // E32Main() |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 GLDEF_C TInt E32Main() |
|
39 { |
|
40 __UHEAP_MARK; |
|
41 FLOG("[bgchecker] E32Main() begin"); |
|
42 if ( User::TrapHandler() != NULL ) |
|
43 { |
|
44 User::SetTrapHandler( NULL ); |
|
45 } |
|
46 |
|
47 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
48 if ( !cleanup ) |
|
49 { |
|
50 return KErrNone; |
|
51 } |
|
52 |
|
53 TRAPD( err, ThreadStartL() ); |
|
54 ( void ) err; |
|
55 |
|
56 delete cleanup; |
|
57 FLOG("[bgchecker] E32Main() end"); |
|
58 __UHEAP_MARKEND; |
|
59 |
|
60 return err; |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // ThreadStartL() |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 LOCAL_C TInt ThreadStartL() |
|
69 { |
|
70 if ( !IAUpdateEnabledL() ) |
|
71 { |
|
72 FLOG("[bgchecker] ThreadStartL() IAUpdate not enabled"); |
|
73 RemoveExistingSoftNotificationL(); |
|
74 return KErrNone; |
|
75 } |
|
76 TFullName name; |
|
77 TFindProcess iaupdatebgFinder(_L("*iaupdatebgchecker*")); |
|
78 |
|
79 if (iaupdatebgFinder.Next(name) == KErrNone ) |
|
80 { |
|
81 FLOG("[bgchecker] Process already exists"); |
|
82 User::LeaveIfError( KErrAlreadyExists ); |
|
83 } |
|
84 |
|
85 RProcess::Rendezvous( KErrNone ); |
|
86 |
|
87 User::LeaveIfError( User::RenameProcess( KBackgroundChecker ) ); |
|
88 |
|
89 CActiveScheduler *threadScheduler = new CActiveScheduler; |
|
90 |
|
91 CleanupStack::PushL( threadScheduler ); |
|
92 |
|
93 CActiveScheduler::Install( threadScheduler ); |
|
94 |
|
95 FLOG("[bgchecker] launch background checker"); |
|
96 |
|
97 CIAUpdateBGTimer* timer = CIAUpdateBGTimer::NewL(); |
|
98 |
|
99 CleanupStack::PushL( timer ); |
|
100 |
|
101 timer->StartProcessL(); |
|
102 |
|
103 FLOG("[bgchecker] background checker is started"); |
|
104 |
|
105 CActiveScheduler::Start(); |
|
106 |
|
107 CleanupStack::PopAndDestroy( 2 ); |
|
108 |
|
109 return KErrNone; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // IAUpdateEnabledL() |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 LOCAL_C TBool IAUpdateEnabledL() |
|
117 { |
|
118 FLOG("[bgchecker] IAUpdateEnabledL() begin"); |
|
119 TBool enabled = EFalse; |
|
120 RFeatureControl featureControl; |
|
121 TInt error( KErrNone ); |
|
122 |
|
123 error = featureControl.Connect(); |
|
124 FLOG_NUM("[bgchecker] IAUpdateEnabledL() Connection to the Feature Manager Server: %d", error ); |
|
125 |
|
126 User::LeaveIfError( error ); |
|
127 |
|
128 TUid iaupdatefeature; |
|
129 iaupdatefeature.iUid = KFeatureIdIAUpdate; |
|
130 |
|
131 TInt ret = featureControl.FeatureSupported( iaupdatefeature ); |
|
132 if ( ret == KFeatureSupported ) |
|
133 { |
|
134 enabled = ETrue; |
|
135 } |
|
136 featureControl.Close(); |
|
137 FLOG_NUM("[bgchecker] IAUpdateEnabledL() enabled: %d", enabled ); |
|
138 return enabled; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // RemoveExistingSoftNotificationL() |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 LOCAL_C void RemoveExistingSoftNotificationL() |
|
146 { |
|
147 FLOG("[bgchecker] RemoveExistingSoftNotificationL() begin"); |
|
148 |
|
149 CIAUpdateBGInternalFileHandler* internalFile = CIAUpdateBGInternalFileHandler::NewLC(); |
|
150 CIAUpdateBGSoftNotification* softNotification = CIAUpdateBGSoftNotification::NewL( NULL, internalFile ); |
|
151 CleanupStack::PushL( softNotification ); |
|
152 softNotification->RemoveSoftNotificationL( softNotification->Id() ); |
|
153 CleanupStack::PopAndDestroy( softNotification ); |
|
154 CleanupStack::PopAndDestroy( internalFile ); |
|
155 |
|
156 FLOG("[bgchecker] RemoveExistingSoftNotificationL() end"); |
|
157 return; |
|
158 } |
|
159 |
|
160 //EOF |
|
161 |