Exemple #1
0
 private static extern IntPtr RIL_Initialize(
     uint dwIndex,
     RILRESULTCALLBACK pfnResult,
     RILNOTIFYCALLBACK pfnNotify,
     uint dwNotificationClasses,
     uint dwParam,
     out IntPtr lphRil);
 private static extern IntPtr RIL_Initialize(
     uint dwIndex,
     RILRESULTCALLBACK pfnResult,
     RILNOTIFYCALLBACK pfnNotify,
     uint dwNotificationClasses,
     uint dwParam,
     out IntPtr lphRil);
        /*
         * Uses RIL to get CellID from the phone.
         */
        private void GetCellTowerInfo()
        {
            if (maybeCDMA)
            {
                return;
            }

            IntPtr hRil = IntPtr.Zero;

            try
            {
                // initialise handles
                IntPtr hRes = IntPtr.Zero;

                RILRESULTCALLBACK callback = new RILRESULTCALLBACK(rilResultCallback);
                try
                {
                    GCHandle cb = GCHandle.Alloc(callback, GCHandleType.Pinned);
                    callback = (RILRESULTCALLBACK)cb.Target;
                }
                catch { }

                // initialise RIL
                hRes = RIL_Initialize(1,         // RIL port 1
                                      callback,  // function to call with result
                                      null,      // function to call with notify
                                      0,         // classes of notification to enable
                                      0,         // RIL parameters
                                      out hRil); // RIL handle returned

                if (hRes != IntPtr.Zero)
                {
                    return;
                    //throw new Exception("Cannot connect to GSM chip.");
                }

                // initialised successfully

                // use RIL to get cell tower info with the RIL handle just created
                idChanged = false;
                hRes      = RIL_GetCellTowerInfo(hRil);

                // wait for cell tower info to be returned
                if (!waithandle.WaitOne(5000, false))
                {
                    maybeCDMA = true;
                    return;
                }


                //celltower info finished
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return;
            }
            finally
            {
                // finished - release the RIL handle
                try
                {
                    if (hRil != IntPtr.Zero)
                    {
                        RIL_Deinitialize(hRil);
                    }
                }
                catch { }
            }

            if (idChanged)
            {
                idChanged = false;
                OnTowerChanged(new EventArgs());
                return;
            }
            else
            {
                return;
            }
        }