|
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 javaappconverter process |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 |
|
23 #include "javauids.h" |
|
24 #include "silentmidletconvert.h" |
|
25 #include "logger.h" |
|
26 |
|
27 _LIT_SECURE_ID(KJavaPostUpdaterSecureID, KJavaPostUpdaterUid); |
|
28 |
|
29 |
|
30 /** |
|
31 * If uids file exists, the old S60 midlets have not yet been |
|
32 * converted for OMJ java environment. |
|
33 */ |
|
34 static TBool isConversionNeeded(RFs& aFs) |
|
35 { |
|
36 TFileName importDataFile(KUidsImportDataFilePathName); |
|
37 importDataFile.Append(KUidsImportDataFileName); |
|
38 |
|
39 TUint attributes; |
|
40 TInt err = aFs.Att(importDataFile, attributes); |
|
41 if (KErrNone != err) |
|
42 { |
|
43 return EFalse; |
|
44 } |
|
45 else |
|
46 { |
|
47 return ETrue; |
|
48 } |
|
49 } |
|
50 |
|
51 |
|
52 /** |
|
53 * Allow starting process only from Java Captain, |
|
54 * allow running only one instance of the process, |
|
55 * create file server connection, |
|
56 * create active scheduler and start it |
|
57 * |
|
58 * @return ETrue if conversion was done |
|
59 */ |
|
60 static TBool convertJavaAppsL() |
|
61 { |
|
62 JELOG2(EJavaConverters); |
|
63 |
|
64 TBool conversionExecuted = EFalse; |
|
65 |
|
66 _LIT(KPreinstallerMatch, "javaappconverter*"); |
|
67 TFindProcess find(KPreinstallerMatch); |
|
68 TFullName ignoreName; |
|
69 find.Next(ignoreName); |
|
70 |
|
71 // Can only have one javaappconverter. If a second is found exit |
|
72 if (find.Next(ignoreName) == KErrNone) |
|
73 { |
|
74 ELOG(EJavaPreinstaller, "javaappconverter.exe already running."); |
|
75 return ETrue; |
|
76 } |
|
77 |
|
78 // The only time that this application should be executed |
|
79 // is when javapostupdater calls it. |
|
80 if (User::CreatorSecureId() != KJavaPostUpdaterSecureID) |
|
81 { |
|
82 ELOG(EJavaConverters, |
|
83 "ConvertJavaAppsL: Mismatch in secure ID, only javapostupdater can launch this exe."); |
|
84 User::Leave(KErrPermissionDenied); |
|
85 } |
|
86 |
|
87 RFs fs; |
|
88 User::LeaveIfError(fs.Connect()); |
|
89 CleanupClosePushL(fs); |
|
90 |
|
91 if (isConversionNeeded(fs)) |
|
92 { |
|
93 CActiveScheduler* as = new(ELeave) CActiveScheduler(); |
|
94 |
|
95 // Install active scheduler |
|
96 CActiveScheduler::Install(as); |
|
97 CleanupStack::PushL(as); |
|
98 |
|
99 // Setup and start the MIDlet conversion |
|
100 CSilentMIDletConvert* si = CSilentMIDletConvert::NewLC(fs); |
|
101 |
|
102 LOG(EJavaConverters, EInfo, "ConvertJavaAppsL: Call CSilentMIDletConvert::Start()"); |
|
103 |
|
104 si->Start(); |
|
105 |
|
106 // Start active scheduler, starts conversion |
|
107 LOG(EJavaConverters, EInfo, "ConvertJavaAppsL: Starting CActiveScheduler"); |
|
108 CActiveScheduler::Start(); |
|
109 |
|
110 LOG(EJavaConverters, EInfo, "ConvertJavaAppsL: Cleaning up"); |
|
111 |
|
112 CleanupStack::PopAndDestroy(si); |
|
113 CleanupStack::PopAndDestroy(as); |
|
114 |
|
115 conversionExecuted = ETrue; |
|
116 } |
|
117 else |
|
118 { |
|
119 LOG(EJavaConverters, EInfo, |
|
120 "ConvertJavaAppsL: Conversion has already been done."); |
|
121 } |
|
122 |
|
123 CleanupStack::PopAndDestroy(&fs); // close connection to file server |
|
124 |
|
125 return conversionExecuted; |
|
126 } |
|
127 |
|
128 |
|
129 /** |
|
130 * Create cleanup stack and run the javaappconverter code inside TRAP harness |
|
131 * to log unexpected leaves. |
|
132 */ |
|
133 TInt E32Main() |
|
134 { |
|
135 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
136 |
|
137 TBool conversionExecuted(EFalse); |
|
138 TRAPD(err, conversionExecuted = convertJavaAppsL()); |
|
139 if (err != KErrNone) |
|
140 { |
|
141 ELOG1(EJavaConverters, "ConvertJavaAppsL:Main error %d", err); |
|
142 } |
|
143 if (!conversionExecuted) |
|
144 { |
|
145 // Use this error code to tell the process that started us, |
|
146 // that we did nothing because conversion was already done. |
|
147 err = KErrAlreadyExists; |
|
148 } |
|
149 |
|
150 delete cleanupStack; |
|
151 return err; |
|
152 } |
|
153 // eof |