mrp_sms.c 9.93 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
#ifdef __MMI_DSM_NEW__

#include "MMI_Include.h"
#include "PixtelDataTypes.h"
#include "MMIDataType.h"
#include "med_utility.h"
//#include "SimDetectionDef.h"
#include "MessagesResourceData.h"
#include "Ems.h"
#include "SmsGuiInterfaceProt.h"
#include "SmsGuiInterfaceType.h"
#include "ProtocolEvents.h"
#include "AlarmFrameworkProt.h"
#include "CommonScreens.h"
#include "Wgui_ems.h"
#include "SettingProfile.h"

#include "MessagesMiscell.h"
#include "SmsGuiInterfaceProt.h"
#include "UcAppGProt.h"

#include "mrp_include.h"

#if (MTK_VERSION > 0x0812)
#include "Mms_api.h"
#endif

#if (MTK_VERSION >= 0x0924)
#include "SmsAppProt.h"
#endif

#if (MTK_VERSION <= 0x0848)
#include "SMSApi.h"
#endif

#if (MTK_VERSION < 0x09B0952)
#include "SMSStruct.h"
#endif

#ifdef __MED_IN_ASM__
#define med_alloc_ext_mem(size) applib_asm_alloc_anonymous_nc(size)
#define med_alloc_ext_mem_cacheable(size) applib_asm_alloc_anonymous(size)
#define med_free_ext_mem(ptr) applib_asm_free_anonymous(*ptr)
#endif


#if (MTK_VERSION >=0x0952)
#ifndef IMG_SEND_SUCCESS_PIC_MSG
#define IMG_SEND_SUCCESS_PIC_MSG  (IMG_GLOBAL_SUCCESS)
#define IMG_SEND_FAIL_PIC_MSG          (IMG_GLOBAL_FAIL)
#endif
#endif


//adaptor
#if (MTK_VERSION >= 0x0824)
#define INPUT_TYPE_PHONE_NUMBER						IMM_INPUT_TYPE_NUMERIC
#define INPUT_TYPE_ALPHANUMERIC_PASSWORD			IMM_INPUT_TYPE_ALPHANUMERIC_PASSWORD
#define INPUT_TYPE_ALPHANUMERIC_SENTENCECASE			IMM_INPUT_TYPE_SENTENCE
#endif

T_DSM_MSG_INFO gdsmSMSInfo = {0};
static int32 dsmDeliveryLock = 0;
U8 newSmsDisplay = 1;

#if(MTK_VERSION >= 0x09B0952)
U8 dsmSmsOpCount = 0;
#endif

#if(MTK_VERSION < 0x09B0952)
static U8 dsmDeliveryRepyStates[2] = {0};
#endif


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
extern EMSData * GetEMSDataForEdit (EMSData ** p, U8 force);
extern EMSData *GetEMSDataForView(EMSData **p, U8 force);
U8 mmi_msg_check_interrupt(void);
static MR_BOOL mr_IsReadySendSms(void);


/* 直接INCLUDE对应功能的c文件,大家不要感觉差异。*/
#if(MTK_VERSION < 0x09B0952)
#include ".\mt07a-09a\mrp_sms(07a-09a).c"
#else
#include ".\mt09b\mrp_sms(09b).c"
#endif


#define MR_MAX_PROCESS_SMS_CALLBACK 5
static SMS_CALLBACK sms_process_call[MR_MAX_PROCESS_SMS_CALLBACK];


int32 mr_sms_execute_incoming_sms(uint8 *pContent, int32 nLen, uint8 *pNum, int32 type)
{
	int i;
	int32 ret = MR_IGNORE;
	
	for (i = 0; i < MR_MAX_PROCESS_SMS_CALLBACK; i++)
	{
		if (sms_process_call[i] != NULL)
		{
			ret = sms_process_call[i](pContent, nLen, pNum, type);
			if (ret == MR_SUCCESS)
			{
				break; 
			}
		}
	}

	return ret;
}


int32 mr_sms_register_cb(SMS_CALLBACK cb)
{
	int i;
	
	for (i = 0; i < MR_MAX_PROCESS_SMS_CALLBACK; i++)
	{
		if (sms_process_call[i] == NULL || sms_process_call[i] == cb)
		{
			break;
		}
	}

	if (i < MR_MAX_PROCESS_SMS_CALLBACK)
	{
		sms_process_call[i] = cb;
		return MR_SUCCESS;
	}
	else
	{
		return MR_FAILED;
	}
}


int32 mr_sms_deregister_cb(SMS_CALLBACK cb)
{
	int i;
	
	for (i = 0; i < MR_MAX_PROCESS_SMS_CALLBACK; i++)
	{
		if (sms_process_call[i] == cb)
		{
			sms_process_call[i] = NULL;
			return MR_SUCCESS;
		}
	}

	return MR_FAILED;
}


int32 mr_sms_initialize(void)
{
#if(MTK_VERSION >= 0x09B0952)
	dsmSmsOpCount = 0;
#endif

	return MR_SUCCESS;
}


int32 mr_sms_terminate(void)
{
	return MR_SUCCESS;
}


