Brew

  Home  Smartphone OS  Brew


“Brew job preparation guide for freshers and experienced candidates. Number of Brew frequently asked questions(FAQs) asked in many interviews”



78 Brew Questions And Answers

65⟩ How to allow the input of symbols in my text control?

Certain limited symbol entry is available by pressing a certain key (usually 1) multiple times. This set of symbols is OEM dependent. On the Kyocera 3035, the following symbols are available by pressing the '1' key multiple times: .&@,-':;?/"(). On the Sharp Z- 800, the following symbols are available by pressing the 1 key multiple times: .,@:!?/.

To allow a greater breadth of symbol entry in your text control, you must associate your text control to a soft key menu using ITEXTCTL_SetSoftKeyMenu(). The set of symbols available using this method are:

-.&'()_!?*#%":+<>=¿¡""/@,~{}$[]^;.

ITEXTCTL_SetSoftKeyMenu() adds an item to the Soft Key menu that allows the user to change the text entry mode (the text string for this item is the currently selected mode - for example, MultiTap). When it receives this command, the text control displays a menu allowing the user to select the new text entry mode. After the user selects the new mode, the text control is reactivated and the user may continue to enter text. When entering text, the user may press the Select Key to leave text-edit mode and activate the SoftKey Menu. While the Soft Key menu is active, the user may press the UP key to return to edit mode without making a menu selection.

The following is an example of how to allow multiple input modes in your text control:

// Create text control

ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_TEXTCTL,

(void **)&pMe->m_pIText);

if (pMe->m_pIText) {

// Create soft key menu

ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_SOFTKEYCTL,

(void **)&pMe->m_pISoftKey);

if (!pMe->m_pISoftKey) {

ITEXTCTL_Release (pMe->m_pIText);

pMe->m_pIText = NULL;

return FALSE;

}

}

else {

return FALSE;

}

// Set the soft key menu rectangle

IMENUCTL_SetRect(pMe->m_pISoftKey, &softKeyRect);

// Set text control title, size, properties, rectangle

ITEXTCTL_SetTitle(pMe->m_pIText, NULL, NULL, titleString);

ITEXTCTL_SetMaxSize(pMe->m_pIText, 100);

ITEXTCTL_SetProperties(pMe->m_pIText, TP_FRAME | TP_MULTILINE );

ITEXTCTL_SetRect(pMe->m_pIText, &rect);

// Initialize the softkey menu of the text control.

ITEXTCTL_SetSoftKeyMenu (pMe->m_pIText, pMe->m_pISoftKey);

// Set both the soft key and text control active.

IMENUCTL_SetActive(pMe->m_pISoftKey,TRUE);

ITEXTCTL_SetActive (pMe->m_pIText, TRUE);

In the app's HandleEvent function, you must handle the EVT_KEY and EVT_COMMAND

events as follows:

case EVT_COMMAND:

// Process EVT_COMMAND event - change of input mode

if((pMe->m_pIText != NULL) && ITEXTCTL_HandleEvent(pMe->m_pIText,

eCode, wParam, dwParam)) {

return TRUE;

}

return FALSE;

case EVT_KEY:

if ((pMe->m_pIText != NULL) && ITEXTCTL_HandleEvent(pMe->m_pIText,

EVT_KEY, wParam, dwParam)) {

//Event handled by text control

return TRUE;

}

if(pMe->m_pISoftKey != NULL && IMENUCTL_HandleEvent(

pMe->m_pISoftKey, EVT_KEY, wParam, dwParam)) {

//Event handled by menu control

return TRUE;

}

return FALSE;

 181 views

66⟩ How to check the status of my sockets and PPP connection?

We can check on the status of the PPP connection (active, inactive, opening or closing) using INETMGR_NetStatus().

NetState netState = NET_INVALID_STATE;

AEENetStats netStats;

netState = INETMGR_NetStatus (pINetMgr, &netStats);

We can use INETMGR_OnEvent() to monitor both the status of the PPP connection and socket connections. Refer to NetMgrEvent enum in AEENet.h for a list of all network and socket events.

// Register to receive Network and Socket events

INETMGR_OnEvent(piNet, (PFNNETMGREVENT)CheckNetStatus,

(void*)pMe, TRUE);

//Callback invoked when Network/Socket event is received

static void CheckNetStatus(void* cxt,

NetMgrEvent evt, uint32 dwData) {

SampleApp *pMe = (SampleApp*)cxt;

if(evt == NE_PPP) {

// network event. dwData = NetState enum value

// refer NetState data structure in BREW API Reference doc

}

if(evt == NE_SO_CLOSING || evt == NE_SO_CLOSED) {

// socket event - closing or closed.

// DwData is pointer to socket

}

… …

return;

}

 199 views

67⟩ Is it possible to transfer data between two phones?

