sysstatemgmt/systemstatereferenceplugins/custcmd/src/cmdpublishstartupmode.cpp
changeset 0 4e1aa6a622a0
child 20 1ddbe54d0645
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19  @released
       
    20 */
       
    21 
       
    22 #include <ssm/starterdomaincrkeys.h>
       
    23 #include <centralrepository.h>
       
    24 #include <e32property.h>
       
    25 #include <ssm/startupdomainpskeys.h>
       
    26 
       
    27 #include "cmdpublishstartupmode.h"
       
    28 #include "ssmuiproviderdll.h"
       
    29 #include "ssmdebug.h"
       
    30 
       
    31 
       
    32 /**
       
    33  * Constructs and returns a new custom command, leaving on errors.
       
    34  * 
       
    35  * @internalComponent
       
    36  */
       
    37 CCustomCmdPublishStartupMode* CCustomCmdPublishStartupMode::NewL()
       
    38 	{
       
    39 	CCustomCmdPublishStartupMode* self = new (ELeave) CCustomCmdPublishStartupMode();
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 CCustomCmdPublishStartupMode::CCustomCmdPublishStartupMode()
       
    44 :	CActive(EPriorityNormal)
       
    45 	{
       
    46 	CActiveScheduler::Add(this);
       
    47 	}
       
    48 
       
    49 CCustomCmdPublishStartupMode::~CCustomCmdPublishStartupMode()
       
    50 	{
       
    51 	Deque();
       
    52 	//Cancel the request if there is any
       
    53 	iSsmMiscAdaptation.Cancel();
       
    54 	
       
    55 	//Close RSsmMiscAdaptation
       
    56 	iSsmMiscAdaptation.Close();
       
    57 	
       
    58 	delete iRepository;
       
    59 	}
       
    60 
       
    61 /**
       
    62  * Initializes this custom command. This consists of connecting to the required servers.
       
    63  * 
       
    64  * @internalComponent
       
    65  */
       
    66 TInt CCustomCmdPublishStartupMode::Initialize(CSsmCustomCommandEnv* /*aCmdEnv*/)
       
    67 	{
       
    68 	iHiddenResetPckg = EFalse;
       
    69 	iState = EInitial;
       
    70 	// Connect to the central repository
       
    71 	TRAPD(err, iRepository = CRepository::NewL(KCRUidStartup));
       
    72 	if(KErrNone != err && KErrNotFound != err)
       
    73 			{
       
    74 			return err;
       
    75 			}
       
    76 	
       
    77 	//Connect to RSsmMiscAdaptation
       
    78 	err = iSsmMiscAdaptation.Connect();
       
    79 	return err;
       
    80 	}
       
    81 
       
    82 /**
       
    83  * Destory this object and any resources allocated to it.
       
    84  * 
       
    85  * @internalComponent
       
    86  */
       
    87 void CCustomCmdPublishStartupMode::Close()
       
    88 	{
       
    89 	}
       
    90 
       
    91 void CCustomCmdPublishStartupMode::Release()
       
    92 	{
       
    93 	delete this;
       
    94 	}
       
    95 
       
    96 /**
       
    97  * Issues the required requests to publish the startup mode. Completes aStatus upon completion.
       
    98  * 
       
    99  * @internalComponent
       
   100  */
       
   101 void CCustomCmdPublishStartupMode::Execute(const TDesC8& /*aParams*/, TRequestStatus& aStatus)
       
   102 	{
       
   103 	// Remember our completion value
       
   104 	iReturnStatus = &aStatus;
       
   105 	aStatus = KRequestPending;
       
   106     iState = ERequestingStartupMode;
       
   107 
       
   108 	// Issue request
       
   109 	iSsmMiscAdaptation.GetGlobalStartupMode(iStartupModePckg, iStatus);
       
   110 	SetActive();
       
   111 	}
       
   112 
       
   113 void CCustomCmdPublishStartupMode::PublishStartupModeL()
       
   114     {
       
   115     if(iStatus != KErrNone)
       
   116          {
       
   117          DEBUGPRINT2A("Request GetGlobalStartupMode returned error: %d", iStatus.Int());
       
   118          User::Leave(iStatus.Int());
       
   119          }
       
   120 
       
   121      // Publish startup mode
       
   122      TInt err = RProperty::Set(CSsmUiSpecific::StartupPSUid(), KPSGlobalStartupMode, iStartupModePckg());
       
   123      if(KErrNone != err)
       
   124          {
       
   125          DEBUGPRINT2A("Publishing startup mode returned error: %d", err);
       
   126          User::Leave(err);
       
   127          }
       
   128 
       
   129      iState = ERequestingHiddenReset;
       
   130      iSsmMiscAdaptation.GetHiddenReset(iHiddenResetPckg, iStatus);
       
   131      SetActive();
       
   132     }
       
   133 
       
   134 void CCustomCmdPublishStartupMode::PublishHiddenResetL()
       
   135     {
       
   136     DEBUGPRINT2A("Request GetHiddenReset completed with errorcode: %d", iStatus.Int());
       
   137     // Only if we've been able to open the repository it is published from.
       
   138     if(iRepository != NULL)
       
   139         {
       
   140         // Retrieve startup reason
       
   141         TInt startupReason = 0;
       
   142         TInt err = iRepository->Get(KStartupReason, startupReason);
       
   143 
       
   144         if (KErrNone == err)
       
   145             {
       
   146             if ( startupReason == ENormalStartup &&
       
   147                  iStatus.Int() == KErrNone && // Hidden reset query was successful
       
   148                  iHiddenResetPckg())
       
   149                 {
       
   150                 DEBUGPRINT1A("Hidden reset detected");
       
   151                 startupReason = EUnknownReset;
       
   152                 }
       
   153             
       
   154             // Publish startup reason
       
   155             err = RProperty::Set(CSsmUiSpecific::StartupPSUid(), KPSStartupReason, startupReason);
       
   156             if(KErrNone != err)
       
   157                 {
       
   158                 DEBUGPRINT2A("Publishing startup reason returned error: %d", err);
       
   159                 User::Leave(err);
       
   160                 }
       
   161             DEBUGPRINT2A( "Startup reason set to %d", startupReason);
       
   162             }
       
   163         }
       
   164 
       
   165     // Command complete, signal back
       
   166     User::RequestComplete(iReturnStatus, KErrNone);
       
   167     // Reset iReturnStatus so it is not completed again in future
       
   168     iReturnStatus = NULL;       
       
   169     }
       
   170 
       
   171 /**
       
   172  * From CActive::RunL()
       
   173  * 
       
   174  * @internalComponent 
       
   175  */
       
   176 void CCustomCmdPublishStartupMode::RunL()
       
   177 	{
       
   178 	switch(iState)
       
   179 	    {
       
   180 	    case ERequestingStartupMode:
       
   181 	        {
       
   182 	        PublishStartupModeL();
       
   183 	        break;
       
   184 	        }
       
   185 	    case ERequestingHiddenReset:
       
   186 	        {
       
   187 	        PublishHiddenResetL();
       
   188 	        break;
       
   189 	        }
       
   190 	    default:
       
   191 	        {
       
   192 	        User::Leave(KErrArgument);
       
   193 	        }
       
   194 	    }
       
   195 	}
       
   196 
       
   197 /**
       
   198  * From CActive::DoCancel()
       
   199  * 
       
   200  * @internalComponent 
       
   201  */
       
   202 void CCustomCmdPublishStartupMode::DoCancel()
       
   203 	{
       
   204 	//Cancel the request if there is any
       
   205 	iSsmMiscAdaptation.Cancel();
       
   206 	}
       
   207 
       
   208 /**
       
   209  * From CActive::RunError()
       
   210  * 
       
   211  * @internalComponent 
       
   212  */
       
   213 TInt CCustomCmdPublishStartupMode::RunError(TInt aError)
       
   214 	{
       
   215 	DEBUGPRINT2A("CCustomCmdPublishStartupMode::RunError received error: %d", aError);
       
   216 	User::RequestComplete(iReturnStatus, aError);
       
   217 	// We've returned the error via the status so return KErrNone here.
       
   218 	return KErrNone;
       
   219 	}
       
   220 
       
   221 void CCustomCmdPublishStartupMode::ExecuteCancel()
       
   222 	{
       
   223 	Cancel();
       
   224 	if(iReturnStatus != NULL)
       
   225 		{
       
   226 		User::RequestComplete(iReturnStatus, KErrCancel);
       
   227 		iReturnStatus = NULL;
       
   228 		}
       
   229 	}