EPRIVLEVEL error when executing IFILEMGR_OpenFile | developer.brewmp.com EPRIVLEVEL error when executing IFILEMGR_OpenFile | developer.brewmp.com

Developer

EPRIVLEVEL error when executing IFILEMGR_OpenFile

Forums:

Here is my code

IFileMgr *pIFileMgr=NULL;
IFile* pIfile=NULL;
uint32 result=0;
uint32 iFileResult=0;
result = ISHELL_CreateInstance(pMe->piShell,AEECLSID_FILEMGR,
                    (void**)&pIFileMgr);
if(result!=SUCCESS){
       return NULL;

pIfile = IFILEMGR_OpenFile(pIFileMgr,CONFIG_FILE,mode);
iFileResult = IFILEMGR_GetLastError(pIFileMgr);

the iFileResult is always EPRIVLEVEL. I run it with mode = _OFM_READWRITE and _OFM_CREATE, but I get the same error. I have the AEEPRIVID_PLFile permission.

The other weird thing is on the phone it works, but not on the emulator... We submitted the application to NSTL for testing and they are having this problem on the phone that I can't reproduce.

CONFIG_FILE is the exact path ie fs:/mod/app/config.txt

I've tried messing around with the FS_ACL_Grant, but haven't got anywhere with that. Does my app need permission to write in it's own directory?

 

any help would be greatly appreciated. Thanks

AEEPRIVID_PLFile  priviledge is required in order to do file operations, can you please make sure that you are not opening the MIF created after compiling CIF and opening it in legacy Brew MIF editor. This action may currupt the MIF file.
I tried to replicate the issue on simulator but it is working fine for me. As you said that NSTL is seeing this issue on phone, can you please let me know the device model, i will let you know the update on this.
 

AEEPRIVID_PLFile  priviledge is required in order to do file operations, can you please make sure that you are not opening the MIF created after compiling CIF and opening it in legacy Brew MIF editor. This action may currupt the MIF file.
I tried to replicate the issue on simulator but it is working fine for me. As you said that NSTL is seeing this issue on phone, can you please let me know the device model, i will let you know the update on this.
 

The phone model is the Motorola Barrage (v860). I'll try to make a simple file and see if that works as well. I do have a case Open with our actual project the case # is 00084878. So you can take a look at it. I'll let you konw the results of a much simpler program. I"ve only edited the cif file in the Resource manager so I don't think that is it, but I'll double check. Thanks for your help.

The phone model is the Motorola Barrage (v860). I'll try to make a simple file and see if that works as well. I do have a case Open with our actual project the case # is 00084878. So you can take a look at it. I'll let you konw the results of a much simpler program. I"ve only edited the cif file in the Resource manager so I don't think that is it, but I'll double check. Thanks for your help.

here is my code ( really only the last 2 functions you need to look at. since the app starts and calls the drawScreen function)

#include "AEEModGen.h" // Module interface definitions.
#include "AEEAppGen.h" // Applet interface definitions.
#include "AEEShell.h" // Shell interface definitions.
#include "AEEFile.h"
#include "AEEStdLib.h"
#include "FileCreationTest.bid"
#include "FileCreationTest_res.h"
typedef struct _FileCreationTest {
AEEApplet applet; // First element of this structure must be AEEApplet.
IDisplay * piDisplay; // Copy of IDisplay Interface pointer for easy access.
IShell * piShell; // Copy of IShell Interface pointer for easy access.
AEEDeviceInfo deviceInfo; // Copy of device info for easy access.
} FileCreationTest;
static boolean FileCreationTest_HandleEvent(FileCreationTest* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean FileCreationTest_InitAppData(FileCreationTest* pMe);
void FileCreationTest_FreeAppData(FileCreationTest* pMe);
static void FileCreationTest_DrawScreen(FileCreationTest * pMe);
int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
void ** ppObj)
{
*ppObj = NULL;
// Confirm this applet is the one intended to be created (classID matches):
if( AEECLSID_FILECREATIONTEST == ClsId ) {
// Create the applet and make room for the applet structure.
// NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
if( TRUE == AEEApplet_New(sizeof(FileCreationTest),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)FileCreationTest_HandleEvent,
(PFNFREEAPPDATA)FileCreationTest_FreeAppData) ) {
// Initialize applet data. This is called before EVT_APP_START is
// sent to the HandleEvent function.
if(TRUE == FileCreationTest_InitAppData((FileCreationTest*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
// Release the applet. This will free the memory allocated for
// the applet when AEEApplet_New was called.
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;

boolean FileCreationTest_InitAppData(FileCreationTest * pMe)
{
// Save local copy for easy access:
pMe->piDisplay = pMe->applet.m_pIDisplay;
pMe->piShell = pMe->applet.m_pIShell;
// Get the device information for this handset.
// Reference all the data by looking at the pMe->deviceInfo structure.
// Check the API reference guide for all the handy device info you can get.
pMe->deviceInfo.wStructSize = sizeof(pMe->deviceInfo);
ISHELL_GetDeviceInfo(pMe->applet.m_pIShell,&pMe->deviceInfo);
// Insert your code here for initializing or allocating resources...
return TRUE;// No failures up to this point, so return success.

void FileCreationTest_FreeAppData(FileCreationTest * pMe)
{

static boolean FileCreationTest_HandleEvent(FileCreationTest* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {
case EVT_APP_START:
FileCreationTest_DrawScreen(pMe); // Draw text on display screen.
return TRUE;
case EVT_APP_STOP:
return TRUE;
case EVT_APP_SUSPEND:
return TRUE;
case EVT_APP_RESUME:
FileCreationTest_DrawScreen(pMe); // Redraw text on display screen.
return TRUE;
case EVT_APP_MESSAGE:
return TRUE;
case EVT_KEY:
return FALSE;
case EVT_FLIP:
return TRUE;
case EVT_KEYGUARD:
return TRUE;
// If event wasn't handled here, then break out:
default:
break;
}
return FALSE; // Event wasn't handled.

IFile* getConfigFile(FileCreationTest *pMe,OpenFileMode mode,char** error){
IFileMgr *pIFileMgr=NULL;
IFile* pIfile=NULL;
uint32 result=0;
char* CONFIG_FILE="fs:/mod/FileCreationTest/config.txt";
*error = "";
result = ISHELL_CreateInstance(pMe->piShell,AEECLSID_FILEMGR,(void**)&pIFileMgr);
if(result!=SUCCESS){
return NULL;
}
pIfile = IFILEMGR_OpenFile(pIFileMgr,CONFIG_FILE,mode);
result = IFILEMGR_GetLastError(pIFileMgr);
if(result!=SUCCESS){
char* msg="";
switch(result){
case EFILEEXISTS:msg="file Exists.";break;
case EFILENOEXISTS:msg="file Does Not Exist.";break;
case EDIRNOTEMPTY:msg="EDIRNOTEMPTY";break;
case EDIRNOEXISTS:msg="EDIRNOEXISTS";break;
case EBADFILENAME:msg="EBADFILENAME";break;
case EBADSEEKPOS:msg="EBADSEEKPOS";break;
case EFILEEOF:msg="EFILEEOF";break;
case EFSFULL:msg="EFSFULL";break;
case EFILEOPEN:msg="EFILEOPEN";break;
case EBADPARM:msg="EBADPARM";break;
case EPRIVLEVEL:msg="EPRIVLEVEL";break;
default:msg="uknown Error";
}
DBGPRINTF("%s : %x",msg,result);
*error = msg;
}
//not sure if this should happen here or not.
IFILEMGR_Release(pIFileMgr);
return pIfile;

static void FileCreationTest_DrawScreen(FileCreationTest * pMe)
{
char* error;
IFile *piFile;
AECHAR szBuf[64] = {0};
int nStrLen = 0;
RGBVAL oldTextColor = RGB_BLACK;
IDisplay_ClearScreen(pMe->piDisplay); // Erase whole screen.
piFile = getConfigFile(pMe,_OFM_READWRITE,&error);
DBGPRINTF("Message on Read/Write = %s",error);
if(!piFile){
piFile = getConfigFile(pMe,_OFM_CREATE,&error);
DBGPRINTF("Message on Create = %s",error);
}
if(piFile){
char* buf = "This is a test";
int bytesWritten=0;
IFILE_Truncate(piFile,0);
bytesWritten = IFILE_Write(piFile,buf,STRLEN(buf));
DBGPRINTF("Wrote %d bytes",bytesWritten);
error="Success!";
}
// Load the string resource into a buffer:
//nStrLen = ISHELL_LoadResString(pMe->piShell,
// FILECREATIONTEST_RES_FILE,
// IDS_STRING_1001, szBuf, sizeof(szBuf));
STRTOWSTR(error,szBuf,sizeof(szBuf));
nStrLen = STRLEN(error);
// If the text was successfully loaded from resource file into buffer:
if (0 < nStrLen) {
// Set user-text color to black:
oldTextColor = IDisplay_SetColor(pMe->piDisplay,
CLR_USER_TEXT,
RGB_BLACK);
IDisplay_DrawText(pMe->piDisplay, // Display instance.
AEE_FONT_BOLD, // Use Bold font.
szBuf, // String buffer containing text.
-1, // Automatically compute string length.
0, // x-coordinate ignored since IDF_ALIGN_CENTER.
0, // y-coordinate ignored since IDF_ALIGN_MIDDLE.
NULL, // No clipping.
IDF_ALIGN_CENTER | // Center-align horizontally.
IDF_ALIGN_MIDDLE); // Middle-align vertically.
}
// Restore previous color:
IDisplay_SetColor(pMe->piDisplay, CLR_USER_TEXT, oldTextColor);
IDisplay_Update (pMe->piDisplay);

here is my cif file

include "FileCreationTest.bid"
AEEPRIVID_PLFile = 0x0001 --Declare
ModRsc {
id = 20, -- Applet base resource id
type = 1, --RESTYPE_ENCSTRING (see AEEResType.h)
data = UTF16_EncString("FileCreationTest")

ModRsc {
id = 21,
type = 6, --RESTYPE_MIMETYPED (see AEEResType.h)
data = ImageRscData("image/png", BytesOfFile("FileCreationTest_ico.png"))

Applet {
appletid = AEECLSID_FILECREATIONTEST,
resbaseid = 20, -- Applet base resource id
applethostid = 0,
type = 0,
privs = {},

PrivLevel{
AEEPRIVID_PLFile

this works on the phone, but not on the emulator. The emulator I am using is Brew MP Simulation Target -> Flip Phone (1.0.2.549.1) one of the standard phones.

here is my code ( really only the last 2 functions you need to look at. since the app starts and calls the drawScreen function)

#include "AEEModGen.h" // Module interface definitions.
#include "AEEAppGen.h" // Applet interface definitions.
#include "AEEShell.h" // Shell interface definitions.
#include "AEEFile.h"
#include "AEEStdLib.h"
#include "FileCreationTest.bid"
#include "FileCreationTest_res.h"
typedef struct _FileCreationTest {
AEEApplet applet; // First element of this structure must be AEEApplet.
IDisplay * piDisplay; // Copy of IDisplay Interface pointer for easy access.
IShell * piShell; // Copy of IShell Interface pointer for easy access.
AEEDeviceInfo deviceInfo; // Copy of device info for easy access.
} FileCreationTest;
static boolean FileCreationTest_HandleEvent(FileCreationTest* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean FileCreationTest_InitAppData(FileCreationTest* pMe);
void FileCreationTest_FreeAppData(FileCreationTest* pMe);
static void FileCreationTest_DrawScreen(FileCreationTest * pMe);
int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule,
void ** ppObj)
{
*ppObj = NULL;
// Confirm this applet is the one intended to be created (classID matches):
if( AEECLSID_FILECREATIONTEST == ClsId ) {
// Create the applet and make room for the applet structure.
// NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
if( TRUE == AEEApplet_New(sizeof(FileCreationTest),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)FileCreationTest_HandleEvent,
(PFNFREEAPPDATA)FileCreationTest_FreeAppData) ) {
// Initialize applet data. This is called before EVT_APP_START is
// sent to the HandleEvent function.
if(TRUE == FileCreationTest_InitAppData((FileCreationTest*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
// Release the applet. This will free the memory allocated for
// the applet when AEEApplet_New was called.
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;

boolean FileCreationTest_InitAppData(FileCreationTest * pMe)
{
// Save local copy for easy access:
pMe->piDisplay = pMe->applet.m_pIDisplay;
pMe->piShell = pMe->applet.m_pIShell;
// Get the device information for this handset.
// Reference all the data by looking at the pMe->deviceInfo structure.
// Check the API reference guide for all the handy device info you can get.
pMe->deviceInfo.wStructSize = sizeof(pMe->deviceInfo);
ISHELL_GetDeviceInfo(pMe->applet.m_pIShell,&pMe->deviceInfo);
// Insert your code here for initializing or allocating resources...
return TRUE;// No failures up to this point, so return success.

void FileCreationTest_FreeAppData(FileCreationTest * pMe)
{

static boolean FileCreationTest_HandleEvent(FileCreationTest* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {
case EVT_APP_START:
FileCreationTest_DrawScreen(pMe); // Draw text on display screen.
return TRUE;
case EVT_APP_STOP:
return TRUE;
case EVT_APP_SUSPEND:
return TRUE;
case EVT_APP_RESUME:
FileCreationTest_DrawScreen(pMe); // Redraw text on display screen.
return TRUE;
case EVT_APP_MESSAGE:
return TRUE;
case EVT_KEY:
return FALSE;
case EVT_FLIP:
return TRUE;
case EVT_KEYGUARD:
return TRUE;
// If event wasn't handled here, then break out:
default:
break;
}
return FALSE; // Event wasn't handled.

IFile* getConfigFile(FileCreationTest *pMe,OpenFileMode mode,char** error){
IFileMgr *pIFileMgr=NULL;
IFile* pIfile=NULL;
uint32 result=0;
char* CONFIG_FILE="fs:/mod/FileCreationTest/config.txt";
*error = "";
result = ISHELL_CreateInstance(pMe->piShell,AEECLSID_FILEMGR,(void**)&pIFileMgr);
if(result!=SUCCESS){
return NULL;
}
pIfile = IFILEMGR_OpenFile(pIFileMgr,CONFIG_FILE,mode);
result = IFILEMGR_GetLastError(pIFileMgr);
if(result!=SUCCESS){
char* msg="";
switch(result){
case EFILEEXISTS:msg="file Exists.";break;
case EFILENOEXISTS:msg="file Does Not Exist.";break;
case EDIRNOTEMPTY:msg="EDIRNOTEMPTY";break;
case EDIRNOEXISTS:msg="EDIRNOEXISTS";break;
case EBADFILENAME:msg="EBADFILENAME";break;
case EBADSEEKPOS:msg="EBADSEEKPOS";break;
case EFILEEOF:msg="EFILEEOF";break;
case EFSFULL:msg="EFSFULL";break;
case EFILEOPEN:msg="EFILEOPEN";break;
case EBADPARM:msg="EBADPARM";break;
case EPRIVLEVEL:msg="EPRIVLEVEL";break;
default:msg="uknown Error";
}
DBGPRINTF("%s : %x",msg,result);
*error = msg;
}
//not sure if this should happen here or not.
IFILEMGR_Release(pIFileMgr);
return pIfile;

static void FileCreationTest_DrawScreen(FileCreationTest * pMe)
{
char* error;
IFile *piFile;
AECHAR szBuf[64] = {0};
int nStrLen = 0;
RGBVAL oldTextColor = RGB_BLACK;
IDisplay_ClearScreen(pMe->piDisplay); // Erase whole screen.
piFile = getConfigFile(pMe,_OFM_READWRITE,&error);
DBGPRINTF("Message on Read/Write = %s",error);
if(!piFile){
piFile = getConfigFile(pMe,_OFM_CREATE,&error);
DBGPRINTF("Message on Create = %s",error);
}
if(piFile){
char* buf = "This is a test";
int bytesWritten=0;
IFILE_Truncate(piFile,0);
bytesWritten = IFILE_Write(piFile,buf,STRLEN(buf));
DBGPRINTF("Wrote %d bytes",bytesWritten);
error="Success!";
}
// Load the string resource into a buffer:
//nStrLen = ISHELL_LoadResString(pMe->piShell,
// FILECREATIONTEST_RES_FILE,
// IDS_STRING_1001, szBuf, sizeof(szBuf));
STRTOWSTR(error,szBuf,sizeof(szBuf));
nStrLen = STRLEN(error);
// If the text was successfully loaded from resource file into buffer:
if (0 < nStrLen) {
// Set user-text color to black:
oldTextColor = IDisplay_SetColor(pMe->piDisplay,
CLR_USER_TEXT,
RGB_BLACK);
IDisplay_DrawText(pMe->piDisplay, // Display instance.
AEE_FONT_BOLD, // Use Bold font.
szBuf, // String buffer containing text.
-1, // Automatically compute string length.
0, // x-coordinate ignored since IDF_ALIGN_CENTER.
0, // y-coordinate ignored since IDF_ALIGN_MIDDLE.
NULL, // No clipping.
IDF_ALIGN_CENTER | // Center-align horizontally.
IDF_ALIGN_MIDDLE); // Middle-align vertically.
}
// Restore previous color:
IDisplay_SetColor(pMe->piDisplay, CLR_USER_TEXT, oldTextColor);
IDisplay_Update (pMe->piDisplay);

here is my cif file

include "FileCreationTest.bid"
AEEPRIVID_PLFile = 0x0001 --Declare
ModRsc {
id = 20, -- Applet base resource id
type = 1, --RESTYPE_ENCSTRING (see AEEResType.h)
data = UTF16_EncString("FileCreationTest")

ModRsc {
id = 21,
type = 6, --RESTYPE_MIMETYPED (see AEEResType.h)
data = ImageRscData("image/png", BytesOfFile("FileCreationTest_ico.png"))

Applet {
appletid = AEECLSID_FILECREATIONTEST,
resbaseid = 20, -- Applet base resource id
applethostid = 0,
type = 0,
privs = {},

PrivLevel{
AEEPRIVID_PLFile

this works on the phone, but not on the emulator. The emulator I am using is Brew MP Simulation Target -> Flip Phone (1.0.2.549.1) one of the standard phones.

I figured it out. It turns out I was using the full path fs:/mod/app/config.txt, I needed to use the relative path ie: config.txt So it was sure to write in the correct directory. This fixed the problem.

I figured it out. It turns out I was using the full path fs:/mod/app/config.txt, I needed to use the relative path ie: config.txt So it was sure to write in the correct directory. This fixed the problem.