Peer to peer connections between two phones have been found to be unreliable, failing when the phones are on the same subnet. It is best therefore to use a proxy server, transferring data between the phones using the server as a go between.

 192 views

68⟩ Can a BREW-enabled device be used as a server?

In addition to the obvious memory and performance limitations, it is not possible to listen on a socket connection when a BREW application is running on a phone. These factors make implementing a server on BREW difficult at best.

 182 views

69⟩ Is there any way to tell if a socket is already connected?

There are two ways to determine if a socket is connected. The easiest is to check the return value of ISOCKET_Connect(). When a socket is already connected, ISOCKET_Connect() will return EISCONN.

It is also possible to monitor the state of a socket connection by registering for the socket status change events NE_SO_CLOSING, and NE_SO_CLOSED with INETMGR_OnEvent(). Using this method, your application can avoid trying to connect an already connected socket.

For more information about network and socket events, including NE_SO_CLOSING and NE_SO_CLOSED, please refer to the following include file: AEENet.h.

For Example:

// Register to receive Network and Socket events

INETMGR_OnEvent(piNet, (PFNNETMGREVENT)CheckNetStatus,

(void*)pMe, TRUE);

//Callback invoked when Network/Socket event is received

static void CheckNetStatus(void* cxt, NetMgrEvent evt,

uint32 dwData)

{

SampleApp *pMe = (SampleApp*)cxt;

if(evt == NE_SO_CLOSING || evt == NE_SO_CLOSED) {

// flag set to false to indicate socket is disconnected

pMe->m_SocketConnected = FALSE;

ReleaseNetAndSocket(pMe);

}

if(evt == NE_SO_CONNECTED) {

// flag set to true to indicate socket is connected

pMe->m_SocketConnected = TRUE;

}

return;

}

 197 views

70⟩ Are there any restrictions on what value we can set my applications network linger time to?

The INETMGR_SetLinger() function is provided to give developers flexibility in designing their application. However, it is not recommended that you alter the OEM's chosen default linger time (usually 30 seconds), unless your application has a compelling reason to do so. Altering the default linger time in either direction may cause your application to fail TRUE BREW Testing, or carrier rejection of your application.

 200 views

71⟩ What precautions should we take when I invoke INETMGR_GetHostByName() to perform DNS lookup?

You must ensure that your app cancels its pending DNS callback, if any, using CALLBACK_Cancel() in all exit routes. This includes when the app is suspended and when the app is stopped (both via the End key and the Clear key).

For example, if you used the following code to lookup a DNS address:

CALLBACK_Init(&pMe->cbkLookup, GetHostByNameCB, pMe);

INETMGR_GetHostByName(pINetMgr,&pMe->dnsresult, hostName,

&pMe->cbkLookup);

You should use the following code to cancel the callback in all exit routes:

// Check if the callback can be cancelled. If NULL it has

// already happened and cannot be cancelled.

if(pMe->cbkLookup.pfnCancel != NULL) {

CALLBACK_Cancel(&pMe->cbkLookup);

}

The callback cancel code should be incorporated in the Suspend event handler code ( EVT_APP_SUSPEND), the app's FreeAppData function (which is called when the app is stopped, i.e. receives EVT_APP_STOP event), and in the Clear key event handler code (EVT_KEY and keycode AVK_CLR).

Note: Please note that your app will not pass TRUE BREW Testing if it does not properly cancel its pending DNS callback. Some symptoms that might indicate that your app is not canceling its p ending DNS callback are:,/p>

Phone crashes upon starting up app

Phone displays "Please Re-insert Battery" error upon starting up app

Both might imply that the previously running app did not cancel its pending DNS callback.

 224 views

72⟩ Why does connect callback not timeout when service is lost (while attempting to connect) or the server does not respond?

This is due to a bug in the BREW version 1.0.1 SDK - connect callback is not invoked under the following circumstances:

Service is lost while connect is being attempted

Server does not respond

As a workaround, you should implement a timer in association with the callback. If the connect callback does not occur in 30 seconds, you should timeout the connection.

For example:

// initialize pMe->connectCBInvoked = FALSE;

// Set timer for 30 seconds before invoking ISOCKET_Connect()

ISHELL_SetTimer(pMe->a.m_pIShell, 30000, ConnectTimeout_CB, (void *)pMe);

ISOCKET_Connect(pMe->m_pISocket, nodeINAddr, AEE_htons(USAGE_TEST_PORT),

SampleApp_ConnectCB, pMe);

// Set flag indicating connect CB was called

void SampleApp_ConnectCB(void *cxt, int err) {

SampleApp *pMe = (SampleApp*)cxt;

// Set flag indicating connect CB was called

pMe->connectCbInvoked = TRUE;

if (err) {

DisplayOutput((IApplet*)pMe, 3, "Connect failed!");

return;

}

DisplayOutput((IApplet*)pMe, 3, "Connected!");

}

