public void invoke( JSExtensionRequest request, JSExtensionResponse response ) throws WidgetException {
String method = request.getMethodName();
Object[] args = request.getArgs();
String msg = "";
int code = JSExtensionReturnValue.SUCCESS;
JSONObject data = new JSONObject();
JSONObject returnValue = null;
if( !SUPPORTED_METHODS.contains( method ) ) {
throw new WidgetException("Undefined method: " + method);
}
try {
if( method.equals( FUNCTION_HAS_PERMISSION ) ) {
String module = (String) args[ 0 ];
data.put( ARG_MODULE, module );
data.put( FUNCTION_HAS_PERMISSION, hasPermission( module ) );
} else if( method.equals( FUNCTION_HAS_CAPABILITY ) ) {
String capability = (String) args[ 0 ];
data.put( ARG_CAPABILITY, capability );
data.put( FUNCTION_HAS_CAPABILITY, hasCapability( capability ) );
} else if( method.equals( FUNCTION_HAS_DATA_COVERAGE ) ) {
data.put( FUNCTION_HAS_DATA_COVERAGE, hasDataCoverage() );
} else if( method.equals( FUNCTION_IS_MASS_STORAGE_ACTIVE ) ) {
data.put( FUNCTION_IS_MASS_STORAGE_ACTIVE, isMassStorageActive() );
} else if( method.equals( FUNCTION_SET_HOME_SCREEN ) ) {
String picture = (String) args[ 0 ];
data.put( ARG_PICTURE, picture );
setHomeScreenBackground( picture );
} else if( method.equals( SOFTWARE_VERSION ) ) {
data.put( SOFTWARE_VERSION, getSoftwareVersion() );
} else if( method.equals( SCRIPT_API_VERSION ) ) {
data.put( SCRIPT_API_VERSION, getSoftwareVersion() );
} else if( method.equals( MODEL ) ) {
data.put( MODEL, getModel() );
} else if ( method.equals( FUNCTION_GET ) ) {
data.put( FUNCTION_HAS_CAPABILITY, checkAllCapabilties() );
data.put( SOFTWARE_VERSION, getSoftwareVersion() );
data.put( FUNCTION_HAS_PERMISSION, checkAllPermissions() );
data.put( MODEL, getModel() );
data.put( FUNCTION_HAS_DATA_COVERAGE, hasDataCoverage() );
data.put( SCRIPT_API_VERSION, getSoftwareVersion() );
data.put( FUNCTION_IS_MASS_STORAGE_ACTIVE, isMassStorageActive() );
}
} catch( Exception e ) {
msg = e.getMessage();
code = JSExtensionReturnValue.FAIL;
}
returnValue = new JSExtensionReturnValue( msg, code, data ).getReturnValue();
response.setPostData( returnValue.toString().getBytes() );
}