|
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: OMJ S60 preinstaller process |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include <e32property.h> |
|
23 #include <javadomainpskeys.h> |
|
24 |
|
25 #include "javauids.h" |
|
26 #include "javaoslayer.h" |
|
27 #include "javasymbianoslayer.h" |
|
28 #include "silentmidletinstall.h" |
|
29 #include "logger.h" |
|
30 |
|
31 using namespace java::util; |
|
32 |
|
33 |
|
34 _LIT_SECURE_ID(KJavaCaptainSecureID, KJavaCaptainUid); |
|
35 |
|
36 // This file is used to indicate when converting old S60 midlets |
|
37 // to OMJ midlets has been done. |
|
38 _LIT(KConversionOngoing, "D:\\OMJConverting.dat"); |
|
39 |
|
40 |
|
41 /** |
|
42 * The PS keys can be created from this process because javapreinstaller |
|
43 * has the same Symbian secure ID as javainstaller and so javainstaller |
|
44 * can later destroy the keys if necessary. |
|
45 */ |
|
46 static void CreateJavaInstallerPSKeys() |
|
47 { |
|
48 LOG(EJavaPreinstaller, EInfo, |
|
49 "CreateJavaInstallerPSKeys: Going to create Java Installer PS keys"); |
|
50 |
|
51 // any process can read the values of the PS keys |
|
52 _LIT_SECURITY_POLICY_PASS(KReadPolicy); |
|
53 // update allowed by processes with write system data capability |
|
54 _LIT_SECURITY_POLICY_C1(KWritePolicy, ECapabilityWriteDeviceData); |
|
55 |
|
56 TInt err = RProperty::Define(KUidSystemCategory, KPSUidJavaLatestInstallation, |
|
57 RProperty::EInt, KReadPolicy, KWritePolicy); |
|
58 if (KErrAlreadyExists == err) |
|
59 { |
|
60 err = KErrNone; // Ignore KErrAlreadyExists status. |
|
61 } |
|
62 if (err != KErrNone) |
|
63 { |
|
64 ELOG1(EJavaPreinstaller, "CreateJavaInstallerPSKeys: " |
|
65 "creating KPSUidJavaLatestInstallation failed with error %d", err); |
|
66 } |
|
67 |
|
68 err = RProperty::Define(KUidSystemCategory, KPSUidJavaLatestInstallationProgress, |
|
69 RProperty::EInt, KReadPolicy, KWritePolicy); |
|
70 if (KErrAlreadyExists == err) |
|
71 { |
|
72 err = KErrNone; // Ignore KErrAlreadyExists status. |
|
73 } |
|
74 if (err != KErrNone) |
|
75 { |
|
76 ELOG1(EJavaPreinstaller, "CreateJavaInstallerPSKeys: " |
|
77 "creating KPSUidJavaLatestInstallationProgress failed with error %d", err); |
|
78 } |
|
79 |
|
80 err = RProperty::Define(KUidSystemCategory, KPSUidJavaLatestInstallationState, |
|
81 RProperty::EInt, KReadPolicy, KWritePolicy); |
|
82 if (KErrAlreadyExists == err) |
|
83 { |
|
84 err = KErrNone; // Ignore KErrAlreadyExists status. |
|
85 } |
|
86 if (err != KErrNone) |
|
87 { |
|
88 ELOG1(EJavaPreinstaller, "CreateJavaInstallerPSKeys: " |
|
89 "creating KPSUidJavaLatestInstallationState failed with error %d", err); |
|
90 } |
|
91 } |
|
92 |
|
93 /** |
|
94 * Create file server connection, |
|
95 * create active scheduler, |
|
96 * add CSilentMIDletInstall active object to it and start it |
|
97 */ |
|
98 static void startPreinstallationL() |
|
99 { |
|
100 JELOG2(EJavaPreinstaller); |
|
101 |
|
102 CActiveScheduler* as = new(ELeave) CActiveScheduler(); |
|
103 |
|
104 // Install active scheduler |
|
105 CActiveScheduler::Install(as); |
|
106 CleanupStack::PushL(as); |
|
107 |
|
108 RFs fs; |
|
109 User::LeaveIfError(fs.Connect()); |
|
110 CleanupClosePushL(fs); |
|
111 |
|
112 // Setup the MIDlet preinstaller and add it to the active scheduler |
|
113 CSilentMIDletInstall* si = CSilentMIDletInstall::NewLC(fs); |
|
114 |
|
115 LOG(EJavaPreinstaller, EInfo, "startPreinstallationL: Call CSilentMIDletInstall::Start()"); |
|
116 |
|
117 // Initialize the MIDlet preinstaller |
|
118 si->Start(); |
|
119 |
|
120 // Start active scheduler. Preinstallation starts. |
|
121 LOG(EJavaPreinstaller, EInfo, "startPreinstallationL: Starting CActiveScheduler"); |
|
122 CActiveScheduler::Start(); |
|
123 |
|
124 // Now preinstallation has been done |
|
125 LOG(EJavaPreinstaller, EInfo, "startPreinstallationL: Cleaning up"); |
|
126 TInt err = fs.Delete(KConversionOngoing); |
|
127 LOG1(EJavaPreinstaller, |
|
128 EInfo, |
|
129 "startPreinstallationL: Delete flag file returned status code %d", |
|
130 err); |
|
131 |
|
132 CleanupStack::PopAndDestroy(si); |
|
133 CleanupStack::PopAndDestroy(&fs); // close connection to file server |
|
134 CleanupStack::PopAndDestroy(as); |
|
135 } |
|
136 |
|
137 /** |
|
138 * Allow starting process only from Java Captain. |
|
139 * Execute actual preinstaller code in CSilentMIDletInstall. |
|
140 */ |
|
141 void preinstallerMainL() |
|
142 { |
|
143 // The only time that this application should be executed |
|
144 // is when Java Captain calls it. |
|
145 if (User::CreatorSecureId() != KJavaCaptainSecureID) |
|
146 { |
|
147 ELOG(EJavaPreinstaller, |
|
148 "preinstallerMainL: Mismatch in secure ID, only Java Captain can launch this exe."); |
|
149 User::Leave(KErrPermissionDenied); |
|
150 } |
|
151 |
|
152 // Create the PS keys that Java Installer will update already now |
|
153 // so that other processes starting during device boot can start |
|
154 // immediately listening to the keys. |
|
155 CreateJavaInstallerPSKeys(); |
|
156 |
|
157 startPreinstallationL(); |
|
158 } |
|
159 |
|
160 /** |
|
161 * Using this kind of dllMain() allows starting preinstaller from |
|
162 * the same starter process as installer and runtime (so that they have the same |
|
163 * Symbian secure Uid and can access the same data cage). |
|
164 */ |
|
165 int dllMain(int /*argc*/, char */*argv*/[]) |
|
166 { |
|
167 JELOG(EJavaPreinstaller, "PREINSTALLER main()"); |
|
168 JavaOsLayer::startUpTrace("PREINSTALLER main() start", -1, -1); |
|
169 |
|
170 User::RenameProcess(_L("javapreinstaller")); |
|
171 User::RenameThread(_L("JavaPreinstallerMainThread")); |
|
172 |
|
173 LOG(EJavaPreinstaller, EInfo, "dllMain: Renaming process and thread done"); |
|
174 |
|
175 // Make sure that this thread has always cleanup stack |
|
176 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
177 |
|
178 TRAPD(err, preinstallerMainL()); |
|
179 if (KErrNone != err) |
|
180 { |
|
181 ELOG1(EJavaPreinstaller, "dllMain: preinstallerMainL leaved with error %d", err); |
|
182 } |
|
183 |
|
184 delete cleanupStack; |
|
185 |
|
186 LOG1(EJavaPreinstaller, EInfo, "PREINSTALLER main() exit = %d", err); |
|
187 JavaOsLayer::startUpTrace("PREINSTALLER main() end", -1, -1); |
|
188 return err; |
|
189 } |
|
190 |
|
191 EXPORT_C FuncPtr findDllMethod(const char* funcName) |
|
192 { |
|
193 FuncPtr ptr = 0; |
|
194 if (strcmp(funcName, "dllMain") == 0) |
|
195 { |
|
196 ptr = (FuncPtr)dllMain; |
|
197 } |
|
198 return ptr; |
|
199 } |
|
200 // eof |