// When timer expires, check if connect CB was invoked

static void ConnectTimeout_CB(void* cxt) {

SampleApp *pMe = (SampleApp *)cxt;

if(pMe->connectCbInvoked == FALSE) {

// Callback was not invoked within 30seconds - cancel connect callback

ISOCKET_Cancel(pMe->m_pISocket, 0, 0);

DisplayOutput((IApplet*) pMe, 3, "Connection timed out");

}

else {

// Callback invoked. Set flag to default value FALSE

pMe->connectCbInvoked = FALSE;

}

}

Note: Multiple TCP sockets are not supported on the Kyocera 3035. It allows one TCP socket and one UDP socket at a given time.

 212 views

74⟩ How to handle the case when we lose cellular coverage?

When the phone goes out of a coverage area, the data call will drop. When this happens, BREW cleans up the underlying OEM sockets that are in use. The ISocket(s) used by an app continue to exist, and the app will get appropriate error responses when it tries to use them.

For synchronous (TCP/IP) data communication, there are two ways to handle the potentially bad sockets:

Check the return value from all Socket operations

Writing or reading from the socket will cause AEE_NET_ERROR to be returned. In your code, you should check the return value from the Socket connect, read, write and take appropriate action.

// Connect callback

static void SampleApp_ConnectCB(void *cxt, int err) {

SampleApp *pMe = (SampleAppApp*)cxt;

if (err) {

// connect failed

SampleApp_CleanUp(pMe);

//Clean up net manager and

// sockets

ShowMainMenu(pMe);

return;

}

}

// Writing

iRet = ISOCKET_Write(pMe->m_piSock, (byte*)Request,

(uint16)STRLEN(Request));

if (iRet == AEE_NET_ERROR) {

// Write error

SampleApp_CleanUp(pMe);

// Clean up net manager and sockets

ShowMainMenu(pMe);

return;

}

// Reading

iRet = ISOCKET_Read(pMe->m_piSock, (byte*)buf,

sizeof(buf));

if (iRet == AEE_NET_ERROR) {

// Read error

SampleApp_CleanUp(pMe);

// Clean up net manager and sockets

ShowMainMenu(pMe);

return;

}

Register for change in network/socket state

Another way to handle the phone going out of coverage while a data call is in progress is to register for Network and Socket events using INETMGR_OnEvent() and take appropriate action when notified of change in network/socket status. In the example below, a flag is set to indicate that the socket is bad. The socket state is checked before it is used.

For more information on Network and Socket events, please refer to NetMgrEvent and NetState enums in aeenet.h include file.

For example:

// Register to receive Network and Socket events

INETMGR_OnEvent(piNet, (PFNNETMGREVENT)CheckNetStatus,

(void*)pMe, TRUE);

//Callback invoked when Network/Socket event is received

static void CheckNetStatus(void* cxt, NetMgrEvent evt,

uint32, dwData) {

SampleApp *pMe = (SampleApp*)cxt;

if(evt == NE_PPP) {

if(dwData == NET_PPP_CLOSING || dwData ==

NET_PPP_CLOSED) {

// flag set to false to indicate socket is bad

pMe->m_SocketState = FALSE;

// clean up network and socket

ReleaseNetAndSocket(pMe);

}

}

if(evt == NE_SO_CLOSING || evt == NE_SO_CLOSED) {

pMe->m_SocketState = FALSE;

ReleaseNetAndSocket(pMe);

}

if(evt == NE_SO_CONNECTED) {

pMe->m_SocketState = TRUE;

}

return;

}

// Check socket state before using it

static void RoadWarriorApp_ReadCB(void *cxt) {

int rc;

SampleApp *pMe = (SampleApp *)cxt;

if(pMe->m_SocketState == FALSE) { //socket is bad

ReleaseNetAndSocket(pMe);

ShowMainMenu(pMe);

return;

}

rc = ISOCKET_Read(piSock, (byte*)buf, sizeof(buf));

}

When registering for network and socket events using INETMGR_InEvent(), you must de- register before terminating the application by using INETMGR_OnEvent() with bRegister = FALSE.

Note: After the phone goes out of coverage, the sockets are unusable. You must release your ISocket(s) and reinstantiate them when next required. The INetMgr does not need to be released and re-instantiated before using it for the next network operation, however there is no harm in doing so.

To handle potentially bad sockets for asynchronous(UDP) data communication, register for change in network/socket state (described in number 2 above).

 191 views

78⟩ Why does ISOCKET_Release() return one when we are expecting a return value of zero?

When an application calls ISOCKET_Release(), the internal state of the ISocket object changes to "closing," and BREW begins waiting for the asynchronous "closed" event. Since the closed event is received in a callback, the reference count of the ISocket object is incremented to prevent it from being released before its internal state changes to closed.

 205 views