|
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: HtiDeviceReboot implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <hal.h> |
|
22 #include <starterclient.h> |
|
23 #include <syslangutil.h> |
|
24 |
|
25 // CONSTANTS |
|
26 _LIT( KHtiDeviceRebootName, "HtiDeviceReboot" ); |
|
27 _LIT( KParamNormalRfs, "rfsnormal" ); |
|
28 _LIT( KParamDeepRfs, "rfsdeep" ); |
|
29 |
|
30 // MACROS |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 |
|
34 // MODULE DATA STRUCTURES |
|
35 |
|
36 // LOCAL FUNCTION PROTOTYPES |
|
37 LOCAL_C TInt StartL(); |
|
38 LOCAL_C TInt Reboot(); |
|
39 LOCAL_C TInt RestoreFactorySettings( TBool aIsDeepRfs ); |
|
40 |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 |
|
44 // ============================ LOCAL FUNCTIONS =============================== |
|
45 |
|
46 LOCAL_C TInt StartL() |
|
47 { |
|
48 TInt error = KErrNone; |
|
49 |
|
50 TInt cmdLen = User::CommandLineLength(); |
|
51 HBufC* cmdLine = HBufC::NewLC( cmdLen ); |
|
52 TPtr ptCmdLine = cmdLine->Des(); |
|
53 User::CommandLine( ptCmdLine ); |
|
54 |
|
55 if ( cmdLen == 0 ) |
|
56 { |
|
57 error = Reboot(); |
|
58 } |
|
59 |
|
60 else |
|
61 { |
|
62 TLex parser( *cmdLine ); |
|
63 parser.SkipCharacters(); |
|
64 if ( parser.MarkedToken().CompareF( KParamNormalRfs ) == 0 ) |
|
65 { |
|
66 error = RestoreFactorySettings( EFalse ); |
|
67 } |
|
68 else if ( parser.MarkedToken().CompareF( KParamDeepRfs ) == 0 ) |
|
69 { |
|
70 error = RestoreFactorySettings( ETrue ); |
|
71 } |
|
72 else |
|
73 { |
|
74 error = KErrArgument; // Unknown argument |
|
75 } |
|
76 } |
|
77 |
|
78 CleanupStack::PopAndDestroy(); // cmdLine |
|
79 return error; |
|
80 } |
|
81 |
|
82 LOCAL_C TInt Reboot() |
|
83 { |
|
84 RStarterSession session; |
|
85 TInt error = session.Connect(); |
|
86 if ( error == KErrNone ) |
|
87 { |
|
88 session.Reset( RStarterSession::EUnknownReset ); |
|
89 session.Close(); |
|
90 } |
|
91 return error; |
|
92 } |
|
93 |
|
94 LOCAL_C TInt RestoreFactorySettings( TBool aIsDeepRfs ) |
|
95 { |
|
96 // In case of deep rfs, set language to default |
|
97 if ( aIsDeepRfs ) |
|
98 { |
|
99 TInt lang = 0; |
|
100 if ( SysLangUtil::GetDefaultLanguage( lang ) == KErrNone ) |
|
101 { |
|
102 HAL::Set( HALData::ELanguageIndex, lang ); |
|
103 } |
|
104 } |
|
105 |
|
106 // Do reboot with appropriate rfs reason code |
|
107 RStarterSession session; |
|
108 TInt error = session.Connect(); |
|
109 if ( error == KErrNone ) |
|
110 { |
|
111 session.Reset( aIsDeepRfs ? RStarterSession::EDeepRFSReset : |
|
112 RStarterSession::ENormalRFSReset ); |
|
113 session.Close(); |
|
114 } |
|
115 return error; |
|
116 } |
|
117 |
|
118 GLDEF_C TInt E32Main() |
|
119 { |
|
120 __UHEAP_MARK; |
|
121 |
|
122 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
123 CActiveScheduler *scheduler = new(ELeave) CActiveScheduler; |
|
124 CActiveScheduler::Install( scheduler ); |
|
125 |
|
126 User::RenameThread( KHtiDeviceRebootName ); |
|
127 |
|
128 TRAPD( err, StartL() ); |
|
129 |
|
130 delete scheduler; |
|
131 delete cleanup; |
|
132 |
|
133 __UHEAP_MARKEND; |
|
134 |
|
135 return err; |
|
136 } |
|
137 |
|
138 // End of File |