[代码共享] 在Windows Mobile上监听Radio Interface Layer Notification

楼主
[代码共享] 在Windows Mobile上监听Radio Interface Layer Notification
[CODE]
//------------------------------------------------------------------------
// <copyright file="RilSpy.cs" company="Yaping Xin">
//     Copyright (c) Yaping Xin. All rights reserved.
// </copyright>
// <Description>Listen to the Radio Interface Layer</Description>
//------------------------------------------------------------------------
namespace RilSpyNet
{
    using System;
    using RilNET;

    /// <summary>
    /// Listen to the Radio Interface Layer, get events
    /// </summary>
    public class RilSpy
    {
       /// <summary>
       /// Delegation definition of Log event handler
       /// </summary>
       /// <param name="message">Message to transfer</param>
       public delegate void LogHandler(string message);
       
       /// <summary>Event handler to record log</summary>
       public event LogHandler Log;
       
       /// <summary>Output handler</summary>
       private IntPtr hRil;
       
       /// <summary>
       /// Start the listener
       /// </summary>
       public void Run()
       {
           int hr = Ril.Initialize(1, new RILRESULTCALLBACK(this.RilResultCallback), new RILNOTIFYCALLBACK(this.RilNotifyCallback), RIL_NCLASS.ALL, 0, out hRil);
       }

       /// <summary>
       /// Record the message
       /// </summary>
       /// <param name="message">Message to transfer</param>
       protected void OnLog(string message)
       {
           if (this.Log != null)
           {
               this.Log(message);
           }
       }

       private void RilResultCallback(uint dwCode, int hrCmdID, IntPtr lpData, uint cbData, uint dwParam)
       {
           this.CallBackProc("RilResultCallback", dwCode, lpData, cbData, dwParam);
       }

       private void RilNotifyCallback(uint dwCode, IntPtr lpData, uint cbData, uint dwParam)
       {
           this.CallBackProc("RilNotifyCallback", dwCode, lpData, cbData, dwParam);
       }

       private void CallBackProc(string notifyTitle, uint dwCode, IntPtr lpData, uint cbData, uint dwParam)
       {
           RIL_NCLASS dwClass = ((RIL_NCLASS)dwCode & RIL_NCLASS.ALL);
           string message = string.Format("{0} - dwCode: {1}, RIL_NCLASS: {2}", notifyTitle, dwCode, dwClass);
          
           switch (dwClass)
           {
               case RIL_NCLASS.CALLCTRL:
                   RIL_NOTIFY_CALLCTR callControl = (RIL_NOTIFY_CALLCTR)dwCode;
                   message += string.Format(", CALLCTR: {0}", callControl);
                   break;
               case RIL_NCLASS.RADIOSTATE:
                   RIL_NOTIFY_RADIOSTATE dwRadioState = (RIL_NOTIFY_RADIOSTATE)dwCode;
                   message += string.Format(", RADIOSTATE: {0}", dwRadioState);
                   break;
               default:
                   break;
           }

           this.OnLog(message);
       }
    }
}

[/CODE]
1楼
RIL(Radio Interface Layer)工作在手机的底层,负责数据传输、AT指令的发送、接收及解析、提供网络支持,支持上层通讯应用程序的SMS、Voice Call等。可以说,RIL是手机通信系统的软件层面的最底层。

如果我们想监听手机上的通讯活动,比如说想记录用户什么时候给那个号码拨打了电话,什么时候开始呼叫,什么时候开始建立会话进行通话,什么时候挂的电话(谁挂的),以及更详细一点的信息,例如手机都通过了哪些基站……这些信息都可以拦截RIL层的消息来得到。

本程序就是一个例子。当然,只是个示范程序,实现了最基本的监听,想要得到进一步详细的信息,只需对监听来的消息进行进一步解析即可。

2楼
这类代码通常都是用C++来实现,但是在这里我用到了一个RIL.dll的.Net封装:RilNet,所以这段程序就可以用C#来写了。

关于C#封装Ril.dll的实例,可以在codeproject.com、Codeplex.com上看到。


3楼
[P]代码这些东西,我早就看不懂了[/P][P]过来怀念一下当年[/P][P]很高兴[URL=http://www.leadbbs.com/User/LookUserInfo.asp?ID=11433][B][FACE=Tahoma][COLOR=#454545]Xinsoft[/COLOR][/FACE][/B][/URL] 老大还活着[EM51][/P][P] [/P]
4楼
同怀念。多谢楼上,我还活着呢,呵呵。[EM05]

电脑版 Page created in 0.0625 seconds with 4 queries.