|
1 /* |
|
2 * Copyright (c) 2010 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 * Static utility methods |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32debug.h> |
|
20 #include <centralrepository.h> |
|
21 #include "utils.h" |
|
22 |
|
23 const TInt KCenRepBufferSize = 255; |
|
24 const TText KStrComma = ','; |
|
25 const TUint32 KMenuHideApplication = 0x00000008; |
|
26 |
|
27 // Ovi Store launcher UID |
|
28 const TInt KUidOviStoreLauncher = 0x0; |
|
29 // Ovi Store widget UID |
|
30 const TInt KUidOviStoreWidget = 0x0; |
|
31 // Ovi Store downloader UID |
|
32 const TInt KUidOviStoreDownloader = 0x0; |
|
33 // Ovi Store ASServer UID |
|
34 const TInt KUidOviStoreASServer = 0x0; |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // Check if Ovi Store client is running |
|
38 // @return ETrue, if the process is running |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 TBool CUtils::OviStoreRunning() |
|
42 { |
|
43 TBool running = EFalse; |
|
44 RArray<TInt> uids( 4 ); |
|
45 uids.Append(KUidOviStoreLauncher); |
|
46 uids.Append(KUidOviStoreWidget); |
|
47 uids.Append(KUidOviStoreDownloader); |
|
48 uids.Append(KUidOviStoreASServer); |
|
49 if ( CUtils::AreProcessesRunning(uids) != KErrNotFound ) |
|
50 { |
|
51 running = ETrue; |
|
52 } |
|
53 uids.Close(); |
|
54 return running; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // Checks if the process with given UID is running. |
|
59 // @param aUid UID of the process |
|
60 // @return ETrue, if the process is running |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 TBool CUtils::IsProcessRunning(const TInt aUid) |
|
64 { |
|
65 RArray<TInt> uids; |
|
66 uids.Append(aUid); |
|
67 const TBool ret = (AreProcessesRunning(uids) != KErrNotFound); |
|
68 uids.Close(); |
|
69 return ret; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // @param aUid UID of the process |
|
74 // @return The index of the first matching UIDwithin the array. |
|
75 // KErrNotFound, if no matching entry can be found. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 TInt CUtils::AreProcessesRunning(const RArray<TInt>& aUids) |
|
79 { |
|
80 TInt ret = KErrNotFound; |
|
81 TFileName res; |
|
82 TFindProcess find; |
|
83 //RDebug::Print(_L("Searching. 0x%08x"), &aUids) |
|
84 |
|
85 while (find.Next(res) == KErrNone) |
|
86 { |
|
87 RProcess ph; |
|
88 ph.Open(res); |
|
89 const TInt sid = ph.SecureId(); |
|
90 //RDebug::Print(_L("Scanning process: '%S' (0x%08x)"), &res, sid); |
|
91 |
|
92 if ( (ret = aUids.Find(sid)) != KErrNotFound ) |
|
93 { |
|
94 //RDebug::Print(_L(" Found process: '%S' %d (0x%08x)"), &res, ret, aUids[ret]); |
|
95 ph.Close(); |
|
96 break; |
|
97 } |
|
98 ret = KErrNotFound; |
|
99 /* |
|
100 if (ph.SecureId() == aUid) |
|
101 { |
|
102 RDebug::Print(_L(" Found process: '%S'"), &res); |
|
103 ph.Close(); |
|
104 ret = ETrue; |
|
105 break; |
|
106 } |
|
107 */ |
|
108 ph.Close(); |
|
109 } |
|
110 |
|
111 return ret; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // HideApplicationFromMenu() - Non-leaving version |
|
116 // |
|
117 // @param aUid UID of the application to hide/reveal from the menu |
|
118 // @param aHidden Flag to indicate the application visibility. ETrue = Hide |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CUtils::HideApplicationFromMenu(TInt aUid, TBool aHidden) |
|
122 { |
|
123 TRAPD( ret, HideApplicationFromMenuL(aUid, aHidden) ); |
|
124 return ret; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // HideApplicationFromMenuL() |
|
129 // |
|
130 // @param aUid UID of the application to hide/reveal from the menu |
|
131 // @param aHidden Flag to indicate the application visibility. ETrue = Hide |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CUtils::HideApplicationFromMenuL(TInt aUid, TBool aHidden) |
|
135 { |
|
136 const TUid KCRUidMenu = { 0x0 }; |
|
137 |
|
138 TBuf<KCenRepBufferSize> keyContent; |
|
139 TBool updated( EFalse ); |
|
140 |
|
141 CRepository* aAppShellRepository = CRepository::NewLC( KCRUidMenu ); |
|
142 User::LeaveIfError(aAppShellRepository->Get( KMenuHideApplication, keyContent )); |
|
143 |
|
144 TBuf<8> MenuUid; |
|
145 UIDText( MenuUid, aUid); |
|
146 TInt offset = keyContent.FindC( MenuUid ); |
|
147 if ( offset == KErrNotFound && aHidden ) |
|
148 { |
|
149 __ASSERT_ALWAYS( keyContent.Length() + 9 < KCenRepBufferSize, |
|
150 User::Leave( KErrOverflow ) ); |
|
151 if ( keyContent.Length() > 0 ) |
|
152 keyContent.Append( KStrComma ); |
|
153 keyContent.Append( MenuUid ); |
|
154 updated = ETrue; |
|
155 } |
|
156 else if ( offset != KErrNotFound && !aHidden ) |
|
157 { |
|
158 if ( offset == 0 ) |
|
159 { |
|
160 keyContent.Delete( 0, Min( 9, keyContent.Length() ) ); |
|
161 updated = ETrue; |
|
162 } |
|
163 else if ( keyContent[offset - 1] == KStrComma ) |
|
164 { |
|
165 keyContent.Delete( offset - 1, 9 ); |
|
166 updated = ETrue; |
|
167 } |
|
168 else |
|
169 User::Leave( KErrCorrupt ); |
|
170 } |
|
171 if ( updated ) |
|
172 User::LeaveIfError(aAppShellRepository->Set( KMenuHideApplication, keyContent )); |
|
173 |
|
174 CleanupStack::PopAndDestroy(); // aAppShellRepository |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // UIDText - Converts UID specified by aInt to string representation |
|
179 // |
|
180 // @param aUid Descriptor containing the string |
|
181 // @param aInt Int representing the UID |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CUtils::UIDText(TDes& aUid, TInt aInt) |
|
185 { |
|
186 TUidName uidName( TUid::Uid( aInt ).Name() ); |
|
187 aUid.Copy( uidName.Mid( 1, KMaxUidName - 2 ) ); |
|
188 aUid.UpperCase(); |
|
189 } |