javaruntimes/midp/runtime/javasrc/javax/microedition/midlet/MIDlet.java
branchRCL_3
changeset 77 7cee158cb8cd
parent 60 6c158198356e
child 83 26b2b12093af
equal deleted inserted replaced
71:d5e927d5853b 77:7cee158cb8cd
    23 
    23 
    24 import com.nokia.mj.impl.rt.ui.ConfirmData;
    24 import com.nokia.mj.impl.rt.ui.ConfirmData;
    25 import com.nokia.mj.impl.rt.ui.RuntimeUi;
    25 import com.nokia.mj.impl.rt.ui.RuntimeUi;
    26 import com.nokia.mj.impl.rt.ui.RuntimeUiFactory;
    26 import com.nokia.mj.impl.rt.ui.RuntimeUiFactory;
    27 
    27 
       
    28 import com.nokia.mj.impl.rt.midp.SchemeHandlerBase;
       
    29 
    28 import com.nokia.mj.impl.rt.support.ApplicationInfo;
    30 import com.nokia.mj.impl.rt.support.ApplicationInfo;
    29 
    31 
    30 import com.nokia.mj.impl.security.midp.authorization.AccessControllerFactoryImpl;
    32 import com.nokia.mj.impl.security.midp.authorization.AccessControllerFactoryImpl;
    31 import com.nokia.mj.impl.security.midp.authorization.AccessControllerImpl;
    33 import com.nokia.mj.impl.security.midp.authorization.AccessControllerImpl;
    32 import com.nokia.mj.impl.security.utils.SecurityPromptMessage;
    34 import com.nokia.mj.impl.security.utils.SecurityPromptMessage;
    33 
    35 
    34 import com.nokia.mj.impl.utils.Id;
    36 import com.nokia.mj.impl.utils.Id;
    35 import com.nokia.mj.impl.utils.Logger;
    37 import com.nokia.mj.impl.utils.Logger;
       
    38 
    36 
    39 
    37 /**
    40 /**
    38  * A class to be extended by the MIDlet applcation. See MIDP spec for
    41  * A class to be extended by the MIDlet applcation. See MIDP spec for
    39  * further details.
    42  * further details.
    40  */
    43  */
    54     /**
    57     /**
    55      * For allowing of MIDlet constructor to be called only once.
    58      * For allowing of MIDlet constructor to be called only once.
    56      */
    59      */
    57     private static boolean mConstructionAllowed = true;
    60     private static boolean mConstructionAllowed = true;
    58 
    61 
       
    62     private static final int DOMAIN_MANUFACTURER_OR_OPERATOR = 1;
       
    63 
    59     /*** ----------------------------- PUBLIC ------------------------------ */
    64     /*** ----------------------------- PUBLIC ------------------------------ */
    60 
    65 
    61     /**
    66     /**
    62      * For checking if MIDlet is allowed to do some protected action.
    67      * For checking if MIDlet is allowed to do some protected action.
    63      * @see MIDP spec for further details.
    68      * @see MIDP spec for further details.
   137     public final boolean platformRequest(String url)
   142     public final boolean platformRequest(String url)
   138     throws ConnectionNotFoundException
   143     throws ConnectionNotFoundException
   139     {
   144     {
   140         Logger.PLOG(Logger.EJavaRuntime,
   145         Logger.PLOG(Logger.EJavaRuntime,
   141                     "MIDlet.platformRequest(): " + url);
   146                     "MIDlet.platformRequest(): " + url);
       
   147 
   142         if (null == url)
   148         if (null == url)
   143         {
   149         {
   144             throw new NullPointerException(
   150             throw new NullPointerException(
   145                 "URL is null");
   151                 "URL is null");
   146         }
   152         }
   151         if (true == url.equals(""))
   157         if (true == url.equals(""))
   152         {
   158         {
   153             return false;
   159             return false;
   154         }
   160         }
   155 
   161 
       
   162         ApplicationInfo appInfo = ApplicationInfo.getInstance();
       
   163         String domain = appInfo.getProtectionDomain();
       
   164 
       
   165         // Handling for java scheme.
       
   166         /*if (url.startsWith("java://"))
       
   167         {
       
   168             String handlerName = parseHandlerName(url);
       
   169 
       
   170             if (handlerName.equals("taskmanager"))
       
   171             {
       
   172                 // Check application is bound either Manufacturer or Operator domain.
       
   173                 enforceSecurityDomain(DOMAIN_MANUFACTURER_OR_OPERATOR, domain);
       
   174             }
       
   175 
       
   176             return invokeSchemeHandler(handlerName, url);
       
   177         }*/
       
   178 
   156         // If the platform request is used to start arbitrary native application,
   179         // If the platform request is used to start arbitrary native application,
   157         // check that MIDlet is in manufacturer or operator domain
   180         // check that MIDlet is in manufacturer or operator domain
   158         if (startsArbitraryNativeApp(url))
   181         if (startsArbitraryNativeApp(url))
   159         {
   182         {
   160             ApplicationInfo appInfo = ApplicationInfo.getInstance();
   183             enforceSecurityDomain(DOMAIN_MANUFACTURER_OR_OPERATOR, domain);
   161             String domain = appInfo.getProtectionDomain();
   184         }
   162             if ((ApplicationInfo.MANUFACTURER_DOMAIN.equals(domain) != true) &&
       
   163                     (ApplicationInfo.OPERATOR_DOMAIN.equals(domain) != true))
       
   164             {
       
   165                 Logger.WLOG(Logger.EJavaRuntime,
       
   166                             "Only manufacturer or operator domain MIDlets can start arbitrary native apps.");
       
   167 
       
   168                 throw new ConnectionNotFoundException(
       
   169                     "Request allowed only for manufacturer or operator MIDlets");
       
   170             }
       
   171         }
       
   172 
       
   173 
   185 
   174         Logger.ILOG(Logger.EJavaRuntime,
   186         Logger.ILOG(Logger.EJavaRuntime,
   175                     "Before handleConfirmationNote()");
   187                     "Before handleConfirmationNote()");
   176 
   188 
   177         // Ask from the user if it is allowed to do the request.
   189         // Ask from the user if it is allowed to do the request.
   360         }
   372         }
   361 
   373 
   362         return false;
   374         return false;
   363     }
   375     }
   364 
   376 
       
   377     private String parseHandlerName(String url) throws ConnectionNotFoundException
       
   378     {
       
   379         // Parse handler name from URL. Remove java:// prefix.
       
   380         String handlerName = url.substring(7).trim();
       
   381 
       
   382         // name format: handlername?query
       
   383         int nameEndIndex = handlerName.indexOf('?');
       
   384 
       
   385         if (nameEndIndex != -1)
       
   386         {
       
   387             handlerName = handlerName.substring(0, nameEndIndex);
       
   388             return handlerName;
       
   389         }
       
   390         else
       
   391         {
       
   392             throw new ConnectionNotFoundException("Handler not found for URL");
       
   393         }
       
   394     }
       
   395 
       
   396     private boolean invokeSchemeHandler(String handlerName, String url)
       
   397         throws ConnectionNotFoundException
       
   398     {
       
   399         try
       
   400         {
       
   401             // Avoid loading whatever class from the system using handler
       
   402             // as package name.
       
   403             Class clazz = Class.forName("com.nokia.mj.impl.rt." + handlerName + ".SchemeHandler");
       
   404 
       
   405             SchemeHandlerBase handler = (SchemeHandlerBase)clazz.newInstance();
       
   406 
       
   407             handler.execute(url);
       
   408             return false;  // No need to close MIDlet.
       
   409         }
       
   410         catch (Throwable t)
       
   411         {
       
   412             Logger.ELOG(Logger.EJavaRuntime, "Cannot invoke scheme handler: " + t.toString());
       
   413             // ClassNotFoundException, IllegalAccessException or InstantionException.
       
   414             throw new ConnectionNotFoundException("Handler not found for URL");
       
   415         }
       
   416     }
       
   417 
       
   418     private void enforceSecurityDomain(int type, String domain)
       
   419         throws ConnectionNotFoundException
       
   420     {
       
   421         if (DOMAIN_MANUFACTURER_OR_OPERATOR == type)
       
   422         {
       
   423             if ((ApplicationInfo.MANUFACTURER_DOMAIN.equals(domain) != true) &&
       
   424                     (ApplicationInfo.OPERATOR_DOMAIN.equals(domain) != true))
       
   425             {
       
   426                 Logger.WLOG(Logger.EJavaRuntime,
       
   427                             "Only manufacturer or operator domain MIDlets can invoke scheme");
       
   428 
       
   429                 throw new ConnectionNotFoundException(
       
   430                     "Request allowed only for manufacturer or operator MIDlets");
       
   431             }
       
   432         }
       
   433         else
       
   434         {
       
   435             Logger.ELOG(Logger.EJavaRuntime,
       
   436                         "Security enforcement failed: unknown domain category");
       
   437 
       
   438             throw new ConnectionNotFoundException(
       
   439                 "Security enforcement failed: unknown domain category");
       
   440         }
       
   441     }
       
   442 
   365     /*** ----------------------------- NATIVE ----------------------------- */
   443     /*** ----------------------------- NATIVE ----------------------------- */
   366 
   444 
   367     private native void _managePlatformRequest(String url);
   445     private native void _managePlatformRequest(String url);
   368 }
   446 }