|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32property.h> |
|
19 |
|
20 #include <QFile> |
|
21 |
|
22 #include "hsrecoverymanager.h" |
|
23 |
|
24 const TInt KPSCategoryUid(0x20022F36); |
|
25 const TInt KPSCrashCountKey(1); |
|
26 const int KCrashCountThreshold(3); |
|
27 const int KResetCrashCountInterval(60000); |
|
28 |
|
29 /*! |
|
30 \class HsRecoveryManager |
|
31 \ingroup group_hsapplication |
|
32 \brief Used during homescreen startup for recovering from possible crash situations. |
|
33 */ |
|
34 |
|
35 /*! |
|
36 Constructs a new recovery manager with the given \a parent item. |
|
37 */ |
|
38 HsRecoveryManager::HsRecoveryManager(QObject *parent) |
|
39 : QObject(parent) |
|
40 { |
|
41 mTimer.setInterval(KResetCrashCountInterval); |
|
42 mTimer.setSingleShot(true); |
|
43 connect(&mTimer, SIGNAL(timeout()), SLOT(resetCrashCount())); |
|
44 } |
|
45 |
|
46 /*! |
|
47 Destructor. |
|
48 */ |
|
49 HsRecoveryManager::~HsRecoveryManager() |
|
50 { |
|
51 } |
|
52 |
|
53 /*! |
|
54 Executes this recovery manager. If crash count exceeds the |
|
55 threshold, the ROM configuration is selected. Otherwise, |
|
56 the existing one is used. |
|
57 */ |
|
58 void HsRecoveryManager::execute() |
|
59 { |
|
60 int count = crashCount(); |
|
61 if (KCrashCountThreshold <= count) { |
|
62 restoreRomDatabase(); |
|
63 resetCrashCount(); |
|
64 return; |
|
65 } |
|
66 if (0 < count) { |
|
67 mTimer.start(); |
|
68 } |
|
69 } |
|
70 |
|
71 /*! |
|
72 Restores the ROM database to c: drive. |
|
73 */ |
|
74 void HsRecoveryManager::restoreRomDatabase() |
|
75 { |
|
76 // If exists, remove the database from c: |
|
77 QFile file("c:/private/20022f35/homescreen.db"); |
|
78 if (file.exists()) { |
|
79 file.remove(); |
|
80 } |
|
81 // Copy the rom database to c: and set permissions. |
|
82 file.setFileName("z:/private/20022f35/homescreen.db"); |
|
83 file.copy("c:/private/20022f35/homescreen.db"); |
|
84 file.setFileName("c:/private/20022f35/homescreen.db"); |
|
85 file.setPermissions(QFile::ReadOwner | QFile::WriteOwner); |
|
86 } |
|
87 |
|
88 /*! |
|
89 Resets the crash count to zero. |
|
90 */ |
|
91 void HsRecoveryManager::resetCrashCount() |
|
92 { |
|
93 RProperty::Set(TUid::Uid(KPSCategoryUid), KPSCrashCountKey, 0); |
|
94 } |
|
95 |
|
96 /*! |
|
97 Returns the current crash count. |
|
98 */ |
|
99 int HsRecoveryManager::crashCount() |
|
100 { |
|
101 TInt count = 0; |
|
102 RProperty::Get(TUid::Uid(KPSCategoryUid), KPSCrashCountKey, count); |
|
103 return count; |
|
104 } |