javaextensions/mobinfo/src.s60/javamobinfo.cpp
changeset 61 bf7ee68962da
parent 21 2a9601315dfc
child 78 71ad690e91f5
equal deleted inserted replaced
48:e0d6e9bd3ca7 61:bf7ee68962da
    27 #include <cmmanager.h>
    27 #include <cmmanager.h>
    28 #include <cmconnectionmethoddef.h>
    28 #include <cmconnectionmethoddef.h>
    29 #include <cmpluginpacketdatadef.h>
    29 #include <cmpluginpacketdatadef.h>
    30 #include <cmpluginwlandef.h>
    30 #include <cmpluginwlandef.h>
    31 #include <cmpluginhscsddef.h>
    31 #include <cmpluginhscsddef.h>
       
    32 #include "connectionmanager.h"
       
    33 
    32 using namespace CMManager;
    34 using namespace CMManager;
    33 
    35 
    34 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    36 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    35 #include <es_sock.h>
    37 #include <es_sock.h>
    36 #include <es_enum.h>
    38 #include <es_enum.h>
    73 const TInt KJVMProcessUid = KJavaMidp;
    75 const TInt KJVMProcessUid = KJavaMidp;
    74 
    76 
    75 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
    76 //    forward declarations
    78 //    forward declarations
    77 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    78 HBufC* GetProperty(const TInt aProperty, const TUint32 aAppDefaultApn);
    80 HBufC* GetProperty(const TInt aProperty, const TUint32 aAppDefaultApn, const TUint32 aAppDefaultApType);
    79 HBufC* GetTelephonyPropertyL(const TInt aProperty);
    81 HBufC* GetTelephonyPropertyL(const TInt aProperty);
    80 HBufC* GetDateTimePropertyL(const TInt aProperty);
    82 HBufC* GetDateTimePropertyL(const TInt aProperty);
    81 HBufC* GetNetworkAccessL(const TUint32 aAppDefaultApn);
    83 HBufC* GetNetworkAccessL(const TUint32 aAppDefaultApn, const TUint32 aAppDefaultApType);
    82 TUint32     GetUsedIapL();
    84 TUint32     GetUsedIapL();
    83 HBufC*      GetBearerTypeL(TUint32 aIapId);
    85 HBufC*      GetBearerTypeL(TUint32 aIapId);
       
    86 HBufC*      GetIapBearerTypeL(const TUint32 aAppDefaultApn, const TUint32 aAppDefaultApType);
    84 HBufC*      TranslateBearerInfoToNetworkAccessL(TConnMonBearerInfo aBearerInfo);
    87 HBufC*      TranslateBearerInfoToNetworkAccessL(TConnMonBearerInfo aBearerInfo);
    85 HBufC*      GetDefIapBearerTypeL(TUint32 aMidSuiteId);
    88 HBufC*      GetAppDefIapBearerTypeL(const TUint32 aAppDefaultApn);
    86 
    89 
    87 /*
    90 /*
    88  * Class:     com_nokia_mj_impl_properties_mobinfo_MobileInfoProperties
    91  * Class:     com_nokia_mj_impl_properties_mobinfo_MobileInfoProperties
    89  * Method:    _getProperty
    92  * Method:    _getProperty
    90  * Signature: (I)Ljava/lang/String;
    93  * Signature: (I)Ljava/lang/String;
    93 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
    94 //    JNI function called from java side from MobileInfoProperties class.
    97 //    JNI function called from java side from MobileInfoProperties class.
    95 //    Each mobinfo java property implementation calls the getPropertyMsid()
    98 //    Each mobinfo java property implementation calls the getPropertyMsid()
    96 //    function of the MobileInfoProperties class.
    99 //    function of the MobileInfoProperties class.
    97 //    @param aProperty name of the actual property
   100 //    @param aProperty name of the actual property
       
   101 //    @param aAppDefaultApn application default access point id
       
   102 //    @param aAppDefaultApType application default access point type ( SNAP, IAP)
    98 //    @param aAppDefaultApn Application default apn
   103 //    @param aAppDefaultApn Application default apn
    99 // -----------------------------------------------------------------------------
   104 // -----------------------------------------------------------------------------
   100 JNIEXPORT jstring JNICALL
   105 JNIEXPORT jstring JNICALL
   101 Java_com_nokia_mj_impl_properties_mobinfo_MobileInfoProperties__1getPropertyApn
   106 Java_com_nokia_mj_impl_properties_mobinfo_MobileInfoProperties__1getPropertyApn
   102 (JNIEnv* aJni, jclass, jint aProperty, jint aAppDefaultApn)
   107 (JNIEnv* aJni, jclass, jint aProperty, jint aAppDefaultApn, jint aAppDefaultApType)
   103 {
   108 {
   104     LOG1(ESOCKET, EInfo, "MOBINFO + getPropertyMsid(), msid: %D", aAppDefaultApn);
   109     LOG1(ESOCKET, EInfo, "MOBINFO + getPropertyMsid(), msid: %D", aAppDefaultApn);
   105     HBufC* property = NULL;
   110     HBufC* property = NULL;
   106     jstring str = NULL;
   111     jstring str = NULL;
   107     property = GetProperty(aProperty, aAppDefaultApn);
   112     property = GetProperty(aProperty, aAppDefaultApn,aAppDefaultApType);
   108     if (NULL != property)
   113     if (NULL != property)
   109     {
   114     {
   110         LOG(ESOCKET,EInfo,"_getPropertyApn, property is not null");
   115         LOG(ESOCKET,EInfo,"_getPropertyApn, property is not null");
   111         str = java::util::S60CommonUtils::NativeToJavaString(*aJni, property->Des());
   116         str = java::util::S60CommonUtils::NativeToJavaString(*aJni, property->Des());
   112         LOG(ESOCKET, EInfo,"MOBINFO - after nativetojavastring");
   117         LOG(ESOCKET, EInfo,"MOBINFO - after nativetojavastring");
   122 {
   127 {
   123     LOG1(ESOCKET, EInfo, "MOBINFO Key: %d", aKey);
   128     LOG1(ESOCKET, EInfo, "MOBINFO Key: %d", aKey);
   124     HBufC* property = NULL;
   129     HBufC* property = NULL;
   125     jstring str = NULL;
   130     jstring str = NULL;
   126 
   131 
   127     property = GetProperty(aKey,NULL);
   132     property = GetProperty(aKey,NULL,0);
   128     if (NULL != property)
   133     if (NULL != property)
   129     {
   134     {
   130         TPtrC data(property->Des());
   135         TPtrC data(property->Des());
   131         str = java::util::S60CommonUtils::NativeToJavaString(*aJni, data);
   136         str = java::util::S60CommonUtils::NativeToJavaString(*aJni, data);
   132         delete property;
   137         delete property;
   133     }
   138     }
   134     return str;
   139     return str;
   135 }
   140 }
   136 
   141 
   137 HBufC* GetProperty(const TInt aProperty, const TUint32 aAppDefaultApn)
   142 HBufC* GetProperty(const TInt aProperty, const TUint32 aAppDefaultApn, const TUint32 aAppDefaultApType)
   138 {
   143 {
   139     JELOG2(ESOCKET);
   144     JELOG2(ESOCKET);
   140     LOG(ESOCKET, EInfo, "MOBINFO + GetProperty()");
   145     LOG(ESOCKET, EInfo, "MOBINFO + GetProperty()");
   141     HBufC* property = NULL;
   146     HBufC* property = NULL;
   142     TInt err;
   147     TInt err;
   146     case DATEFORMAT:
   151     case DATEFORMAT:
   147     case TIMEFORMAT:
   152     case TIMEFORMAT:
   148         TRAP(err, property = GetDateTimePropertyL(aProperty));
   153         TRAP(err, property = GetDateTimePropertyL(aProperty));
   149         break;
   154         break;
   150     case NETWORK_ACCESS:
   155     case NETWORK_ACCESS:
   151         TRAP(err, property = GetNetworkAccessL(aAppDefaultApn));
   156         TRAP(err, property = GetNetworkAccessL(aAppDefaultApn,aAppDefaultApType));
   152         LOG(ESOCKET, EInfo,"after GetNetworkAccessL");
   157         LOG(ESOCKET, EInfo,"after GetNetworkAccessL");
   153         break;
   158         break;
   154 
   159 
   155     default:
   160     default:
   156         TRAP(err, property = GetTelephonyPropertyL(aProperty));
   161         TRAP(err, property = GetTelephonyPropertyL(aProperty));
   783 
   788 
   784 // ---------------------------------------------------------------------------
   789 // ---------------------------------------------------------------------------
   785 // Get type network access of currently used active connection
   790 // Get type network access of currently used active connection
   786 // @return network access, ownership hand over
   791 // @return network access, ownership hand over
   787 // ---------------------------------------------------------------------------
   792 // ---------------------------------------------------------------------------
   788 HBufC* GetNetworkAccessL(TUint32 aAppDefaultApn)
   793 HBufC* GetNetworkAccessL(TUint32 aAppDefaultApn, const TUint32 aAppDefaultApType)
   789 {
   794 {
   790     LOG(ESOCKET, EInfo, "MOBINFO + GetNetworkAccessL");
   795     LOG(ESOCKET, EInfo, "MOBINFO + GetNetworkAccessL");
   791     HBufC* bearerType = NULL;
   796     HBufC* bearerType = NULL;
   792     TUint32 iapId = GetUsedIapL();
   797     TUint32 iapId = GetUsedIapL();
   793     if (iapId == 0)
   798     if (iapId != 0)
   794     {
   799     {
   795         bearerType = GetDefIapBearerTypeL(aAppDefaultApn);
   800         // active connection present, opened by MIDlet.
       
   801         bearerType = GetBearerTypeL(iapId);
       
   802 
   796     }
   803     }
   797     else
   804     else
   798     {
   805     {
   799         bearerType = GetBearerTypeL(iapId);
   806         // if there is no active connection by the application, return the app default bearer type.
       
   807         if (aAppDefaultApType == 3)
       
   808         {
       
   809             // app default is IAP
       
   810             bearerType = GetAppDefIapBearerTypeL(aAppDefaultApn);
       
   811 
       
   812         }
       
   813         else
       
   814         {
       
   815             bearerType = GetIapBearerTypeL(aAppDefaultApn,aAppDefaultApType);
       
   816         }
       
   817 
   800     }
   818     }
   801     LOG(ESOCKET, EInfo, "MOBINFO - GetNetworkAccessL");
   819     LOG(ESOCKET, EInfo, "MOBINFO - GetNetworkAccessL");
   802     return bearerType;
   820     return bearerType;
       
   821 }
       
   822 
       
   823 
       
   824 //// ---------------------------------------------------------------------------
       
   825 //// Check if device default is set (SNAP or IAP)
       
   826 //// @return true if device default defined, else false
       
   827 //// ---------------------------------------------------------------------------
       
   828 
       
   829 bool isDeviceDefaultPresentL()
       
   830 {
       
   831     TCmDefConnType type;
       
   832     RCmManager * mgr = new(ELeave) RCmManager();
       
   833     mgr->OpenL();
       
   834 
       
   835     TCmDefConnValue obj;
       
   836     mgr->ReadDefConnL(obj);
       
   837     type = obj.iType;
       
   838 
       
   839     if ((type!=ECmDefConnConnectionMethod) && (type!=ECmDefConnDestination))
       
   840     {
       
   841         // device default is other than SNAP or IAP
       
   842         return false;
       
   843     }
       
   844     else
       
   845     {
       
   846         return true;
       
   847 
       
   848     }
       
   849 
       
   850 
       
   851 
       
   852 }
       
   853 
       
   854 //// ---------------------------------------------------------------------------
       
   855 //// Get bearer type of Access point ID
       
   856 //// @return bearer type Acess point ID
       
   857 //// ---------------------------------------------------------------------------
       
   858 
       
   859 HBufC* GetIapBearerTypeL(const TUint32 aAppDefaultApn, const TUint32 aAppDefaultApType)
       
   860 {
       
   861 
       
   862     LOG(ESOCKET, EInfo, "MOBINFO + GetIapBearerTypeL()");
       
   863     RConnectionMonitor      monitor;
       
   864     TUint                   connectionCount(0);
       
   865     TUint                   iapId(0);
       
   866     TRequestStatus          status(KErrNone);
       
   867     HBufC*                  bearerType(NULL);
       
   868     TUint                   connectionId(0);
       
   869     TUint                   subConnectionCount(0);
       
   870     TConnMonBearerInfo      bearerInfo(EBearerInfoUnknown);
       
   871     bool                    flag = false;
       
   872     TUint                   connIdx = 1;
       
   873 
       
   874     User::LeaveIfError(monitor.ConnectL());
       
   875     CleanupClosePushL(monitor);
       
   876 
       
   877     status = KRequestPending;
       
   878     monitor.GetConnectionCount(connectionCount, status);
       
   879     User::WaitForRequest(status);
       
   880     User::LeaveIfError(status.Int());
       
   881     LOG1(ESOCKET, EInfo, "MOBINFO: GetIapBearerTypeL: Count of active connections: %D", connectionCount);
       
   882 
       
   883     // Go through all connections
       
   884     for (connIdx = 1; connIdx <= connectionCount;  ++connIdx)
       
   885     {
       
   886 
       
   887         connectionId = 0;
       
   888         subConnectionCount = 0;
       
   889         flag = false;
       
   890 
       
   891         // Get connection ID
       
   892         monitor.GetConnectionInfo(connIdx, connectionId, subConnectionCount);
       
   893         User::LeaveIfError(connectionId);
       
   894         // Get connection IAP ID
       
   895         status = KRequestPending;
       
   896         monitor.GetUintAttribute(connectionId, 0, KIAPId, iapId, status);
       
   897         User::WaitForRequest(status);
       
   898         User::LeaveIfError(status.Int());
       
   899         LOG1(ESOCKET, EInfo, "MOBINFO: GetIapBearerTypeL Connection 's IAP ID found: %D", iapId);
       
   900         if (aAppDefaultApType == 2)
       
   901         {
       
   902             LOG(ESOCKET, EInfo, "MOBINFO: Matching MIDlet defined SNAP to active IAP ID ");
       
   903             // Midlet has a SNAP defined, so check if the active IAP is under this SNAP.
       
   904             flag = ConnectionManager::isIapDefault(iapId, aAppDefaultApn,false);
       
   905             if (!flag)
       
   906             {
       
   907                 continue;  // active access point doesn't belong to MIDlet SNAP, check the next active access point.
       
   908             }
       
   909             else
       
   910             {
       
   911                 break;
       
   912             }
       
   913         }
       
   914         else
       
   915         {
       
   916             // No SNAP defined for the MIDlet, check for system default SNAP/IAP.
       
   917             if (isDeviceDefaultPresentL())
       
   918             {
       
   919                 LOG(ESOCKET, EInfo, "MOBINFO: Matching device default to active IAP ID ");
       
   920                 flag = ConnectionManager::isIapDefault(iapId, 0, true);
       
   921                 if (!flag)
       
   922                 {
       
   923                     continue;  // active access point doesn't belong to MIDlet SNAP, check the next active access point.
       
   924                 }
       
   925                 else
       
   926                 {
       
   927                     break;
       
   928                 }
       
   929             }
       
   930             else
       
   931             {
       
   932                 LOG(ESOCKET, EInfo, "MOBINFO: Returning the bearer type of first active IAP ");
       
   933                 flag = true;
       
   934                 break; // no MIDlet SNAP, no device default, select this access point and return the bearer type
       
   935 
       
   936             }
       
   937         }
       
   938 
       
   939     } // end of for loop
       
   940 
       
   941     if (flag)
       
   942     {
       
   943         // we did not reach end of active connections, one of the conditions matched , find the bearer type
       
   944         status = KRequestPending;
       
   945         monitor.GetIntAttribute(connectionId,
       
   946                                 0,
       
   947                                 KBearerInfo,
       
   948                                 (TInt&)bearerInfo,
       
   949                                 status);
       
   950         User::WaitForRequest(status);
       
   951         User::LeaveIfError(status.Int());
       
   952 
       
   953         // Translate bearer type to type of network access
       
   954         bearerType = TranslateBearerInfoToNetworkAccessL(bearerInfo);
       
   955     }
       
   956     CleanupStack::PopAndDestroy(&monitor);
       
   957     if (bearerType == NULL)
       
   958     {
       
   959         // No active connection (or) active IAP didn't match the conditions
       
   960         bearerType = KNetworkAccessNa().AllocL();
       
   961     }
       
   962     return bearerType;
       
   963 
       
   964 
   803 }
   965 }
   804 
   966 
   805 //// ---------------------------------------------------------------------------
   967 //// ---------------------------------------------------------------------------
   806 //// Get currently used Access point ID
   968 //// Get currently used Access point ID
   807 //// @return currently used Acess point ID
   969 //// @return currently used Acess point ID
  1045 
  1207 
  1046 
  1208 
  1047 
  1209 
  1048 // --------------------------------------------------------------------
  1210 // --------------------------------------------------------------------
  1049 // Get network access type of default access point set in MIDlet settings
  1211 // Get network access type of default access point set in MIDlet settings
  1050 // @param aAppDefaultApn MIDlet suite ID
  1212 // @param aAppDefaultApn MIDlet default IAP
  1051 // @return network access type, ownership hand over
  1213 // @return network access type, ownership hand over
  1052 HBufC* GetDefIapBearerTypeL(TUint32 aAppDefaultApn)
  1214 HBufC* GetAppDefIapBearerTypeL(const TUint32 aAppDefaultApn)
  1053 {
  1215 {
  1054     LOG(ESOCKET, EInfo, "MOBINFO + GetDefIapBearerTypeL");
  1216     LOG1(ESOCKET, EInfo, "MOBINFO + GetAppDefIapBearerTypeL aId = %d ", aAppDefaultApn);
  1055     ELOG1(ESOCKET,  "GetDefIapBearerTypeL %d", aAppDefaultApn);
       
  1056     HBufC* bearerType(NULL);
  1217     HBufC* bearerType(NULL);
  1057     // MAPNSettings* apnTable = GetAPNSettingsLC(KAPNSettingsVersion);
  1218 
  1058     //TUint32 apn = apnTable->GetAPNIdL( aMidSuiteId );
       
  1059     //CleanupStack::PopAndDestroy(); //apnTable
       
  1060     LOG1(ESOCKET, EInfo, "MIDlet specific IAP ID gotten: %D", aAppDefaultApn);
       
  1061     if (aAppDefaultApn == 0 || aAppDefaultApn == (TUint32)-1)
  1219     if (aAppDefaultApn == 0 || aAppDefaultApn == (TUint32)-1)
  1062     {
  1220     {
  1063         bearerType = KNetworkAccessNa().AllocL();
  1221         bearerType = KNetworkAccessNa().AllocL();
  1064     }
  1222     }
  1065     else
  1223     else
  1066     {
  1224     {
       
  1225 
  1067         RCmManager localCmManager;
  1226         RCmManager localCmManager;
  1068         localCmManager.OpenL();
  1227         localCmManager.OpenL();
  1069         TUint32 tmpval = localCmManager.GetConnectionMethodInfoIntL(aAppDefaultApn,ECmBearerType);
  1228         TUint32 iap = aAppDefaultApn;
       
  1229         TUint32 tmpval = localCmManager.GetConnectionMethodInfoIntL(iap,ECmBearerType);
  1070         ELOG1(ESOCKET,  "GetConnectionMethodInfoIntL: %d", tmpval);
  1230         ELOG1(ESOCKET,  "GetConnectionMethodInfoIntL: %d", tmpval);
  1071         switch (tmpval)
  1231         switch (tmpval)
  1072         {
  1232         {
  1073         case KUidHSCSDBearerType:
  1233         case KUidHSCSDBearerType:
  1074             bearerType = KNetworkAccessCSD().AllocL();
  1234             bearerType = KNetworkAccessCSD().AllocL();
  1082 
  1242 
  1083             /* Bearer type LAN,LANModem currently not supported by cmmanager */
  1243             /* Bearer type LAN,LANModem currently not supported by cmmanager */
  1084         default :
  1244         default :
  1085             bearerType = KNetworkAccessNa().AllocL();
  1245             bearerType = KNetworkAccessNa().AllocL();
  1086             break;
  1246             break;
  1087 
  1247         }
  1088 
  1248     }
  1089         }
  1249     LOG(ESOCKET, EInfo, "MOBINFO - GetAppDefIapBearerTypeL");
  1090 
       
  1091     }
       
  1092     LOG(ESOCKET, EInfo, "MOBINFO - GetDefIapBearerTypeL");
       
  1093     return bearerType;
  1250     return bearerType;
  1094 }
  1251 }