首页
社区
课程
招聘
[原创]在WM5以上系统使用Notification Broker机制实现获取全部电话状态
发表于: 2009-4-18 09:44 8390

[原创]在WM5以上系统使用Notification Broker机制实现获取全部电话状态

2009-4-18 09:44
8390
查了很多资料涉及到Notification Broker的都只有触发一种状态的代码,但是为了一个功能改进,我需要一种能获取多种电话状态(呼出、呼入、通话中……)的方法,同时由于程序是需要主动触发的,所以用RegistryNotifyApp做主动Broker,查了MSDN却发现没有对RegistryNotifyApp如何在多种事件中启动做出过多说明,就继续翻其他MSDN,终于看到在NOTIFICATIONCONDITION的解释里有这含义模糊的两行文字:
dwMask
Applies only to DWORD values. This mask is applied to the changed registry value before comparison. By specifying a bit mask, the Notifications Broker notifies the clients only when specific bits in the registry value changes.
This mask is not applied to TargetValue. If dwMask is 0, TargetValue is treated as a string (type REG_SZ), otherwise it is treated as type REG_DWORD.

TargetValue
If the changed value is type REG_SZ, then comparison is done between psz and the changed value. If the changed value is type REG_DWORD, then dwMask is applied to the changed value and then the result is compared to dw. If the changed value is neither REG_SZ nor REG_DWORD, then notification is sent without any comparison. You must set dwMask to -1 to test against the whole doubleword.

可以看出,dwMask=-1好像会有什么好玩的事情发生,立即写代码测试:
#define SN_PHONECALLTALKING_ROOT HKEY_LOCAL_MACHINE
#define SN_PHONECALLTALKING_PATH TEXT("System\\State\\Phone")
#define SN_PHONECALLTALKING_VALUE TEXT("Status")
#define SN_PHONECALLTALKING_BITMASK 536870912
#define SN_PHONECALLCALLING_BITMASK 131072
#define SN_PHONEINCOMINGCALL_BITMASK 65536

#define MY_NOTIFICATION_NAME TEXT("testnotification")

DWORD GetCurrentNotificationStatus()
{
	DWORD lpPhoneTalking = 0;
	HRESULT hr;
	hr = RegistryGetDWORD(SN_PHONECALLTALKING_ROOT, 
		SN_PHONECALLTALKING_PATH, 
		SN_PHONECALLTALKING_VALUE, 
		&lpPhoneTalking);
	if(SUCCEEDED(hr))
	{
		if(lpPhoneTalking & SN_PHONECALLTALKING_BITMASK){
			return SN_PHONECALLTALKING_BITMASK;
		}else if(lpPhoneTalking & SN_PHONECALLCALLING_BITMASK){
			return SN_PHONECALLCALLING_BITMASK;
		}else if(lpPhoneTalking & SN_PHONEINCOMINGCALL_BITMASK){
			return SN_PHONEINCOMINGCALL_BITMASK;
		}else{
			return lpPhoneTalking;
		}
	}else{
		return 0;
	}
}

HRESULT RegisterNotification()
{
	HRESULT hr = NULL;

	NOTIFICATIONCONDITION nc;

	nc.dwMask = -1;
	nc.ctComparisonType = REG_CT_ANYCHANGE;
	nc.TargetValue.dw = 0x01;

	hr = RegistryNotifyApp(SN_PHONECALLTALKING_ROOT, SN_PHONECALLTALKING_PATH,
		SN_PHONECALLTALKING_VALUE, MY_NOTIFICATION_NAME, szExeFile,
		NULL, NULL, 0x00, RNAF_NONAMEONCMDLINE, &nc);
	return hr;
}

int _tmain(int argc, _TCHAR* argv[])
{
	GetModuleFileName(NULL,szExeFile,256);
	HRESULT hr = RegisterNotification();
	LPCTSTR currStatus;
	DWORD dStatus;
	dStatus=GetCurrentNotificationStatus();
	switch(dStatus){
		case SN_PHONECALLCALLING_BITMASK:
			currStatus=L"Calling";
			break;
		case SN_PHONECALLTALKING_BITMASK:
			currStatus=L"Talking";
			break;
		case SN_PHONEINCOMINGCALL_BITMASK:
			currStatus=L"Incoming";
			break;
		default:
			currStatus=(LPCTSTR)dStatus;
	}

	MessageBox(GetActiveWindow(),currStatus,TEXT("test"),MB_SETFOREGROUND | MB_ICONINFORMATION | MB_OK);
	return 0;
}


执行程序,查找注册表果然注册了一个新的Broker“testnotification”,然后测试呼叫电话和打出电话和接听,成功获取了三种状态。

因此,如果你想在自己的Notification Broker程序里实现监控某种事件的整个状态,用dwMask = -1配合ctComparisonType = REG_CT_ANYCHANGE使用即可。

[课程]Linux pwn 探索篇!

上传的附件:
收藏
免费 7
支持
分享
最新回复 (6)
雪    币: 2604
活跃值: (64)
能力值: (RANK:510 )
在线值:
发帖
回帖
粉丝
2
确实是非常好的研究,可以有很多用处。
2009-4-19 10:09
0
雪    币: 2604
活跃值: (64)
能力值: (RANK:510 )
在线值:
发帖
回帖
粉丝
3
前面我也一直在考虑如何获取WM手机当前的通话状态。

可以使用一个线程专门检测,当发现处于通话状态时可以打开其他模块进行录音操作。
2009-4-19 10:10
0
雪    币: 164
活跃值: (10)
能力值: ( LV7,RANK:110 )
在线值:
发帖
回帖
粉丝
4
不用,WM5以上的直接能实现在电话事件时自动唤醒你的程序,就是我代码里用的RegistryNotifyApp,这样平时程序就不需要在后台运行了。
2009-4-19 23:09
0
雪    币: 2604
活跃值: (64)
能力值: (RANK:510 )
在线值:
发帖
回帖
粉丝
5
太好了!其实这可以做为,电话录音软件的一个重要基础。

剩下的工作就是录音了。
2009-4-20 09:08
0
雪    币: 218
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
在模拟器里面并没有唤醒程序
window mobile professional 6

只能在程序运行的时候检测到.

请教小金是在什么环境下?

下面是我nofitications注册表信息
上传的附件:
2009-7-20 14:32
0
雪    币: 164
活跃值: (10)
能力值: ( LV7,RANK:110 )
在线值:
发帖
回帖
粉丝
7
实际使用中的PPC真机环境。
2009-7-20 15:50
0
游客
登录 | 注册 方可回帖
返回
//