It is sometimes useful to be able to detect whether an application is started at boot time by the Startup List API (present only in S60 3rd Edition) or by the user, and passing Symbian Signed - which is generally required to have an application which requires auto boot feature - makes this almost mandatory. This article will help you with this.
First, you have to modify the application registration file and add some opaque_data field in the APP_REGISTRATION_INFO resource. The content and value of these data does not really matter, you just need to specify something like below:
#include <appinfo.rh>
#include <uikon.rh>
RESOURCE APP_REGISTRATION_INFO
{
...
opaque_data = r_startup_detect;
}
RESOURCE NUMBER_INT8 r_startup_detect
{
value = 1;
}
The opaque_data and other launch parameters will be ignored by the startup list when launching the application. Thus, detecting whether they are present or not allows to differentiate whether the application has been launched at boot time or by the user.
To do this, you shall override the ProcessCommandParametersL() function in your AppUI:
TBool CMyAppUi::ProcessCommandParametersL( CApaCommandLine &aCommandLine )
{
if(aCommandLine.OpaqueData().Length() > 0)
{
// Opaque data exists, app. has been manually started from the menu
}
else
{
// App. has been auto-started -> exit if auto-start in settings is OFF
}
return CEikAppUi::ProcessCommandParametersL( aCommandLine );
}
you can also note that passing Symbian Signed requires that your application has a setting option that allow to disable the auto start feature. As no API is currently available to do this, you will need to have some code to handle this. Hopefully, this is very well explained in the Forum Nokia Technical Library (which this article is based on).
Hello Eric,
It would be a lot more convenient to do this check already in AppUi ConstructL method, right after the call to BaseConstructL. So, I tried this:
CApaCommandLine* commandLine = NULL; TInt getCommandLineError = CApaCommandLine::GetCommandLineFromProcessEnvironment( commandLine ); User::LeaveIfError( getCommandLineError ); CleanupStack::PushL( commandLine ); MultiThreadedLogger::Log(commandLine->OpaqueData()); if(commandLine->OpaqueData().Length() > 0) // Opaque data exists, app. has been manually started from the menu else // App. has been auto-started -> exit if auto-start in settings is OFF CleanupStack::PopAndDestroy( commandLine ); commandLine = NULL;
But in this approach the OpaqueData field is always empty, so something modifies it after AppUi::ConstructL has been executed. Do you have any idea if this is the case? According to APPARC documentation, GetCommandLineFromProcessEnvironment should be usable at any time, even in a plain EXE.
Thanks, Pawel
Hello Eric,
This is very useful information, thanks.
But is it true that an app which autostarts needs to have an autostart-disable mechanism to be able to pass Symbian Signed? I've just read through the Symbian Signed Test Criteria and I didn't see this stipulation there.
Good :-)
Anyway, my results agree with what Pawel says - I can't get his code using GetCommandLineFromProcessEnvironment in the AppUi's ConstructL to work (although the same code worked fine in a console app and detected the presence or not of the opaque data) but your code in ProcessCommandParametersL works OK.
I've tried this on S60 3rd SDK and on an N73 with the same results.
I'm puzzled by this - must confess I don't really understand the data flow here - where does GetCommandLineFromProcessEnvironment fish the data up from - could be from RProcess but I don't see any opaque data associated with an RProcess???
Anyway, Eric's solution is working well for me now, thanks.
Hi, can you do the same thing for EXEs withoug a GUI? I do not know how to access the opaque data without AppUi and in turn I do not know how to set command line parameters from app registration resource that could be read with User::CommandLine() for example. Thanks, J.