1 /* |
|
2 * Copyright (c) 2008 - 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: Java platform 2.0 cleaner process (javacleaner.exe) |
|
15 * When OMJ is uninstalled, this program is executed to |
|
16 * uninstall all OMJ midlets, unregister OMJ |
|
17 * specific MIDlet starter and reregister old starter |
|
18 */ |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32base.h> |
|
23 #include <apgcli.h> // for RApaLsSession |
|
24 #include <e32property.h> |
|
25 #include <swinstallerinternalpskeys.h> |
|
26 |
|
27 #include "javauids.h" |
|
28 #include "logger.h" |
|
29 |
|
30 |
|
31 /** |
|
32 * Start Java Installer process with commandline options |
|
33 * that ask it to uninstall all OMJ midlets. Wait until |
|
34 * the uninstallation has been done. |
|
35 */ |
|
36 static void UninstallAllOmjMidlets() |
|
37 { |
|
38 LOG(EJavaConverters, EInfo, "javacleaner: UninstallAllOmjMidlets: Going to start installer"); |
|
39 |
|
40 RProcess rJavaInstaller; |
|
41 // Just command 'uninstallall', 256 is more than enough |
|
42 TBuf<256> commandLine; |
|
43 |
|
44 // Build command line used to pass all necessary info to Java Installer |
|
45 commandLine = _L("javainstallerstarter"); |
|
46 commandLine.Append(_L(" uninstallall -forceuninstall -captainmsgs=no")); |
|
47 |
|
48 // Run installer silently |
|
49 commandLine.Append(_L(" -silent -skipotastatus")); |
|
50 |
|
51 // start JavaInstaller |
|
52 #ifdef RD_JAVA_S60_RELEASE_5_0_IAD |
|
53 TBuf<128> processName = _L("j9midps60"); |
|
54 #else // RD_JAVA_S60_RELEASE_5_0_IAD |
|
55 TBuf<128> processName = _L("javamidp"); |
|
56 #endif // RD_JAVA_S60_RELEASE_5_0_IAD |
|
57 |
|
58 TInt err = rJavaInstaller.Create(processName, commandLine); |
|
59 if (KErrNone == err) |
|
60 { |
|
61 LOG(EJavaConverters, EInfo, "javacleaner: UninstallAllOmjMidlets calling Rendezvous"); |
|
62 // This call will wait until Java Installer exits (or panics) |
|
63 TRequestStatus status; |
|
64 rJavaInstaller.Logon(status); |
|
65 |
|
66 LOG(EJavaConverters, EInfo, "javacleaner: UninstallAllOmjMidlets calling Resume"); |
|
67 rJavaInstaller.Resume(); |
|
68 |
|
69 // now wait until Java Installer exits |
|
70 User::WaitForRequest(status); |
|
71 if (status.Int() != KErrNone) |
|
72 { |
|
73 ELOG1(EJavaConverters, |
|
74 "javacleaner: UninstallAllOmjMidlets Installer exited with error %d", |
|
75 status.Int()); |
|
76 } |
|
77 } |
|
78 else |
|
79 { |
|
80 ELOG1(EJavaConverters, |
|
81 "javacleaner: UninstallAllOmjMidlets Cannot start Installer, error %d", err); |
|
82 } |
|
83 |
|
84 LOG(EJavaConverters, EInfo, "javacleaner: UninstallAllOmjMidlets calling RProcess::Close"); |
|
85 // free resources before returning |
|
86 rJavaInstaller.Close(); |
|
87 } |
|
88 |
|
89 |
|
90 /** |
|
91 * Start Java Installer process with commandline option |
|
92 * that asks it to delete all PS keys that Java Installer uses and |
|
93 * remove all unnecessary directories that OMJ has created. |
|
94 * Wait until the uninstallation has been done. |
|
95 */ |
|
96 static void CleanOmjDataAndPsKeys() |
|
97 { |
|
98 LOG(EJavaConverters, EInfo, "javacleaner: CleanOmjDataAndPsKeys: Going to start installer"); |
|
99 |
|
100 RProcess rJavaInstaller; |
|
101 // Just command 'removealldata', 256 is more than enough |
|
102 TBuf<256> commandLine; |
|
103 |
|
104 // Build command line used to pass all necessary info to Java Installer |
|
105 commandLine = _L("javainstallerstarter"); |
|
106 commandLine.Append(_L(" removealldata")); |
|
107 |
|
108 // Run installer silently |
|
109 commandLine.Append(_L(" -silent")); |
|
110 |
|
111 // start JavaInstaller |
|
112 #ifdef RD_JAVA_S60_RELEASE_5_0_IAD |
|
113 TBuf<128> processName = _L("j9midps60"); |
|
114 #else // RD_JAVA_S60_RELEASE_5_0_IAD |
|
115 TBuf<128> processName = _L("javamidp"); |
|
116 #endif // RD_JAVA_S60_RELEASE_5_0_IAD |
|
117 |
|
118 TInt err = rJavaInstaller.Create(processName, commandLine); |
|
119 if (KErrNone == err) |
|
120 { |
|
121 LOG(EJavaConverters, EInfo, "javacleaner: CleanOmjDataAndPsKeys calling Rendezvous"); |
|
122 // This call will wait until Java Installer exits (or panics) |
|
123 TRequestStatus status; |
|
124 rJavaInstaller.Logon(status); |
|
125 |
|
126 LOG(EJavaConverters, EInfo, "javacleaner: CleanOmjDataAndPsKeys calling Resume"); |
|
127 rJavaInstaller.Resume(); |
|
128 |
|
129 // now wait until Java Installer exits |
|
130 User::WaitForRequest(status); |
|
131 if (status.Int() != KErrNone) |
|
132 { |
|
133 ELOG1(EJavaConverters, |
|
134 "javacleaner: CleanOmjDataAndPsKeys Installer exited with error %d", |
|
135 status.Int()); |
|
136 } |
|
137 } |
|
138 else |
|
139 { |
|
140 ELOG1(EJavaConverters, |
|
141 "javacleaner: CleanOmjDataAndPsKeys Cannot start Installer, error %d", err); |
|
142 } |
|
143 |
|
144 LOG(EJavaConverters, EInfo, "javacleaner: CleanOmjDataAndPsKeys calling RProcess::Close"); |
|
145 // free resources before returning |
|
146 rJavaInstaller.Close(); |
|
147 } |
|
148 |
|
149 /** |
|
150 * Return true if really uninstalling OMJ |
|
151 */ |
|
152 static TBool IsCleaningNeeded() |
|
153 { |
|
154 TBool clean(EFalse); |
|
155 TInt value(0); |
|
156 // Ignore errors, if the value cannot be read, cleaning is not done. |
|
157 RProperty::Get(KPSUidSWInstallerUiNotification, KSWInstallerUninstallation, value); |
|
158 if (0 == value) |
|
159 { |
|
160 // Native installer is updating OMJ. Do not clean |
|
161 LOG(EJavaConverters, EInfo, |
|
162 "javacleaner: IsCleaningNeeded(): Updating OMJ. No cleaning needed."); |
|
163 clean = EFalse; |
|
164 } |
|
165 else |
|
166 { |
|
167 // Really uninstalling OMJ |
|
168 clean = ETrue; |
|
169 } |
|
170 |
|
171 return clean; |
|
172 } |
|
173 |
|
174 /** |
|
175 * Create cleanup stack and run the cleaner code inside TRAP harness |
|
176 * to log unexpected leaves. |
|
177 */ |
|
178 TInt E32Main() |
|
179 { |
|
180 __UHEAP_MARK; |
|
181 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
182 |
|
183 if (IsCleaningNeeded()) |
|
184 { |
|
185 UninstallAllOmjMidlets(); |
|
186 // Must wait for a moment so that the Java Installer instance |
|
187 // started by previous call exits fully |
|
188 User::After(500000); |
|
189 CleanOmjDataAndPsKeys(); |
|
190 } |
|
191 |
|
192 delete cleanupStack; |
|
193 __UHEAP_MARKEND; |
|
194 return KErrNone; |
|
195 } |
|
196 // eof |
|