int32 mr_sms_send_mms(T_DSM_MMS *pMMS)
{
#ifndef	__MR_CFG_FEATURE_NO_SMS__
#if (defined(__MMI_UNIFIED_COMPOSER__) || defined(__MMI_MMS_STANDALONE_COMPOSER__))
	mmi_uc_entry_write_struct data = { 0 };
	srv_uc_addr_struct uc_addr = {0};
	BOOL result;	
	WCHAR* path;
	WCHAR* tmp;
	
	path = OslMalloc(mr_str_wstrlen((char*)pMMS->file_path) + 2);
	if (path == NULL)
		return MR_FAILED;

	path[0] = 0;
	app_ucs2_strcat((kal_int8*)path, (kal_int8*)pMMS->file_path);

	if(path[0] == 'A'||path[0] == 'a')
	{
		path[0] = MMI_SYSTEM_DRV;
	}
	else if(path[0] == 'B'||path[0] == 'b')
	{
		path[0] = MMI_PUBLIC_DRV;
	}
	else
	{
		path[0] = MMI_CARD_DRV;
	}
	
	tmp = path;
	while(tmp = (WCHAR*)app_ucs2_strchr((kal_int8*)tmp, '/'))
	{
		*tmp = '\\';
		++tmp;
	}

	if (pMMS->addr != NULL)
	{
		uc_addr.addr = (kal_uint8*)pMMS->addr;
		data.addr = &uc_addr;
		data.addr_num = 1;
	}

	data.file_path = (U8*)path;
	data.text_buffer = (U8*)pMMS->content;
	data.text_num = mr_str_wstrlen((char*)pMMS->content);
	data.subject = (U8*)pMMS->subject;

	data.info_type = SRV_UC_INFO_TYPE_MMS;

	mmi_uc_entry_write_msg_with_content(SRV_UC_STATE_WRITE_NEW_MSG, &data);

	OslMfree(path);
	
	return MR_SUCCESS;
#else
	return MR_IGNORE;
#endif
#else
	return MR_IGNORE;
#endif
}


/****************************************************************************
函数名:bool mr_IsReadySendSms(void)
描  述:判断gsm模块是否初始化完并能发短信
参  数:无
返  回:初始化完成:MR_TRUE
       初始化未完:MR_FALSE
****************************************************************************/
static MR_BOOL mr_IsReadySendSms(void)
{
	MR_BOOL result;
	
	if(0)
	{
		result  = MR_FALSE;
	}
#if (MTK_VERSION >= 0x09B0952)
	else
	{
		if(srv_sms_check_send_action_pending(SRV_SMS_FG_SEND)||(!srv_sms_is_sms_ready())||dsmSmsOpCount)
			result = MR_FALSE;
		else
			result = MR_TRUE;
	}
#else

#if (MTK_VERSION>=0x0936)
	else if(mmi_sms_is_allow_send_sms())
	{
		result = MR_TRUE;
	}
	
#endif
	else if(mmi_frm_sms_get_sms_list_size(0x00)==MMI_FRM_SMS_INVALID_INDEX)   //not ready
	{
		result  = MR_FALSE;
	}
	else
	{
		if(mmi_frm_sms_check_action_pending())
			result  = MR_FALSE;
		else
			result  = MR_TRUE;
	}
#endif
	return result;
}


int32 mr_sms_send_sms_from_ui(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#ifndef	__MR_CFG_FEATURE_NO_SMS__
	EMSData	* pEMS = NULL;
	S8 * textbufUCS2 = NULL;
	int32 len = 0;
	byte  result = 1;
	T_PLAT_SENDSMS_REQ *req = (T_PLAT_SENDSMS_REQ *)input;
	
	if(input == NULL||input_len < sizeof(T_PLAT_SENDSMS_REQ))
		return MR_FAILED;
	
	if(req->pContent != NULL)
	{
		len = mr_str_wstrlen(req->pContent);
	}

	if(len > 0)
	{
		textbufUCS2 = OslMalloc(len + 2);
	
		if(textbufUCS2 == NULL)
			return MR_FAILED;

		memset(textbufUCS2,0,len+2);

		if(req->pContent != NULL)
		{
			memcpy(textbufUCS2,req->pContent,len);
		}

		mr_str_convert_endian((char *)textbufUCS2);
	}

#if(MTK_VERSION >=0x0924)
	ReleaseEMSViewBuffer();

	pEMS = GetEMSDataForView(0, 1);
	
	if(pEMS == NULL)
	{
		if(textbufUCS2 != NULL)
			OslMfree(textbufUCS2);
		return MR_FAILED;
	}

	if(len > 0 )
	{
#if (__MR_CFG_VAR_MTK_VERSION__ >= 0x11B1132)	
		// TO DO
#else	
		result = AppendEMSString(INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,pEMS, (U8*)textbufUCS2, SMSAL_UCS2_DCS, NULL); 
#endif		
		OslMfree(textbufUCS2);
	}
		
	if(result)
	{
		mmi_sms_entry_write_msg(SMS_SEND_CASE_FORWARD);
		return MR_SUCCESS;
	}
	else
	{
		return MR_FAILED;
	}
#else
	ReleaseEMSEditBuffer();

	pEMS = GetEMSDataForEdit (0, 1);
	
	if(pEMS == NULL)
	{
		if(textbufUCS2 != NULL)
			OslMfree(textbufUCS2);
		return MR_FAILED;
	}

	if(len > 0 )
	{
#if (__MR_CFG_VAR_MTK_VERSION__ >= 0x11B1132)	
		// TO DO
#else
		result = AppendEMSString(INPUT_TYPE_ALPHANUMERIC_SENTENCECASE,pEMS, (U8*)textbufUCS2, SMSAL_UCS2_DCS, NULL); 
#endif		
		OslMfree(textbufUCS2);
	}
		
	if(result)
	{
		mmi_msg_entry_write_msg();
		return MR_SUCCESS;
	}
	else
	{
		return MR_FAILED;
	}
#endif	
#else
	return MR_IGNORE;
#endif
}


