javaextensions/mobinfo/javasrc.s60/com/nokia/mj/impl/properties/mobinfo/MobileInfoProperties.java
branchRCL_3
changeset 19 04becd199f91
child 23 98ccebc37403
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.mj.impl.properties.mobinfo;
       
    20 
       
    21 import java.util.Hashtable;
       
    22 
       
    23 import com.nokia.mj.impl.rt.support.SystemPropertyProvider;
       
    24 import com.nokia.mj.impl.rt.support.Jvm;
       
    25 import com.nokia.mj.impl.utils.Logger;
       
    26 import com.nokia.mj.impl.connectionmanager.ConnectionManager;
       
    27 import com.nokia.mj.impl.connectionmanager.AccessPoint;
       
    28 import com.nokia.mj.impl.rt.support.ApplicationInfo;
       
    29 import com.nokia.mj.impl.rt.support.ApplicationUtils;
       
    30 import com.nokia.mj.impl.utils.Uid;
       
    31 
       
    32 /**
       
    33  * Provides system properties related to Mobile Info
       
    34  */
       
    35 public class MobileInfoProperties implements SystemPropertyProvider
       
    36 {
       
    37     static
       
    38     {
       
    39         try
       
    40         {
       
    41             Jvm.loadSystemLibrary("javamobinfo");
       
    42         }
       
    43         catch (Exception e)
       
    44         {
       
    45             Logger.ELOG(Logger.ESOCKET, "MOBINFO: Unable to load javamobinfo");
       
    46         }
       
    47     }
       
    48 
       
    49     // Strings that are exposed as system properties.
       
    50     private static final String NETWORK_ACCESS = "com.nokia.network.access";
       
    51 
       
    52     private static final String BATTERY_LEVEL = "com.nokia.mid.batterylevel";
       
    53 
       
    54     private static final String COUNTRY_CODE = "com.nokia.mid.countrycode";
       
    55 
       
    56     private static final String IMEI = "com.nokia.mid.imei";
       
    57 
       
    58     static final String IMSI = "com.nokia.mid.imsi";
       
    59 
       
    60     private static final String NETWORK_AVAILABILITY = "com.nokia.mid.networkavailability";
       
    61 
       
    62     private static final String NETWORK_ID = "com.nokia.mid.networkid";
       
    63 
       
    64     private static final String NETWORK_SIGNAL = "com.nokia.mid.networksignal";
       
    65 
       
    66     private static final String EMAIL_RECIEVE_SETTINGS = "com.nokia.mid.settings.email-receive-protocol";
       
    67 
       
    68     private static final String EMAIL_SEND_SETTINGS = "com.nokia.mid.settings.email-send-protocol";
       
    69 
       
    70     private static final String CELLID = "com.nokia.mid.cellid";
       
    71 
       
    72     static final String MSISDN = "com.nokia.mid.msisdn";
       
    73 
       
    74     private static final String DATEFORMAT = "com.nokia.mid.dateformat";
       
    75 
       
    76     private static final String TIMEFORMAT = "com.nokia.mid.timeformat";
       
    77 
       
    78     private static final String NETWORKSTATUS = "com.nokia.mid.networkstatus";
       
    79 
       
    80     private static final int APP_DEFAULT_APN_NOT_SPECIFIED = -1;
       
    81 
       
    82     // Constants associated with the strings
       
    83     private static final int NETWORK_ACCESS_V = 1;
       
    84 
       
    85     private static final int BATTERY_LEVEL_V = 2;
       
    86 
       
    87     private static final int COUNTRY_CODE_V = 3;
       
    88 
       
    89     private static final int IMEI_V = 4;
       
    90 
       
    91     private static final int IMSI_V = 5;
       
    92 
       
    93     private static final int NETWORK_AVAILABILITY_V = 6;
       
    94 
       
    95     private static final int NETWORK_ID_V = 7;
       
    96 
       
    97     private static final int NETWORK_SIGNAL_V = 8;
       
    98 
       
    99     private static final int EMAIL_RECIEVE_SETTINGS_V = 9;
       
   100 
       
   101     private static final int EMAIL_SEND_SETTINGS_V = 10;
       
   102 
       
   103     private static final int CELLID_V = 11;
       
   104 
       
   105     private static final int MSISDN_V = 12;
       
   106 
       
   107     private static final int DATEFORMAT_V = 13;
       
   108 
       
   109     private static final int TIMEFORMAT_V = 14;
       
   110 
       
   111     private static final int NETWORKSTATUS_V = 15;
       
   112 
       
   113     private static Hashtable iPropertyKeys;
       
   114 
       
   115     static
       
   116     {
       
   117         iPropertyKeys = new Hashtable();
       
   118         iPropertyKeys.put(NETWORK_ACCESS,       new Integer(NETWORK_ACCESS_V));
       
   119         iPropertyKeys.put(BATTERY_LEVEL,        new Integer(BATTERY_LEVEL_V));
       
   120         iPropertyKeys.put(COUNTRY_CODE,         new Integer(COUNTRY_CODE_V));
       
   121         iPropertyKeys.put(IMEI,                 new Integer(IMEI_V));
       
   122         iPropertyKeys.put(IMSI,                 new Integer(IMSI_V));
       
   123         iPropertyKeys.put(NETWORK_AVAILABILITY, new Integer(NETWORK_AVAILABILITY_V));
       
   124         iPropertyKeys.put(NETWORK_ID,           new Integer(NETWORK_ID_V));
       
   125         iPropertyKeys.put(NETWORK_SIGNAL,       new Integer(NETWORK_SIGNAL_V));
       
   126         iPropertyKeys.put(EMAIL_RECIEVE_SETTINGS, new Integer(EMAIL_RECIEVE_SETTINGS_V));
       
   127         iPropertyKeys.put(EMAIL_SEND_SETTINGS,  new Integer(EMAIL_SEND_SETTINGS_V));
       
   128         iPropertyKeys.put(CELLID,               new Integer(CELLID_V));
       
   129         iPropertyKeys.put(MSISDN,               new Integer(MSISDN_V));
       
   130         iPropertyKeys.put(DATEFORMAT,           new Integer(DATEFORMAT_V));
       
   131         iPropertyKeys.put(TIMEFORMAT,           new Integer(TIMEFORMAT_V));
       
   132         iPropertyKeys.put(NETWORKSTATUS,        new Integer(NETWORKSTATUS_V));
       
   133     }
       
   134 
       
   135     public String getProperty(String aKey)
       
   136     {
       
   137         // enforce security
       
   138         ApplicationUtils appUtils = ApplicationUtils.getInstance();
       
   139         appUtils.checkPermission(new MobileInfoPermission(aKey, "read"));
       
   140 
       
   141         int value = ((Integer)iPropertyKeys.get(aKey)).intValue();
       
   142         Uid appSuiteUid;
       
   143         ConnectionManager CmInstance = null;
       
   144         String result = null;
       
   145         // Only network access seems to have another way to handle it.
       
   146         if (aKey.equals(EMAIL_RECIEVE_SETTINGS)
       
   147                 || aKey.equals(EMAIL_SEND_SETTINGS))
       
   148         {
       
   149             return null;
       
   150         }
       
   151         if (aKey.equals(NETWORK_ACCESS))
       
   152         {
       
   153             // get application suite uid
       
   154             try
       
   155             {
       
   156                 appSuiteUid = ApplicationInfo.getInstance().getSuiteUid();
       
   157                 CmInstance = ConnectionManager.getInstance();
       
   158                 if (CmInstance != null)
       
   159                 {
       
   160                     AccessPoint apn = CmInstance.getApplicationDefault(appSuiteUid);
       
   161                     if (apn != null)
       
   162                     {
       
   163                         if (apn.getType() == AccessPoint.NAP_IAP) // IAP ID
       
   164                         {
       
   165                             result = _getPropertyApn(NETWORK_ACCESS_V, apn.getNapId());
       
   166                         }
       
   167                         else
       
   168                         {
       
   169                             result = _getPropertyApn(NETWORK_ACCESS_V, APP_DEFAULT_APN_NOT_SPECIFIED);
       
   170                         }
       
   171                     }
       
   172                     else
       
   173                     {
       
   174                         result = _getPropertyApn(NETWORK_ACCESS_V, APP_DEFAULT_APN_NOT_SPECIFIED);
       
   175                     }
       
   176                 }
       
   177                 else
       
   178                 {
       
   179                     result = _getPropertyApn(NETWORK_ACCESS_V, APP_DEFAULT_APN_NOT_SPECIFIED);
       
   180                 }
       
   181             }
       
   182             catch (Exception e)
       
   183             {
       
   184                 Logger.LOG(Logger.ESOCKET, Logger.EInfo,"MobilInfoProperties :: getSuiteUid exception ");
       
   185                 result = _getPropertyApn(NETWORK_ACCESS_V, APP_DEFAULT_APN_NOT_SPECIFIED);
       
   186             }
       
   187             return result;
       
   188         }
       
   189         else
       
   190         {
       
   191             return _getProperty(value);
       
   192         }
       
   193     }
       
   194 
       
   195     public boolean isStatic(String aKey)
       
   196     {
       
   197         if (aKey.equals(IMEI) || aKey.equals(IMSI))
       
   198         {
       
   199             return true;
       
   200         }
       
   201         return false;
       
   202     }
       
   203 
       
   204     private native String _getProperty(int value);
       
   205     private static native String _getPropertyApn(int property, int aAppDefaultApn);
       
   206 
       
   207 }