예제 #1
0
        public void testCompressEntireURLInCapsWithPath()
        {
            String testURL = "HTTPS://WWW.RADIUSNETWORKS.COM/C2HC48";

            byte[] expectedBytes = { 0x01, (byte)'r', (byte)'a', (byte)'d', (byte)'i', (byte)'u', (byte)'s', (byte)'n', (byte)'e', (byte)'t', (byte)'w', (byte)'o', (byte)'r', (byte)'k', (byte)'s', 0x00, (byte)'C', (byte)'2', (byte)'H', (byte)'C', (byte)'4', (byte)'8' };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #2
0
        public void testCompressWithDotCaTLDWithSlash()
        {
            String testURL = "http://google.ca/";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', (byte)'.', (byte)'c', (byte)'a', (byte)'/' };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #3
0
        public void testCompressHttpsAndWWWInCaps()
        {
            String testURL = "HTTPS://WWW.radiusnetworks.com";

            byte[] expectedBytes = { 0x01, (byte)'r', (byte)'a', (byte)'d', (byte)'i', (byte)'u', (byte)'s', (byte)'n', (byte)'e', (byte)'t', (byte)'w', (byte)'o', (byte)'r', (byte)'k', (byte)'s', 0x07 };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #4
0
        public void testCompressWithDotInfoTLD()
        {
            String testURL = "http://google.info";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x0b };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #5
0
        public void testCompressWithSubdomainsAndSlashesInPath()
        {
            String testURL = "http://www.forums.google.com/123/456";

            byte[] expectedBytes = { 0x00, (byte)'f', (byte)'o', (byte)'r', (byte)'u', (byte)'m', (byte)'s', (byte)'.', (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', 0x00, (byte)'1', (byte)'2', (byte)'3', (byte)'/', (byte)'4', (byte)'5', (byte)'6' };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #6
0
        public void testCompressWithMoreSubdomains()
        {
            String testURL = "http://www.forums.developer.google.com/123";

            byte[] expectedBytes = { 0x00,
                                     Convert.ToByte('f'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('u'),
                                     Convert.ToByte('m'),
                                     Convert.ToByte('s'),
                                     Convert.ToByte('.'),
                                     Convert.ToByte('d'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('v'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('p'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('.'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('e'),
                                     0x00,
                                     Convert.ToByte('1'),
                                     Convert.ToByte('2'),
                                     Convert.ToByte('3') };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #7
0
        public void testCompressWithDomainInCaps()
        {
            String testURL = "http://GOO.GL/C2HC48";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'.', (byte)'g', (byte)'l', (byte)'/', (byte)'C', (byte)'2', (byte)'H', (byte)'C', (byte)'4', (byte)'8' };
            String hexBytes      = bytesToHex(UrlBeaconUrlCompressor.Compress(testURL));

            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #8
0
        public void testCompressWithDotCoTLD()
        {
            String testURL = "http://google.co";

            byte[] expectedBytes = { 0x02, (byte)'g', (byte)'o', (byte)'o', (byte)'g', (byte)'l', (byte)'e', (byte)'.', (byte)'c', (byte)'o' };
            String hexBytes      = bytesToHex(UrlBeaconUrlCompressor.Compress(testURL));

            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #9
0
        public void testCompressWithoutTLD()
        {
            String testURL = "http://xxx";

            byte[] expectedBytes = { 0x02,
                                     Convert.ToByte('x'),
                                     Convert.ToByte('x'),
                                     Convert.ToByte('x') };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #10
0
        public void testCompressWithTrailingSlash()
        {
            String testURL = "http://google.com/123";

            byte[] expectedBytes = { 0x02,
                                     Convert.ToByte('g'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('e'),
                                     0x00,
                                     Convert.ToByte('1'),
                                     Convert.ToByte('2'),
                                     Convert.ToByte('3') };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #11
0
        public void testCompressWithSubdomainsWithTrailingSlash()
        {
            String testURL = "http://www.forums.google.com/";

            byte[] expectedBytes = { 0x00,
                                     Convert.ToByte('f'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('u'),
                                     Convert.ToByte('m'),
                                     Convert.ToByte('s'),
                                     Convert.ToByte('.'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('g'),
                                     Convert.ToByte('l'),
                                     Convert.ToByte('e'),
                                     0x00 };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #12
0
        public void testCompressHttpsURL()
        {
            String testURL = "https://www.radiusnetworks.com";

            byte[] expectedBytes = { 0x01,
                                     Convert.ToByte('r'),
                                     Convert.ToByte('a'),
                                     Convert.ToByte('d'),
                                     Convert.ToByte('i'),
                                     Convert.ToByte('u'),
                                     Convert.ToByte('s'),
                                     Convert.ToByte('n'),
                                     Convert.ToByte('e'),
                                     Convert.ToByte('t'),
                                     Convert.ToByte('w'),
                                     Convert.ToByte('o'),
                                     Convert.ToByte('r'),
                                     Convert.ToByte('k'),
                                     Convert.ToByte('s'),
                                     0x07 };
            Assert.True(Arrays.Equals(expectedBytes, UrlBeaconUrlCompressor.Compress(testURL)));
        }
예제 #13
0
        public async Task <bool> StartBroadcastingBle(Context context, Shoot ev)
        {
            //ask to turn on bluetooth:
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.DefaultAdapter;

            var allprefs = context.GetSharedPreferences(WhiteLabelConfig.BUILD_VARIANT.ToLower(), FileCreationMode.Private);
            //var prefs = allprefs.Edit();
            var useble = allprefs.GetBoolean("ble-" + ev.id, true);

            //prefs.PutInt("ble_enable", currentversion);
            //prefs.Apply();
            if (!useble)
            {
                return(false);
            }

            if (mBluetoothAdapter.State == State.Off)
            {
                //ask to turn on:
                TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
                var dialog = new Android.Support.V7.App.AlertDialog.Builder(context);
                dialog.SetTitle(Resource.String.enableble);
                dialog.SetMessage(Resource.String.blemessage);
                dialog.SetPositiveButton(Android.Resource.String.Yes, (o, e) =>
                {
                    tcs.SetResult(true);
                });

                dialog.SetNegativeButton(Android.Resource.String.No, (o, e) =>
                {
                    tcs.SetResult(false);
                });

                dialog.Show();

                var result = await tcs.Task;
                if (result)
                {
                    allprefs.Edit().PutBoolean("ble-" + ev.id, true).Apply();

                    //turn on ble
                    mBluetoothAdapter.Enable();
                    //need to wait for ble event saying its started here:
                    await Task.WhenAny(Task.Delay(3000), Task.Factory.StartNew(() =>
                    {
                        while (mBluetoothAdapter.State != State.On)
                        {
                            Task.Yield();
                        }
                    }));
                }
                else
                {
                    allprefs.Edit().PutBoolean("ble-" + ev.id, false).Apply();
                    return(false);
                }
            }

            var compat = BeaconTransmitter.CheckTransmissionSupported(context);

            if (compat == BeaconTransmitter.Supported)
            {
                try
                {
                    byte[] urlBytes = UrlBeaconUrlCompressor.Compress("https://" + WhiteLabelConfig.BEACONHOST + "/b/");// 91071");//+ev.offlinecode);
                    //HACK: remove line!
                    //ev.offlinecode = "91071";
                    List <byte> bytes = new List <byte>(urlBytes);
                    bytes.AddRange(Encoding.ASCII.GetBytes(ev.offlinecode));

                    urlBytes = bytes.ToArray();

                    Identifier        encodedUrlIdentifier = Identifier.FromBytes(urlBytes, 0, urlBytes.Length, false);
                    List <Identifier> identifiers          = new List <Identifier>();
                    identifiers.Add(encodedUrlIdentifier);
                    beacon = new Beacon.Builder()
                             .SetIdentifiers(identifiers)
                             .SetServiceUuid(0xfeaa)
                             .SetManufacturer(0x0118)
                             .SetBeaconTypeCode(0x10)
                             .SetTxPower(-59)
                             .Build();
                    BeaconParser beaconParser = new BeaconParser().SetBeaconLayout(BeaconParser.EddystoneUrlLayout);

                    beaconTransmitter = new BeaconTransmitter(context, beaconParser);

                    beaconTransmitter.StartAdvertising(beacon, this);
                }
                catch (MalformedURLException)
                {
                    Log.Debug("BOOTLEGGER", "That URL cannot be parsed");
                }
                return(true);
            }
            else
            {
                //not supported
                return(false);
            }
        }