int32 mr_sms_get_sms_status(int32 param)
{
#ifndef	__MR_CFG_FEATURE_NO_SMS__
      #if (MTK_VERSION >=0x09B0952)	//#if (MTK_VERSION >=09B1012)  eric
	   if(srv_sms_check_send_action_pending(SRV_SMS_FG_SEND)||(!srv_sms_is_sms_ready())||dsmSmsOpCount)
	  #else
	if((mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_APP_INBOX) == MMI_FRM_SMS_INVALID_INDEX)
		||mmi_frm_sms_check_action_pending())
	#endif
	{
		return MR_SMS_NOT_READY;
	}
	else
	{
		return MR_SMS_READY;
	}
#else
	return MR_IGNORE;
#endif
}


U8 dsmIsSmsDisplay(void)
{
	kal_prompt_trace(MOD_MMI,"newSmsDisplay =%d",newSmsDisplay);
	return newSmsDisplay;
}


int32 mr_sms_enable_new_display(int32 param)
{
	if(0 == param)
	{
		newSmsDisplay = 0;
	}
	else
	{
		newSmsDisplay = 1;
	}
	
	return MR_SUCCESS;
}


int32 mr_sms_get_sms_info(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#ifndef	__MR_CFG_FEATURE_NO_SMS__
	T_DSM_GET_SMS_INFO_REQ *pReq = (T_DSM_GET_SMS_INFO_REQ*)input;
	U8 ret;
	
	if((input == NULL)||(input_len < sizeof(T_DSM_GET_SMS_INFO_REQ)))
		return MR_FAILED;

	ret = dsm_get_sms_info(pReq);
	
	if( ret== MR_SUCCESS)
	{
		*output = (uint8 *)&gdsmSMSInfo;
		*output_len = sizeof(gdsmSMSInfo);
		return MR_SUCCESS;
	}
	else
	{
		return ret;
	}
#else
	return MR_IGNORE;
#endif
}

int32 mr_sms_save_sms(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#ifndef	__MR_CFG_FEATURE_NO_SMS__
	kal_prompt_trace(MOD_MMI,"mr_sms_save_sms  111,%d,%d,%d",input,input_len,sizeof(T_MR_SMS_SAVE_ENTRY_REQ));
	if((input == NULL)||(input_len < sizeof(T_MR_SMS_SAVE_ENTRY_REQ)))
	{ 
		kal_prompt_trace(MOD_MMI,"mr_sms_save_sms  222");
		return MR_FAILED;
	} 
	 
	return mr_sms_save_msg((T_MR_SMS_SAVE_ENTRY_REQ *)input);
#else
	return MR_IGNORE;
#endif
}
int32 mr_sms_reply_sms(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#ifndef __MR_CFG_FEATURE_SLIM__
	kal_prompt_trace(MOD_MMI,"mr_sms_reply_sms  111,%d,%d,%d",input,input_len,sizeof(T_MR_SMS_REPLY_ENTRY_REQ));
	if((input == NULL)||(input_len < sizeof(T_MR_SMS_REPLY_ENTRY_REQ)))
	{
		kal_prompt_trace(MOD_MMI,"mr_sms_reply_sms  222");
		return MR_FAILED;
	}
	
	return mr_sms_reply_msg((T_MR_SMS_REPLY_ENTRY_REQ *)input);
#else
	return MR_IGNORE;
#endif
}
#ifdef __MR_CFG_SET_SMS_STATUS__

int32 mr_sms_set_sms_status(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#ifndef	__MR_CFG_FEATURE_NO_SMS__
	T_DSM_SET_SMS_STATE_REQ *pReq = (T_DSM_SET_SMS_STATE_REQ*)input;
	U8 ret; 
	
	kal_prompt_trace(MOD_MMI,"mr_sms_set_sms_state 111,%d",ret);
	if((input == NULL)||(input_len < sizeof(T_DSM_SET_SMS_STATE_REQ)))
		return MR_FAILED;
		
	if (srv_sms_is_sms_ready() == MMI_FALSE)
		return MR_FAILED;
  
	ret = mr_set_sms_status(pReq);
	 
	return ret;
#else
	return MR_IGNORE;
#endif
}
#endif

#endif