phoneclientserver/EnPolicy/Src/SosEnPolicy/CSosEmergencyNumberPolicyHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2004-2005 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:  Provides SOS emergency number policy API implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "csosemergencynumberpolicyhandler.h" 
       
    22 #include    <mmtsy_names.h>
       
    23 #include    <featmgr.h>
       
    24 #include    <bldvariant.hrh>
       
    25 #include    <telservicesvariant.hrh>
       
    26 #include    <telservicesinternalcrkeys.h>
       
    27 #include    <centralrepository.h>
       
    28 #include "csosenpolicysatrefresh.h" 
       
    29 
       
    30 // CONSTANTS
       
    31 // The default emergency numbers.
       
    32 _LIT( KEnPolicyUnivEmergencyNumber, "112" );
       
    33 _LIT( KEnPolicyUSEmergencyNumber, "911" );      // U.S.A
       
    34 _LIT( KEnPolicyUKEmergencyNumber, "999" );      // U.K
       
    35 _LIT( KEnPolicyAUEmergencyNumber, "000" );      // Australian
       
    36 _LIT( KEnPolicyMXEmergencyNumber, "08" );       // Mexico
       
    37 _LIT( KEnPolicyAPACEmergencyNumber, "110" );    // APAC countries, Germany
       
    38 _LIT( KEnPolicyJapanEmergencyNumber, "118" );   // Japan
       
    39 _LIT( KEnPolicyJapanEmergencyNumber2, "119" );  // Japan
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CSosEnPolicyActive::CSosEnPolicyActive()
       
    45 // 
       
    46 // C++ constructor
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CSosEnPolicyActive::CSosEnPolicyActive( 
       
    50     CSosEmergencyNumberPolicyHandler& aEmergNumHandler )
       
    51     : CActive( CActive::EPriorityStandard ), iEmergNumHandler ( aEmergNumHandler )
       
    52     {
       
    53     CActiveScheduler::Add( this );
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSosEnPolicyActive::~CSosEnPolicyActive()
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSosEnPolicyActive::~CSosEnPolicyActive()
       
    61     {    
       
    62     Cancel();
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSosEnPolicyActive::RunL()
       
    67 // 
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CSosEnPolicyActive::RunL()
       
    71     {
       
    72     iEmergNumHandler.CpsssmHandleSimStatusEvent( 
       
    73         CSosEmergencyNumberPolicyHandler::ESosEnPolicySimEmergencyNumberRead );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CSosEnPolicyActive::DoCancel()
       
    78 // 
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CSosEnPolicyActive::DoCancel()
       
    82     {
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CSosEmergencyNumberPolicyHandler::CSosEmergencyNumberPolicyHandler()
       
    87 // 
       
    88 // C++ constructor
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CSosEmergencyNumberPolicyHandler::CSosEmergencyNumberPolicyHandler() 
       
    92     : CActive( CActive::EPriorityStandard )
       
    93     {
       
    94     CActiveScheduler::Add( this );
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CSosEmergencyNumberPolicyImp::NewL()
       
    99 // 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CSosEmergencyNumberPolicyHandler* CSosEmergencyNumberPolicyHandler::NewL( 
       
   103     RTelServer& aETelServer )
       
   104     {
       
   105     CSosEmergencyNumberPolicyHandler* self = 
       
   106         new(ELeave) CSosEmergencyNumberPolicyHandler();
       
   107     CleanupStack::PushL( self );
       
   108     self->ConstructL( aETelServer );
       
   109     CleanupStack::Pop();
       
   110     return self;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CSosEmergencyNumberPolicyHandler::~CSosEmergencyNumberPolicyHandler()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CSosEmergencyNumberPolicyHandler::~CSosEmergencyNumberPolicyHandler()
       
   118     {    
       
   119     Cancel(); // also deletes requester if there is one
       
   120     
       
   121     delete iSatRefresh;
       
   122     // both cancel operations in destructors.
       
   123     delete iSimMonitor;
       
   124     delete iENListHandler;
       
   125 
       
   126     iENStore.Close();
       
   127 
       
   128     FeatureManager::UnInitializeLib();
       
   129     iMobilePhone.Close();
       
   130     
       
   131     delete iCenRepSession;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CSosEmergencyNumberPolicyHandler::ConstructL()
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CSosEmergencyNumberPolicyHandler::ConstructL( RTelServer& aETelServer )
       
   139     {
       
   140     FeatureManager::InitializeLibL();
       
   141 
       
   142     User::LeaveIfError( iMobilePhone.Open( aETelServer , KMmTsyPhoneName ) );
       
   143 
       
   144     // Create sat refresh listener
       
   145     iSatRefresh = CSosEnPolicySatRefresh::NewL( *this );
       
   146     
       
   147     iSimMonitor = CSosEnPolicySimStatusMonitor::NewL( *this );
       
   148 
       
   149     iENListHandler =  CSosEnPolicyENListHandler::NewL() ;
       
   150 
       
   151     User::LeaveIfError( iENStore.Open( iMobilePhone ) );
       
   152 
       
   153     InitializeCentralRepositoryList();
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CSosEmergencyNumberPolicyHandler::IsEmergencyNumberL 
       
   159 // 
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TInt CSosEmergencyNumberPolicyHandler::IsEmergencyNumber ( 
       
   163                                     TPhCltTelephoneNumber& aTelNumber, 
       
   164                                     TPhCltEmergencyNumberQueryMode aMode,
       
   165                                     TBool& aIsEmergencyNumber )
       
   166                                   
       
   167     {
       
   168     if ( aMode == EPhCltEmergencyNumberQueryModeAdvanced )
       
   169         {
       
   170         aIsEmergencyNumber = iENListHandler->IsInListByAdvancedMode( aTelNumber );
       
   171         }
       
   172     else
       
   173         {
       
   174         aIsEmergencyNumber = iENListHandler->IsInListByNormalMode( aTelNumber ); 
       
   175         }
       
   176     
       
   177     return KErrNone;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CSosEmergencyNumberPolicyHandler::CpsssmHandleSimStatusEvent()
       
   182 // 
       
   183 // SIM event occurred, it's either for adding or removing
       
   184 // SIM emergency numbers. If SIM is rejected or removed
       
   185 // SIM emergency numbers are removed.
       
   186 //
       
   187 // Old list is cleared only if new list is received. Otherwise
       
   188 // it's stays valid.
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 /*****************************************************
       
   192 *   Series 60 Customer / ETel
       
   193 *   Series 60  ETel API
       
   194 *****************************************************/
       
   195 void  CSosEmergencyNumberPolicyHandler::CpsssmHandleSimStatusEvent(
       
   196     TSosEnPolicySimEmergencyNumberAction aAction )
       
   197     {
       
   198     // If not null there is something ongoing which should be cancelled first.
       
   199     if ( iSimEnRetriver )
       
   200         {
       
   201         Cancel(); // retriever is also deleted.
       
   202         }
       
   203     
       
   204     // We need to read new numbers.
       
   205     if ( aAction == ESosEnPolicySimEmergencyNumberRead )
       
   206         {
       
   207         TInt err = KErrNone;
       
   208 
       
   209         // _DPRINT( 4, "ENPolicy.EN.SimNumbers.create" );          // debug print
       
   210 
       
   211         // The retrieve may fail, that possibility is TRAPed here.
       
   212         TRAP( err, iSimEnRetriver = 
       
   213             CRetrieveMobilePhoneENList::NewL( iENStore ) );
       
   214 
       
   215         // _DDPRINT( 4, "ENPolicy.EN.SimNumbers.create.ok.", err ); // debug print
       
   216 
       
   217         if( err == KErrNone )
       
   218             {
       
   219             iSimEnRetriver->Start( iStatus );
       
   220             SetActive();
       
   221             }
       
   222         }
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CSosEmergencyNumberPolicyHandler::DoCancel()
       
   227 // 
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 /*****************************************************
       
   231 *   Series 60 Customer / ETel
       
   232 *   Series 60  ETel API
       
   233 *****************************************************/
       
   234 void CSosEmergencyNumberPolicyHandler::DoCancel()
       
   235     {
       
   236     if ( iSimEnRetriver )
       
   237         {
       
   238         iSimEnRetriver->Cancel();
       
   239         delete iSimEnRetriver;
       
   240         iSimEnRetriver = NULL;
       
   241         }
       
   242     }
       
   243 
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CSosEmergencyNumberPolicyHandler::RunL()
       
   247 // 
       
   248 // Number fetch complete. In case of error we stick to that
       
   249 // what we have, or use default list.
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 /*****************************************************
       
   253 *   Series 60 Customer / ETel
       
   254 *   Series 60  ETel API
       
   255 *****************************************************/
       
   256 void CSosEmergencyNumberPolicyHandler::RunL()
       
   257     {
       
   258     if ( iStatus.Int() == KErrNone )
       
   259         {
       
   260         // ownership is transferred!
       
   261         CMobilePhoneENList* list = iSimEnRetriver->RetrieveListL();
       
   262         CleanupStack::PushL( list );
       
   263         if ( list )
       
   264             {
       
   265             TInt count = list->Enumerate();
       
   266 
       
   267             // _DDPRINT( 4, "ENPolicy.EN.SimNumber.count.", count ); // debug print
       
   268 
       
   269             // clear old changeable stuff from list.
       
   270             iENListHandler->ClearCurrentList();
       
   271             for ( TInt i = 0; i < count; i++ )
       
   272                 {
       
   273                 const RMobileENStore::TMobileENEntryV1 entry = 
       
   274                     list->GetEntryL( i );
       
   275 
       
   276                 // _DDPRINT( 4, "ENPolicy.EN.SimNumber.number.", entry.iNumber );
       
   277 
       
   278                 iENListHandler->AddToList( entry.iNumber, EFalse );  
       
   279                 }
       
   280             }
       
   281         CleanupStack::PopAndDestroy(); // list
       
   282         }
       
   283     delete iSimEnRetriver;
       
   284     iSimEnRetriver = NULL;
       
   285     }
       
   286 
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CSosEmergencyNumberPolicyHandler::RunError
       
   290 //
       
   291 // Called when RunL leaves. 
       
   292 // The RunL can leave in EN list operations. It is ok to return KErrNone after
       
   293 // deleting the SimEnRetriever.
       
   294 //
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TInt CSosEmergencyNumberPolicyHandler::RunError( TInt /*aError*/ )
       
   298     {
       
   299     // delete the SimEnRetriever, because not done in RunL.
       
   300     delete iSimEnRetriver;
       
   301     iSimEnRetriver = NULL;
       
   302 
       
   303     return KErrNone;
       
   304     }
       
   305 
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CSosEmergencyNumberPolicyHandler::InitializeCentralRepositoryList()
       
   309 // 
       
   310 // Called once in the startup.
       
   311 // Adds universal (112) emergency number to Central Repository list,
       
   312 // and checks possible product specific values. After this,
       
   313 // these values are not changed.
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CSosEmergencyNumberPolicyHandler::InitializeCentralRepositoryList()
       
   317     {
       
   318     // (From 3GPP specification 22.101, ftp://ftp.3gpp.org/specs/latest/Rel-8/22_series/22101-880.zip)
       
   319     //
       
   320     // "The ME shall identify a number dialled by the end user as a valid emergency number if it occurs under one or more 
       
   321     //  of the following conditions:
       
   322     //      a) 112 and 911 shall always be available. These numbers shall be stored on the ME.
       
   323     //      b) Any emergency number stored on a SIM/USIM when the SIM/USIM is present.
       
   324     //      c) 000, 08, 110, 999, 118 and 119 when a SIM/USIM is not present. These numbers shall be stored on the ME.
       
   325     //      d) Additional emergency numbers that may have been downloaded by the serving network when the SIM/USIM is present."
       
   326     
       
   327     // Universal, 112
       
   328     iENListHandler->AddToList( KEnPolicyUnivEmergencyNumber, ETrue );
       
   329     // U.S, 911
       
   330     iENListHandler->AddToList( KEnPolicyUSEmergencyNumber, ETrue );
       
   331 
       
   332     if ( iSimMonitor->IsReadingAllowed() )
       
   333         {
       
   334         CpsssmHandleSimStatusEvent( ESosEnPolicySimEmergencyNumberRead );
       
   335         }
       
   336     else
       
   337         {
       
   338         iENListHandler->AddToList( KEnPolicyUKEmergencyNumber );
       
   339         iENListHandler->AddToList( KEnPolicyAUEmergencyNumber );
       
   340         iENListHandler->AddToList( KEnPolicyMXEmergencyNumber );
       
   341         iENListHandler->AddToList( KEnPolicyAPACEmergencyNumber );
       
   342         iENListHandler->AddToList( KEnPolicyJapanEmergencyNumber );
       
   343         iENListHandler->AddToList( KEnPolicyJapanEmergencyNumber2 ); 
       
   344         }
       
   345 
       
   346     // Product specific numbers.
       
   347     iENListHandler->AddToList( iENListHandler->ReadProductSpecificNumbers(), ETrue );
       
   348     }
       
   349 
       
   350 // End of file.