javacommons/security/legacysupport/midp2userpreferences/src/MIDP2UserPreferences.cpp
branchRCL_3
changeset 19 04becd199f91
child 47 f40128debb5d
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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:
       
    15 *
       
    16 */
       
    17 #include "javaosheaders.h"
       
    18 #include "javasymbianoslayer.h"
       
    19 #include "javacommonutils.h"
       
    20 #include "s60commonutils.h"
       
    21 #include "UserPreferences.h"
       
    22 #include "UserPreferencesIterator.h"
       
    23 #include "MIDletSuiteUserPreferences.h"
       
    24 #include "MIDletSuiteCustomAttributes.h"
       
    25 #include <MUserSecurityPreferencesTable.h>
       
    26 #include <MSecurityPolicyV2.h>
       
    27 #include "SecurityPreferences.h"
       
    28 #include "javauid.h"
       
    29 
       
    30 using namespace MIDP;
       
    31 using namespace MIDP::DBv2;
       
    32 using namespace java::security::legacysupport;
       
    33 using namespace std;
       
    34 using namespace java::util;
       
    35 
       
    36 EXPORT_C MUserPreferences* GetUserPreferencesL(TUint32 /*aFlags*/,
       
    37         const MSecurityPolicyV2& /*aSecurityPolicy*/)
       
    38 {
       
    39     return CUserPreferences::NewL();
       
    40 }
       
    41 
       
    42 CUserPreferences* CUserPreferences::NewL()
       
    43 {
       
    44     CUserPreferences* self = new(ELeave) CUserPreferences();
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop(self);
       
    48     return self;
       
    49 }
       
    50 
       
    51 CUserPreferences::CUserPreferences()
       
    52 {
       
    53 }
       
    54 
       
    55 void CUserPreferences::ConstructL()
       
    56 {
       
    57 }
       
    58 
       
    59 CUserPreferences::~CUserPreferences()
       
    60 {
       
    61 }
       
    62 
       
    63 MMIDletSuiteUserPreferencesIterator* CUserPreferences::IteratorL()
       
    64 {
       
    65     return CMIDletSuiteUserPreferencesIterator::NewL();
       
    66 }
       
    67 
       
    68 MMIDletSuiteCustomAttributes* CUserPreferences::CustomAttributesL(TUint32 aSuiteId)
       
    69 {
       
    70     return CMIDletSuiteCustomAttributes::NewL(aSuiteId);
       
    71 }
       
    72 
       
    73 MSecurityPreferences* CUserPreferences::SecurityPreferencesL(const MMIDletSuiteInfo& /*aMIDletSuiteInfo*/)
       
    74 {
       
    75     User::Leave(KErrNotSupported);
       
    76     return NULL; // this is here to make the compiler happy (it won't throw a warning)
       
    77 }
       
    78 
       
    79 CMIDletSuiteUserPreferencesIterator* CMIDletSuiteUserPreferencesIterator::NewL()
       
    80 {
       
    81     CMIDletSuiteUserPreferencesIterator* self = new(ELeave) CMIDletSuiteUserPreferencesIterator();
       
    82     CleanupStack::PushL(self);
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop(self);
       
    85     return self;
       
    86 }
       
    87 
       
    88 void CMIDletSuiteUserPreferencesIterator::ConstructL()
       
    89 {
       
    90     StorageUtils* storage = java::security::legacysupport::StorageUtils::NewL();
       
    91     CleanupStack::PushL(storage);
       
    92     storage->readMidletSuitesInfos(iMidletSuites);
       
    93     CleanupStack::PopAndDestroy(storage);
       
    94 }
       
    95 
       
    96 CMIDletSuiteUserPreferencesIterator::CMIDletSuiteUserPreferencesIterator()
       
    97         : iCurrentMidletSuite(0)
       
    98 {
       
    99 }
       
   100 
       
   101 CMIDletSuiteUserPreferencesIterator::~CMIDletSuiteUserPreferencesIterator()
       
   102 {
       
   103 }
       
   104 
       
   105 TBool CMIDletSuiteUserPreferencesIterator::HasNext()
       
   106 {
       
   107     return (iCurrentMidletSuite < iMidletSuites.size());
       
   108 }
       
   109 
       
   110 MMIDletSuiteUserPreferences* CMIDletSuiteUserPreferencesIterator::NextL()
       
   111 {
       
   112     if (iCurrentMidletSuite >= iMidletSuites.size())
       
   113     {
       
   114         User::Leave(KErrNotFound);
       
   115     }
       
   116     CMIDletSuiteUserPreferences* pref = CMIDletSuiteUserPreferences::NewL(
       
   117                                             *(iMidletSuites[iCurrentMidletSuite]));
       
   118     iCurrentMidletSuite++;
       
   119     return pref;
       
   120 }
       
   121 
       
   122 CMIDletSuiteUserPreferences* CMIDletSuiteUserPreferences::NewL(MidletSuiteInfo& aMidletSuiteInfo)
       
   123 {
       
   124     CMIDletSuiteUserPreferences* self = new(ELeave) CMIDletSuiteUserPreferences(aMidletSuiteInfo);
       
   125     CleanupStack::PushL(self);
       
   126     self->ConstructL();
       
   127     CleanupStack::Pop(self);
       
   128     return self;
       
   129 }
       
   130 
       
   131 void CMIDletSuiteUserPreferences::ConstructL()
       
   132 {
       
   133 }
       
   134 
       
   135 CMIDletSuiteUserPreferences::CMIDletSuiteUserPreferences(MidletSuiteInfo& aMidletSuiteInfo)
       
   136         :iMidletSuiteInfo(aMidletSuiteInfo)
       
   137 {
       
   138 }
       
   139 
       
   140 CMIDletSuiteUserPreferences::~CMIDletSuiteUserPreferences()
       
   141 {
       
   142 }
       
   143 
       
   144 TUint32 CMIDletSuiteUserPreferences::Id() const
       
   145 {
       
   146     Uid tmp(iMidletSuiteInfo.iUid);
       
   147     TUid uid;
       
   148     TInt err = uidToTUid(tmp, uid);
       
   149     if (err == KErrNone)
       
   150     {
       
   151         return uid.iUid;
       
   152     }
       
   153     else
       
   154     {
       
   155         return 0;
       
   156     }
       
   157 }
       
   158 
       
   159 TInt CMIDletSuiteUserPreferences::PropertyL(const TDesC& aName, TPtrC& aValue) const
       
   160 {
       
   161     HBufC* desc = NULL;
       
   162     if (aName.Compare(KMidletSuiteName) == 0)
       
   163     {
       
   164         desc = S60CommonUtils::wstringToDes(iMidletSuiteInfo.iName.c_str());
       
   165     }
       
   166     else if (aName.Compare(KMidletSuiteVendor) == 0)
       
   167     {
       
   168         desc = S60CommonUtils::wstringToDes(iMidletSuiteInfo.iVendor.c_str());
       
   169     }
       
   170     else if (aName.Compare(KMidletSuiteVersion) == 0)
       
   171     {
       
   172         desc = S60CommonUtils::wstringToDes(iMidletSuiteInfo.iVersion.c_str());
       
   173     }
       
   174     if (desc != NULL)
       
   175     {
       
   176         aValue.Set(desc->Des());
       
   177         return KErrNone;
       
   178     }
       
   179     return KErrNotFound;
       
   180 }
       
   181 
       
   182 MSecurityPreferences& CMIDletSuiteUserPreferences::SecurityPreferencesL()
       
   183 {
       
   184     User::Leave(KErrNotSupported);
       
   185     return *(reinterpret_cast<MSecurityPreferences*>(new int())); // this is here to make the compiler happy (it won't throw a warning)
       
   186 }
       
   187 
       
   188 
       
   189 CMIDletSuiteCustomAttributes* CMIDletSuiteCustomAttributes::NewL(TUint32 aSuiteId)
       
   190 {
       
   191     CMIDletSuiteCustomAttributes* self = new(ELeave) CMIDletSuiteCustomAttributes(aSuiteId);
       
   192     CleanupStack::PushL(self);
       
   193     self->ConstructL();
       
   194     CleanupStack::Pop(self);
       
   195     return self;
       
   196 }
       
   197 
       
   198 void CMIDletSuiteCustomAttributes::ConstructL()
       
   199 {
       
   200 }
       
   201 
       
   202 CMIDletSuiteCustomAttributes::~CMIDletSuiteCustomAttributes()
       
   203 {
       
   204 }
       
   205 
       
   206 
       
   207 HBufC* CMIDletSuiteCustomAttributes::GetL(const TDesC& aName, TUint32& aFlag)
       
   208 {
       
   209     if (aName.Compare(KOnScreenKeyboardAttribute) != 0)
       
   210     {
       
   211         User::Leave(KErrNotSupported);
       
   212     }
       
   213     TUid suiteId = TUid::Uid(iSuiteId);
       
   214     Uid suiteUid;
       
   215     TUidToUid(suiteId, suiteUid);
       
   216     StorageUtils* storage = java::security::legacysupport::StorageUtils::NewL();
       
   217     CleanupStack::PushL(storage);
       
   218     wstring value = L"";
       
   219     storage->readOnScreenKeyboardAttributeL(suiteUid.toString(), value);
       
   220     CleanupStack::PopAndDestroy(storage);
       
   221     aFlag = KFlagUserModifiable;
       
   222     return mapOnScreenKeyboardToLegacyValueL(value);
       
   223 }
       
   224 
       
   225 void CMIDletSuiteCustomAttributes::AddL(const TDesC& /*aName*/,
       
   226                                         const TDesC& /*aValue*/,
       
   227                                         const TUint32 /*aFlag*/)
       
   228 {
       
   229     User::Leave(KErrNotSupported);
       
   230 }
       
   231 
       
   232 void CMIDletSuiteCustomAttributes::UpdateL(const TDesC& aName,
       
   233         const TDesC& aValue,
       
   234         const TUint32 /*aFlag*/)
       
   235 {
       
   236     if (aName.Compare(KOnScreenKeyboardAttribute) != 0)
       
   237     {
       
   238         User::Leave(KErrNotSupported);
       
   239     }
       
   240     wstring value = L"";
       
   241     mapOnScreenKeyboardToOmjValue(aValue, value);
       
   242     if (value.size() == 0)
       
   243     {
       
   244         return;
       
   245     }
       
   246     TUid suiteId = TUid::Uid(iSuiteId);
       
   247     Uid suiteUid;
       
   248     TUidToUid(suiteId, suiteUid);
       
   249     StorageUtils* storage = java::security::legacysupport::StorageUtils::NewL();
       
   250     CleanupStack::PushL(storage);
       
   251     storage->writeOnScreenKeyboardAttribute(suiteUid.toString(), value);
       
   252     CleanupStack::PopAndDestroy(storage);
       
   253 }
       
   254 
       
   255 void CMIDletSuiteCustomAttributes::RemoveAllL()
       
   256 {
       
   257     User::Leave(KErrNotSupported);
       
   258 }
       
   259 
       
   260 CMIDletSuiteCustomAttributes::CMIDletSuiteCustomAttributes(TUint32 aSuiteId)
       
   261         : iSuiteId(aSuiteId)
       
   262 {
       
   263 }
       
   264 
       
   265 HBufC* CMIDletSuiteCustomAttributes::mapOnScreenKeyboardToLegacyValueL(const std::wstring& aOmjValue)
       
   266 {
       
   267     try
       
   268     {
       
   269         switch (java::util::JavaCommonUtils::wstringToInt(aOmjValue))
       
   270         {
       
   271         case 0:
       
   272             return KValueNo().Alloc();
       
   273         case 1:
       
   274             return KValueGameactions().Alloc();
       
   275         case 2:
       
   276             return KValueNavigationkeys().Alloc();
       
   277         }
       
   278     }
       
   279     catch (ExceptionBase& e)
       
   280     {
       
   281     }
       
   282     User::Leave(KErrNotFound);
       
   283     return NULL; // this is here to make the compiler happy (it won't throw a warning)
       
   284 }
       
   285 
       
   286 void CMIDletSuiteCustomAttributes::mapOnScreenKeyboardToOmjValue(const TDesC& aLegacyValue, std::wstring& aOmjValue)
       
   287 {
       
   288     if (aLegacyValue.Compare(KValueNo) == 0)
       
   289     {
       
   290         aOmjValue += L"0";
       
   291     }
       
   292     else if (aLegacyValue.Compare(KValueGameactions) == 0)
       
   293     {
       
   294         aOmjValue += L"1";
       
   295     }
       
   296     else if (aLegacyValue.Compare(KValueNavigationkeys) == 0)
       
   297     {
       
   298         aOmjValue += L"2";
       
   299     }
       
   300 }
       
   301 
       
   302 CSecurityPreferences* CSecurityPreferences::NewL()
       
   303 {
       
   304     CSecurityPreferences* sp = new(ELeave) CSecurityPreferences();
       
   305     CleanupStack::PushL(sp);
       
   306     sp->ConstructL();
       
   307     CleanupStack::Pop(sp);
       
   308     return sp;
       
   309 }
       
   310 
       
   311 
       
   312 void CSecurityPreferences::ConstructL()
       
   313 {
       
   314 }
       
   315 
       
   316 CSecurityPreferences::CSecurityPreferences()
       
   317 {
       
   318 }
       
   319 
       
   320 CSecurityPreferences::~CSecurityPreferences()
       
   321 {
       
   322 }
       
   323 
       
   324 MPermission::TMode CSecurityPreferences::InteractionModeL(const MFunctionGroupBinding& /*aBinding*/)
       
   325 {
       
   326     User::Leave(KErrNotSupported);
       
   327     return MPermission::EDenied; // this is here to make the compiler happy (it won't throw a warning)
       
   328 }
       
   329 
       
   330 void CSecurityPreferences::InteractionModeL(const MFunctionGroupBinding& /*aBinding*/,
       
   331         MPermission::TMode /*aMode*/)
       
   332 {
       
   333     User::Leave(KErrNotSupported);
       
   334 }
       
   335 
       
   336 TBool CSecurityPreferences::IsFromDefaults(void) const
       
   337 {
       
   338     return EFalse; // this is here to make the compiler happy (it won't throw a warning)
       
   339 }
       
   340 
       
   341 void CSecurityPreferences::SetInteractionMode(const MFunctionGroupBinding& /*aBinding*/,
       
   342         MPermission::TMode /*aMode*/)
       
   343 {
       
   344 }
       
   345