javamanager/javacaptain/extensionplugins/autostarter/src.s60/autostarter.cpp
changeset 35 85266cc22c7f
child 48 e0d6e9bd3ca7
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     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:  autostarter is Java Captain Symbian plugin that starts
       
    15 *               auto start Java applications after they have been installed
       
    16 *               and when the device boots.
       
    17 *
       
    18 */
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <f32file.h>
       
    22 #include <javastorage.h>
       
    23 #include <javastorageentry.h>
       
    24 #include <javastoragenames.h>
       
    25 #include <memory>
       
    26 
       
    27 #include "commsendpoint.h"
       
    28 #include "coreinterface.h"
       
    29 #include "javaprocessconstants.h"
       
    30 #include "javasymbianoslayer.h"
       
    31 #include "javauids.h"
       
    32 #include "logger.h"
       
    33 #include "preinstallerstartermessages.h"
       
    34 #include "rtcinterface.h"
       
    35 #include "rtcmessages.h"
       
    36 
       
    37 #include "autostarter.h"
       
    38 
       
    39 
       
    40 using namespace java::storage;
       
    41 using namespace java::util;
       
    42 
       
    43 
       
    44 /**
       
    45  * Return pointer to ExtensionPluginInterface implementation for this
       
    46  * extension dll
       
    47  */
       
    48 java::captain::ExtensionPluginInterface* getExtensionPlugin()
       
    49 {
       
    50     return new java::captain::AutoStarter();
       
    51 }
       
    52 
       
    53 namespace java
       
    54 {
       
    55 namespace captain
       
    56 {
       
    57 
       
    58 /**
       
    59  * Empty contructor
       
    60  */
       
    61 AutoStarter::AutoStarter() : mCore(0)
       
    62 {
       
    63 }
       
    64 
       
    65 /**
       
    66  * Empty destructor
       
    67  */
       
    68 AutoStarter::~AutoStarter()
       
    69 {
       
    70 }
       
    71 
       
    72 /**
       
    73  * Implement PluginInterface method
       
    74  */
       
    75 void AutoStarter::startPlugin(CoreInterface* core)
       
    76 {
       
    77     LOG(EJavaCaptain, EInfo, "AutoStarter plugin started");
       
    78 
       
    79     mCore = core;
       
    80 }
       
    81 
       
    82 /**
       
    83  * Implement PluginInterface method
       
    84  */
       
    85 void AutoStarter::stopPlugin()
       
    86 {
       
    87     mCore = 0;
       
    88 }
       
    89 
       
    90 /**
       
    91  * Implement ExtensionPluginInterface method
       
    92  */
       
    93 EventConsumerInterface* AutoStarter::getEventConsumer()
       
    94 {
       
    95     return this;
       
    96 }
       
    97 
       
    98 /**
       
    99  * Handle Java Captain events sent by Boot event provider or
       
   100  * preinstaller starter
       
   101  *
       
   102  * Implement EventConsumerInterface method
       
   103  */
       
   104 void AutoStarter::event(const std::string& eventProvider,
       
   105                        java::comms::CommsMessage& aMsg)
       
   106 {
       
   107     LOG1(EJavaCaptain, EInfo, "AutoStarter::event received, id %d", aMsg.getMessageId());
       
   108 
       
   109     if (eventProvider == PREINSTALLER_EVENT_PROVIDER)
       
   110     {
       
   111         int exitStatus = 0;
       
   112         getPreinstallerExitedMessageParams(aMsg, exitStatus);
       
   113         LOG1(
       
   114             EJavaCaptain,
       
   115             EInfo,
       
   116             "AutoStarter::event() preinstaller exited event received (status=%d)",
       
   117             exitStatus);
       
   118 
       
   119             // Start auto-start MIDlets
       
   120             TRAPD(err, checkMIDletsToBeStartedL())
       
   121             if (KErrNone != err)
       
   122             {
       
   123                 ELOG1(EJavaCaptain, "AutoStarter::checkMIDletsToBeStartedL: leaved (%d)", err);
       
   124             }
       
   125     }
       
   126 /*
       
   127     else if ( MESSAGE TELLS THAT NEW MIDLET HAS BEEN INSTALLED )
       
   128     {
       
   129         // Auto-start the new MIDlet if it is auto-start MIDlet
       
   130     }
       
   131 */
       
   132 
       
   133 }
       
   134 
       
   135 /**
       
   136  *
       
   137  *
       
   138  */
       
   139 void AutoStarter::checkMIDletsToBeStartedL()
       
   140 {
       
   141 
       
   142 
       
   143     // Find all MIDlets with Nokia-MIDlet-auto-start
       
   144     // APPLICATION_TABLE, if (AUTORUN == AUTOSTART_TRUE) || (AUTORUN == AUTOSTART_ONCE),
       
   145     // call startMIDletL(ID)
       
   146 
       
   147     LOG(EJavaCaptain, EInfo, "AutoStarter::checkMIDletsToBeStartedL called");
       
   148 
       
   149     std::auto_ptr<JavaStorage> js(JavaStorage::createInstance());    
       
   150     try
       
   151     {
       
   152         js->open(JAVA_DATABASE_NAME);
       
   153 
       
   154         // In Java Storage there is 'APPLICATION_TABLE' table that contains
       
   155         // the Uid of the application in ID column. The value in column AUTORUN is
       
   156         // one of the following AUTOSTART_FALSE (0), AUTOSTART_TRUE (1) or
       
   157         // AUTOSTART_ONCE (2)
       
   158 
       
   159         JavaStorageEntry attribute;
       
   160         JavaStorageApplicationEntry_t findPattern;
       
   161         JavaStorageApplicationList_t  foundEntries;
       
   162 
       
   163         // Get all IDs from APPLICATION_TABLE where AUTORUN is AUTOSTART_TRUE
       
   164         attribute.setEntry(AUTORUN, L"1");
       
   165         findPattern.insert(attribute);
       
   166         attribute.setEntry(ID, L"");
       
   167         findPattern.insert(attribute);
       
   168 
       
   169         js->search(APPLICATION_TABLE, findPattern, foundEntries);
       
   170         findPattern.clear();
       
   171 
       
   172         // Iterate through all found applications
       
   173         JavaStorageApplicationList_t::const_iterator appIterator;
       
   174         for (appIterator = foundEntries.begin(); appIterator != foundEntries.end(); ++appIterator)
       
   175         {
       
   176             std::wstring applicationId = appIterator->begin()->entryValue();
       
   177 
       
   178             LOG1WSTR(EJavaCaptain, EInfo,
       
   179                 "AutoStarter::checkMIDletsToBeStartedL : going to start MIDlet, uid is %s",
       
   180                 applicationId);
       
   181 
       
   182             startMIDletL(applicationId);
       
   183         }
       
   184         foundEntries.clear();
       
   185 
       
   186 
       
   187         // Get all IDs from APPLICATION_TABLE where AUTORUN is AUTOSTART_ONCE
       
   188         attribute.setEntry(AUTORUN, L"2");
       
   189         findPattern.insert(attribute);
       
   190         attribute.setEntry(ID, L"");
       
   191         findPattern.insert(attribute);
       
   192 
       
   193         js->search(APPLICATION_TABLE, findPattern, foundEntries);
       
   194         findPattern.clear();
       
   195 
       
   196         // Iterate through all found applications
       
   197         for (appIterator = foundEntries.begin(); appIterator != foundEntries.end(); ++appIterator)
       
   198         {
       
   199             std::wstring applicationId = appIterator->begin()->entryValue();
       
   200 
       
   201             LOG1WSTR(EJavaCaptain, EInfo,
       
   202                 "AutoStarter::checkMIDletsToBeStartedL : going to start MIDlet (once), uid is %s",
       
   203                 applicationId);
       
   204 
       
   205             if (startMIDletL(applicationId))
       
   206             {
       
   207                 // after starting MIDlet must set AUTORUN value to AUTOSTART_FALSE
       
   208                 JavaStorageApplicationEntry_t matchEntries;
       
   209 
       
   210                 JavaStorageApplicationEntry_t updateEntries;
       
   211                 JavaStorageEntry attribute;
       
   212 
       
   213                 attribute.setEntry(ID, applicationId);
       
   214                 matchEntries.insert(attribute);
       
   215 
       
   216                 attribute.setEntry(AUTORUN, L"0");
       
   217                 updateEntries.insert(attribute);
       
   218 
       
   219                 js->update(APPLICATION_TABLE, updateEntries, matchEntries);
       
   220             }
       
   221         }
       
   222         foundEntries.clear();
       
   223     }
       
   224     catch (JavaStorageException& e)
       
   225     {
       
   226         ELOG1(EJavaCaptain,
       
   227             "AutoStarter::checkMIDletsToBeStartedL: Java Storage exception %s", e.what());
       
   228     }
       
   229 
       
   230     try
       
   231     {
       
   232         js->close();
       
   233     }
       
   234     catch (JavaStorageException& e2)
       
   235     {
       
   236         WLOG1(EJavaCaptain,
       
   237             "AutoStarter::checkMIDletsToBeStartedL: Java Storage exception "
       
   238             "when closing storage %s", e2.what());
       
   239     }
       
   240 }
       
   241 
       
   242 
       
   243 /**
       
   244  *
       
   245  *  @return true if launch succeeded, false is starting failed
       
   246  */
       
   247 bool AutoStarter::startMIDletL(const std::wstring& aUid)
       
   248 {
       
   249     // start MIDlet
       
   250     rtcLaunchInfo launchInfo(aUid);
       
   251 
       
   252     bool launchSuccess = mCore->getRtc()->launch(launchInfo);
       
   253     if (!launchSuccess)
       
   254     {
       
   255         ELOG(EJavaCaptain, "AutoStarter::startMIDletL: launching MIDlet failed");
       
   256     }
       
   257 
       
   258     return launchSuccess;
       
   259 }
       
   260 
       
   261 
       
   262 } // namespace captain
       
   263 } // namespace java