|
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: Haptics uid implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32file.h> |
|
20 #include <f32file.h> |
|
21 #include <pathinfo.h> |
|
22 #include "hwrmhapticsuid.h" |
|
23 #include "hwrmhapticstrace.h" |
|
24 |
|
25 //drive char and colon string length, e.g. "c:" |
|
26 const TInt KDriveAndColon = 2; |
|
27 |
|
28 // Maximum uid file line length |
|
29 const TInt KMaxLineLength( 100 ); |
|
30 |
|
31 // New line character used to terminate each line in uid file |
|
32 const TInt KNewLine( '\n' ); |
|
33 |
|
34 |
|
35 // format specifier used to match valid UIDs |
|
36 _LIT8( KMatchUid, "0x????????" ); |
|
37 |
|
38 // format specifier used to match valid enabled sign |
|
39 _LIT8( KMatchPlusSign, "+" ); |
|
40 |
|
41 // valid vendor id definition |
|
42 _LIT8( KVid, "VID" ); |
|
43 |
|
44 // valid secure id definition |
|
45 _LIT8( KSid, "SID" ); |
|
46 |
|
47 |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // C++ constructor |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 TUidItem::TUidItem( const TDesC8& aUidType, TUid aUid, TBool aAllowed ) |
|
54 : iUidType( aUidType ), iUid( aUid ), iAllowed( aAllowed ) |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Two-phased constructor. |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CHWRMHapticsUid* CHWRMHapticsUid::NewL( const TDesC& aFilename ) |
|
64 { |
|
65 CHWRMHapticsUid* self = NewLC( aFilename ); |
|
66 CleanupStack::Pop( self ); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Two-phased constructor. Leaves instance on the cleanup stack. |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CHWRMHapticsUid* CHWRMHapticsUid::NewLC( const TDesC& aFilename ) |
|
76 { |
|
77 CHWRMHapticsUid* self = new( ELeave ) CHWRMHapticsUid(); |
|
78 |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL( aFilename ); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Destructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CHWRMHapticsUid::~CHWRMHapticsUid() |
|
90 { |
|
91 // Delete all the array objects |
|
92 iUidArray.Close(); |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // C++ constructor |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CHWRMHapticsUid::CHWRMHapticsUid() |
|
101 { |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // By default Symbian 2nd phase constructor is private. |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CHWRMHapticsUid::ConstructL( const TDesC& aFilename ) |
|
109 { |
|
110 RFs fs; |
|
111 User::LeaveIfError( fs.Connect() ); |
|
112 CleanupClosePushL( fs ); |
|
113 |
|
114 // Buffer to store the full path and filename |
|
115 TFileName filename; |
|
116 |
|
117 // Get private file path |
|
118 User::LeaveIfError( fs.PrivatePath( filename ) ); |
|
119 |
|
120 // add the filename to path |
|
121 filename.Insert( 0, PathInfo::RomRootPath().Left( KDriveAndColon ) ); |
|
122 filename.Append( aFilename ); |
|
123 |
|
124 // Parse the file and construct the array of UIDs |
|
125 ParseUidFileL( fs, filename ); |
|
126 |
|
127 CleanupStack::PopAndDestroy( &fs ); |
|
128 } |
|
129 |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // Checks if automated license setting is allowed for VID/SID combination |
|
133 // found from aMessage. If definition for SID is found then VID checking |
|
134 // is omitted. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 TBool CHWRMHapticsUid::LicenseAutoSetAllowed( const RMessage2& aMessage ) |
|
138 { |
|
139 TUid sid = aMessage.SecureId(); |
|
140 TUid vid = aMessage.VendorId(); |
|
141 TBool allowed = EFalse; |
|
142 TBool sidFound = EFalse; |
|
143 |
|
144 for ( TInt n=0; n < iUidArray.Count(); n++ ) |
|
145 { |
|
146 if ( iUidArray[n].iUidType == KSid && |
|
147 sid == iUidArray[n].iUid ) |
|
148 { |
|
149 allowed = iUidArray[n].iAllowed; |
|
150 sidFound = ETrue; |
|
151 } |
|
152 |
|
153 if ( !sidFound && |
|
154 iUidArray[n].iUidType == KVid && |
|
155 vid == iUidArray[n].iUid ) |
|
156 { |
|
157 allowed = iUidArray[n].iAllowed; |
|
158 } |
|
159 } |
|
160 |
|
161 return allowed; |
|
162 } |
|
163 |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // Method constructs the array of UIDs from the given file. |
|
167 // A valid line in the file contains only UID |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CHWRMHapticsUid::ParseUidFileL( RFs& aFs, |
|
171 const TDesC& aFilename ) |
|
172 { |
|
173 TLex8 lex; |
|
174 TPtrC8 sign; |
|
175 TPtrC8 uidType; |
|
176 TPtrC8 id; |
|
177 TUid uid; |
|
178 TInt err( KErrNone ); |
|
179 |
|
180 // Buffer to read each line of the file into |
|
181 TBuf8<KMaxLineLength> fileline; |
|
182 TChar newLine( KNewLine ); |
|
183 RFileReadStream stream; |
|
184 |
|
185 COMPONENT_TRACE( ( _L( "CHWRMHapticsUid::ParseUidFileL - Opening UID file: %S" ), &aFilename ) ); |
|
186 |
|
187 // Open the file and attach to stream |
|
188 err = stream.Open( aFs, aFilename, EFileRead ); |
|
189 |
|
190 // Return without error if file is not found |
|
191 if ( err != KErrNone ) |
|
192 { |
|
193 COMPONENT_TRACE( ( _L( "CHWRMHapticsUid::ParseUidFileL - UID file open failed: %S, error: %d" ), &aFilename, err ) ); |
|
194 } |
|
195 else |
|
196 { |
|
197 CleanupClosePushL( stream ); |
|
198 |
|
199 while( err != KErrEof ) |
|
200 { |
|
201 // read from the file upto the newline character |
|
202 TRAP( err, stream.ReadL( fileline, newLine ) ); |
|
203 |
|
204 lex.Assign( fileline ); |
|
205 sign.Set( lex.NextToken() ); |
|
206 uidType.Set( lex. NextToken() ); |
|
207 id.Set( lex.NextToken() ); |
|
208 TBool allowed = EFalse; |
|
209 if( sign.Match( KMatchPlusSign ) == 0 ) |
|
210 { |
|
211 allowed = ETrue; |
|
212 } |
|
213 if( id.Match( KMatchUid ) == 0 ) |
|
214 { |
|
215 // convert it |
|
216 if( ConvertId( id, uid ) != KErrCorrupt ) |
|
217 { |
|
218 // add UID to array |
|
219 iUidArray.AppendL( TUidItem( uidType, uid, allowed ) ); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 // Close stream |
|
225 CleanupStack::PopAndDestroy( &stream ); |
|
226 } |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Helper method to convert and validate UID from a descriptor |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 TInt CHWRMHapticsUid::ConvertId( const TDesC8& aUidDes, |
|
234 TUid& aUid ) const |
|
235 { |
|
236 TInt ret( KErrNone ); |
|
237 TUint32 id; |
|
238 |
|
239 // this is a matching id |
|
240 TLex8 lex( aUidDes.Right( 8 ) ); |
|
241 |
|
242 if( lex.Val( id, EHex ) != KErrNone ) |
|
243 { |
|
244 // Failed to convert to int |
|
245 ret = KErrCorrupt; |
|
246 } |
|
247 else |
|
248 { |
|
249 // conversion ok so set the uid |
|
250 aUid.iUid = id; |
|
251 } |
|
252 |
|
253 return ret; |
|
254 } |
|
255 |
|
256 |
|
257 // End of File |