Exemple #1
0
 private async void _watcher_LineAdded(PhoneLineWatcher sender, PhoneLineWatcherEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         ViewModel.PhoneLines.Add(args.LineId);
     });
 }
Exemple #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (_LineWatcher == null)
            {
                PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                _LineWatcher              = store.RequestLineWatcher();
                _LineWatcher.LineAdded   += _watcher_LineAdded;
                _LineWatcher.LineRemoved += _watcher_LineRemoved;

                _LineWatcher.Start();
            }
            string str = PhoneLineTransportDevice.GetDeviceSelector(PhoneLineTransport.Bluetooth);

            if (_DeviceWatcher == null)
            {
                _DeviceWatcher          = DeviceInformation.CreateWatcher(str);
                _DeviceWatcher.Added   += _DeviceWatcher_Added;
                _DeviceWatcher.Removed += _DeviceWatcher_Removed;

                _DeviceWatcher.Start();
            }

            string str1  = BluetoothDevice.GetDeviceSelector();
            var    watch = DeviceInformation.CreateWatcher(str1);

            watch.Added   += _DeviceWatcher_Added;
            watch.Removed += _DeviceWatcher_Removed;
            watch.Start();
        }
Exemple #3
0
        private static void LineWatcher_LineRemoved(PhoneLineWatcher sender, PhoneLineWatcherEventArgs args)
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine("LineRemoved: " + args.LineId);
#endif
            if (Guid.Equals(args.LineId, LineId))
            {
                Line   = null;
                LineId = Guid.Empty;
            }
        }
Exemple #4
0
        private async void _watcher_LineRemoved(PhoneLineWatcher sender, PhoneLineWatcherEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("Line removing: {0}", args.LineId);
#endif
                Guid id = args.LineId;
                ViewModel.PhoneLines.Remove(id);
            });
        }
Exemple #5
0
        private static async void LineWatcher_LineAdded(PhoneLineWatcher sender, PhoneLineWatcherEventArgs args)
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine("LineAdded: " + args.LineId);
#endif
            PhoneLine line = await PhoneLine.FromIdAsync(args.LineId);

            if (line.TransportDeviceId == DeviceInfo.Id)
            {
                Line   = line;
                LineId = args.LineId;
            }
        }
Exemple #6
0
        public static async Task <bool> EnsureInitPhoneLineWatcher()
        {
            if (LineWatcher == null)
            {
                PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                if (store == null)
                {
                    return(false);
                }
                LineWatcher              = store.RequestLineWatcher();
                LineWatcher.LineAdded   += LineWatcher_LineAdded;
                LineWatcher.LineRemoved += LineWatcher_LineRemoved;
                LineWatcher.LineUpdated += LineWatcher_LineUpdated;
            }

            return(true);
        }
Exemple #7
0
        private static void LineWatcher_LineUpdated(PhoneLineWatcher sender, PhoneLineWatcherEventArgs args)
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine("LineUpdated: " + args.LineId);
#endif
        }
Exemple #8
0
        private async void Load()
        {
            string displayname = "";

            if (device != null)
            {
                if (device.AccountPhoneNumber != null)
                {
                    displayname = device.AccountPhoneNumber;
                }

                switch (device.DeviceStatus)
                {
                case SmsDeviceStatus.DeviceBlocked:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.DeviceFailure:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.DeviceLocked:
                {
                    StatusIcon.Text = "";
                    break;
                }

                case SmsDeviceStatus.Off:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.Ready:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.SimNotInserted:
                case SmsDeviceStatus.SubscriptionNotActivated:
                case SmsDeviceStatus.BadSim:
                {
                    StatusIcon.Text = "";
                    break;
                }
                }
            }

            try
            {
                string selectorStr = MobileBroadbandModem.GetDeviceSelector();
                DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selectorStr);

                foreach (var mdevice in devices)
                {
                    MobileBroadbandModem modem = MobileBroadbandModem.FromId(mdevice.Id);
                    if (modem.DeviceInformation.TelephoneNumbers.Count > 0)
                    {
                        if (modem.DeviceInformation.TelephoneNumbers.Any(x => x == device.AccountPhoneNumber))
                        {
                            displayname = modem.CurrentNetwork.RegisteredProviderName;

                            // from https://github.com/ADeltaX/MobileShell/blob/experiments/src/App.xaml.cs
                            PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                            PhoneLineWatcher            watcher    = store.RequestLineWatcher();
                            List <PhoneLine>            phoneLines = new List <PhoneLine>();
                            TaskCompletionSource <bool> lineEnumerationCompletion = new TaskCompletionSource <bool>();

                            watcher.LineAdded            += async(o, args) => { var line = await PhoneLine.FromIdAsync(args.LineId); phoneLines.Add(line); };
                            watcher.Stopped              += (o, args) => lineEnumerationCompletion.TrySetResult(false);
                            watcher.EnumerationCompleted += (o, args) => lineEnumerationCompletion.TrySetResult(true);

                            watcher.Start();

                            if (await lineEnumerationCompletion.Task)
                            {
                                watcher.Stop();

                                List <PhoneLine> returnedLines = new List <PhoneLine>();

                                foreach (PhoneLine phoneLine in phoneLines)
                                {
                                    if (phoneLine != null && phoneLine.Transport == PhoneLineTransport.Cellular)
                                    {
                                        returnedLines.Add(phoneLine);
                                    }
                                }

                                if (returnedLines.Any(x => x.NetworkName == modem.CurrentNetwork.RegisteredProviderName))
                                {
                                    var line = returnedLines.First(x => x.NetworkName == modem.CurrentNetwork.RegisteredProviderName);
                                    displayname += " (SIM " + (line.CellularDetails.SimSlotIndex + 1) + ")";
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch
            {
            }

            if (string.IsNullOrEmpty(displayname))
            {
                displayname = "Unidentified SIM";
            }

            LineName.Text = displayname;
        }