From 46ab4129247a0b0fab450d4b022ed11ba7c0e03e Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 12:49:22 -0400 Subject: [PATCH 01/14] Running build on develop. --- .github/workflows/{ios.yml => macos_build.yml} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{ios.yml => macos_build.yml} (97%) diff --git a/.github/workflows/ios.yml b/.github/workflows/macos_build.yml similarity index 97% rename from .github/workflows/ios.yml rename to .github/workflows/macos_build.yml index e3d221271d..1408ff5a9e 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/macos_build.yml @@ -2,15 +2,15 @@ name: Android and iOS build on MacOS on: push: - branches: [ master ] + branches: [ develop ] pull_request: - branches: [ master ] + branches: [ develop ] jobs: build: runs-on: macOS-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@develop - name: Set XCode Version run: sudo xcode-select -s /Applications/Xcode_11.app From 1c744271f81e8ef2f77ad62de4002d97d34681ca Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 13:27:23 -0400 Subject: [PATCH 02/14] Keeping action to Master --- .github/workflows/macos_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos_build.yml b/.github/workflows/macos_build.yml index 1408ff5a9e..f47be594eb 100644 --- a/.github/workflows/macos_build.yml +++ b/.github/workflows/macos_build.yml @@ -10,7 +10,7 @@ jobs: build: runs-on: macOS-latest steps: - - uses: actions/checkout@develop + - uses: actions/checkout@master - name: Set XCode Version run: sudo xcode-select -s /Applications/Xcode_11.app From e5c1c55af2db59c39a8e61737582b80fb1eebd69 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 19:10:22 -0400 Subject: [PATCH 03/14] Starting Bluetooth Beacon Broadcasting. --- android/app/src/main/AndroidManifest.xml | 4 + android/build.gradle | 2 +- app/services/BroadcastingService.js | 122 +++++++++++++++++++++++ app/views/LocationTracking.js | 13 ++- package.json | 4 + 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 app/services/BroadcastingService.js diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index ccb7761d68..6a7cbc71f6 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,10 @@ + + + + { + + var contactArray; + if (contactArrayString !== null) { + contactArray = JSON.parse(contactArrayString); + } else { + contactArray = []; + } + + // Always work in UTC, not the local time in the contactData + var nowUTC = new Date().toISOString(); + var unixtimeUTC = Date.parse(nowUTC); + var unixtimeUTC_28daysAgo = unixtimeUTC - (60 * 60 * 24 * 1000 * 28); + + // Save the contact using the current lat-lon and the + // calculated UTC time (maybe a few milliseconds off from + // when the GPS data was collected, but that's unimportant + // for what we are doing.) + console.log('[GPS] Saving point:', contactArray.length); + var lat_lon_time = { + "uuid": contact["uuid"], + "time": unixtimeUTC + }; + contactArray.push(lat_lon_time); + + SetStoreData('CONTACT_DATA', contactArray); + }); +} + +function saveMyUUID(me) { + // Persist this contact data in our local storage of time/lat/lon values + + GetStoreData('MY_UUIDs') + .then(myUUIDArrayString => { + var myUUIDArray; + if (myUUIDArrayString !== null) { + myUUIDArray = JSON.parse(myUUIDArrayString); + } else { + myUUIDArray = []; + } + + // Always work in UTC, not the local time in the contactData + var nowUTC = new Date().toISOString(); + var unixtimeUTC = Date.parse(nowUTC); + var unixtimeUTC_28daysAgo = unixtimeUTC - (60 * 60 * 24 * 1000 * 28); + + var uuid_time = { + "uuid": me["uuid"], + "time": unixtimeUTC + }; + console.log('[GPS] Saving myUUID:', Moment(unixtimeUTC).format('MMM Do, H:mma'), me["uuid"], myUUIDArray.length); + myUUIDArray.push(uuid_time); + + SetStoreData('MY_UUIDs', myUUIDArray); + }); +} + +function loadLastUUIDAndBroadcast() { + GetStoreData('MY_UUIDs') + .then(myUUIDArrayString => { + var myUUIDArray; + if (myUUIDArrayString !== null) { + myUUIDArray = JSON.parse(myUUIDArrayString); + console.log("Loading last uuid ", myUUIDArray[myUUIDArray.length-1].uuid); + currentUUID = myUUIDArray[myUUIDArray.length-1].uuid; + broadcast(); + } else { + generateNewUUIDAndBroadcast(); + } + }); +} + +function broadcast() { + console.log("Broadcasting: ", currentUUID); + AndroidBLEAdvertiserModule.setCompanyId(0xFF); + AndroidBLEAdvertiserModule.broadcastPacket(currentUUID, [12,23,56,28]); + .then((sucess) => { + console.log("Broadcasting Sucessful", sucess); + }).catch(error => console.log("Broadcasting Error", error)); +} + +function generateNewUUIDAndBroadcast() { + UUIDGenerator.getRandomUUID((uuid) => { + currentUUID = uuid; + saveMyUUID({'uuid':uuid}); + broadcast(); + }); +} + +export default class BroadcastingServices { + static start() { + loadLastUUIDAndBroadcast(); + + BackgroundTimer.runBackgroundTimer(() => { + generateNewUUIDAndBroadcast(); + }, 1000 * 60 * 60); // Every hour, change UUID + + console.log("Starting Bluetooth"); + } + + static stop(nav) { + console.log("Stopping Bluetooth"); + BackgroundTimer.stopBackgroundTimer(); + } +} diff --git a/app/views/LocationTracking.js b/app/views/LocationTracking.js index 75d957d6d9..b624168c1a 100644 --- a/app/views/LocationTracking.js +++ b/app/views/LocationTracking.js @@ -19,6 +19,7 @@ import { } from 'react-native-popup-menu'; import colors from '../constants/colors'; import LocationServices from '../services/LocationService'; +import BroadcastingServices from '../services/BroadcastingService'; import BackgroundGeolocation from '@mauron85/react-native-background-geolocation'; import exportImage from './../assets/images/export.png'; import news from './../assets/images/newspaper.png'; @@ -79,7 +80,10 @@ class LocationTracking extends Component { } willParticipate = () => { - SetStoreData('PARTICIPATE', 'true').then(() => LocationServices.start()); + SetStoreData('PARTICIPATE', 'true').then(() => { + LocationServices.start(); + BroadcastingServices.start(); + }); // Check and see if they actually authorized in the system dialog. // If not, stop services and set the state to !isLogging @@ -91,6 +95,7 @@ class LocationTracking extends Component { }); } else if (authorization === BackgroundGeolocation.NOT_AUTHORIZED) { LocationServices.stop(this.props.navigation); + BroadcastingServices.stop(this.props.navigation); this.setState({ isLogging: false, }); @@ -107,7 +112,10 @@ class LocationTracking extends Component { } willParticipate = () => { - SetStoreData('PARTICIPATE', 'true').then(() => LocationServices.start()); + SetStoreData('PARTICIPATE', 'true').then(() => { + LocationServices.start(); + BroadcastingServices.start(); + }); this.setState({ isLogging: true, }); @@ -115,6 +123,7 @@ class LocationTracking extends Component { setOptOut = () => { LocationServices.stop(this.props.navigation); + BroadcastingServices.stop(this.props.navigation); this.setState({ isLogging: false, }); diff --git a/package.json b/package.json index 4780313b31..f4dfd1d2a8 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,14 @@ "@react-navigation/stack": "5.1.1", "i18next": "^19.3.3", "lodash": "4.17.15", + "moment": "^2.24.0", "patch-package": "^6.2.1", "postinstall-postinstall": "^2.0.0", "react": "16.9.0", "react-native": "0.61.5", "react-native-app-intro-slider": "^3.0.0", + "react-native-background-timer": "^2.2.0", + "react-native-ble-advertiser": "^0.0.3", "react-native-extended-stylesheet": "^0.12.0", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "~1.5.0", @@ -40,6 +43,7 @@ "react-native-safe-area-context": "0.6.0", "react-native-screens": "2.0.0-alpha.12", "react-native-share": "^3.1.0", + "react-native-uuid-generator": "^6.1.1", "react-native-webview": "^8.1.2", "react-native-zip-archive": "^5.0.1", "rn-fetch-blob": "^0.12.0" From 32ffe54676580ea2b9a626f14f09983305ea703b Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 19:22:16 -0400 Subject: [PATCH 04/14] Other ID was too big. --- app/services/BroadcastingService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/BroadcastingService.js b/app/services/BroadcastingService.js index 949e389788..a5cc61b50a 100644 --- a/app/services/BroadcastingService.js +++ b/app/services/BroadcastingService.js @@ -90,7 +90,7 @@ function loadLastUUIDAndBroadcast() { function broadcast() { console.log("Broadcasting: ", currentUUID); AndroidBLEAdvertiserModule.setCompanyId(0xFF); - AndroidBLEAdvertiserModule.broadcastPacket(currentUUID, [12,23,56,28]); + AndroidBLEAdvertiserModule.broadcastPacket(currentUUID, [12,23,56]) .then((sucess) => { console.log("Broadcasting Sucessful", sucess); }).catch(error => console.log("Broadcasting Error", error)); From 56e46a3ae2f0a225b2cd6ba963aca6cecc4d658c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 19:32:00 -0400 Subject: [PATCH 05/14] Only runs Bluetooth on Android --- app/services/BroadcastingService.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/services/BroadcastingService.js b/app/services/BroadcastingService.js index a5cc61b50a..1d19c6049e 100644 --- a/app/services/BroadcastingService.js +++ b/app/services/BroadcastingService.js @@ -88,12 +88,15 @@ function loadLastUUIDAndBroadcast() { } function broadcast() { - console.log("Broadcasting: ", currentUUID); - AndroidBLEAdvertiserModule.setCompanyId(0xFF); - AndroidBLEAdvertiserModule.broadcastPacket(currentUUID, [12,23,56]) - .then((sucess) => { - console.log("Broadcasting Sucessful", sucess); - }).catch(error => console.log("Broadcasting Error", error)); + // Do not run on iOS for now. + if (Platform.OS === 'android') { + console.log("Broadcasting: ", currentUUID); + AndroidBLEAdvertiserModule.setCompanyId(0xFF); + AndroidBLEAdvertiserModule.broadcastPacket(currentUUID, [12,23,56]) + .then((sucess) => { + console.log("Broadcasting Sucessful", sucess); + }).catch(error => console.log("Broadcasting Error", error)); + } } function generateNewUUIDAndBroadcast() { From d60f31bc23954bafdabda0b91145c0efb8e771dc Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 22:45:16 -0400 Subject: [PATCH 06/14] Changing Package version to 0.0.4 to pass tests on Phones without Bluetooth adapters. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4dfd1d2a8..648aa0dc76 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "react-native": "0.61.5", "react-native-app-intro-slider": "^3.0.0", "react-native-background-timer": "^2.2.0", - "react-native-ble-advertiser": "^0.0.3", + "react-native-ble-advertiser": "0.0.4", "react-native-extended-stylesheet": "^0.12.0", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "~1.5.0", From be3713a0c74ec62b076663907948d982526a32e3 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 23:07:43 -0400 Subject: [PATCH 07/14] 0.5.7 --- android/app/build.gradle | 4 ++-- ios/PrivateKit/Info.plist | 4 ++-- ios/PrivateKitTests/Info.plist | 2 +- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 6093cb2bec..ffb7151076 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -132,8 +132,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled true - versionCode 11 - versionName "0.5.4" + versionCode 12 + versionName "0.5.7" } splits { abi { diff --git a/ios/PrivateKit/Info.plist b/ios/PrivateKit/Info.plist index 9a1e4c9587..89689f7635 100644 --- a/ios/PrivateKit/Info.plist +++ b/ios/PrivateKit/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.4 + 0.5.7 CFBundleSignature ???? CFBundleVersion - 11 + 12 LSRequiresIPhoneOS NSAppTransportSecurity diff --git a/ios/PrivateKitTests/Info.plist b/ios/PrivateKitTests/Info.plist index ac7881dd9b..98d2313822 100644 --- a/ios/PrivateKitTests/Info.plist +++ b/ios/PrivateKitTests/Info.plist @@ -19,6 +19,6 @@ CFBundleSignature ???? CFBundleVersion - 11 + 12 diff --git a/package-lock.json b/package-lock.json index 15946fde29..74157f7553 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.6", + "version": "0.5.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1d98895a51..a1e2566990 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.6", + "version": "0.5.7", "private": true, "scripts": { "install:pod": "cd ios && pod install", From 3f59309e023e2cae0b32c65e187a68c9eeb77bfc Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 24 Mar 2020 23:33:26 -0400 Subject: [PATCH 08/14] 0.5.8 --- android/app/build.gradle | 4 ++-- ios/PrivateKit/Info.plist | 4 ++-- ios/PrivateKitTests/Info.plist | 2 +- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index ffb7151076..7b1b015f4e 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -132,8 +132,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled true - versionCode 12 - versionName "0.5.7" + versionCode 13 + versionName "0.5.8" } splits { abi { diff --git a/ios/PrivateKit/Info.plist b/ios/PrivateKit/Info.plist index 89689f7635..25b7e4bf58 100644 --- a/ios/PrivateKit/Info.plist +++ b/ios/PrivateKit/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.7 + 0.5.8 CFBundleSignature ???? CFBundleVersion - 12 + 13 LSRequiresIPhoneOS NSAppTransportSecurity diff --git a/ios/PrivateKitTests/Info.plist b/ios/PrivateKitTests/Info.plist index 98d2313822..3901a001ec 100644 --- a/ios/PrivateKitTests/Info.plist +++ b/ios/PrivateKitTests/Info.plist @@ -19,6 +19,6 @@ CFBundleSignature ???? CFBundleVersion - 12 + 13 diff --git a/package-lock.json b/package-lock.json index 74157f7553..9ec3d2d4e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.7", + "version": "0.5.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a1e2566990..31e0c0c912 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.7", + "version": "0.5.8", "private": true, "scripts": { "install:pod": "cd ios && pod install", From 7e127b647072876382016751ba8472fd4db8e9c6 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 26 Mar 2020 09:25:45 -0400 Subject: [PATCH 09/14] Migrating Bluetooth to 0.0.5 --- android/build.gradle | 2 +- app/services/BroadcastingService.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 970054aa54..8ff49b39df 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,7 @@ buildscript { compileSdkVersion = 28 buildToolsVersion = "28.0.3" targetSdkVersion = 28 - minSdkVersion = 23 + minSdkVersion = 21 supportLibVersion = "28.0.0" googlePlayServicesVersion = "11+" firebaseVersion = "11+" diff --git a/app/services/BroadcastingService.js b/app/services/BroadcastingService.js index 1d19c6049e..f89b59624b 100644 --- a/app/services/BroadcastingService.js +++ b/app/services/BroadcastingService.js @@ -92,7 +92,7 @@ function broadcast() { if (Platform.OS === 'android') { console.log("Broadcasting: ", currentUUID); AndroidBLEAdvertiserModule.setCompanyId(0xFF); - AndroidBLEAdvertiserModule.broadcastPacket(currentUUID, [12,23,56]) + AndroidBLEAdvertiserModule.broadcast(currentUUID, [12,23,56]) .then((sucess) => { console.log("Broadcasting Sucessful", sucess); }).catch(error => console.log("Broadcasting Error", error)); diff --git a/package.json b/package.json index 31e0c0c912..f4a8892a75 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "react-native": "0.61.5", "react-native-app-intro-slider": "^3.0.0", "react-native-background-timer": "^2.2.0", - "react-native-ble-advertiser": "0.0.4", + "react-native-ble-advertiser": "0.0.5", "react-native-extended-stylesheet": "^0.12.0", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "~1.5.0", From e6a2cc6340b8df4f1b4659c6678040663e11ea5a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 26 Mar 2020 09:29:23 -0400 Subject: [PATCH 10/14] Removing the tag for just build number increments on new versions. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4a8892a75..d8a5bc7624 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "install:pod": "cd ios && pod install", "postinstall": "patch-package", - "postversion": "react-native-version --increment-build" + "postversion": "react-native-version" }, "rnpm": { "assets": [ From 4c71c028cfa630cfb4651fdcc401e7bb017f2f65 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 26 Mar 2020 09:31:02 -0400 Subject: [PATCH 11/14] 0.5.9 --- android/app/build.gradle | 4 ++-- ios/PrivateKit/Info.plist | 4 ++-- ios/PrivateKitTests/Info.plist | 4 ++-- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 7b1b015f4e..a8e504e4dd 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -132,8 +132,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled true - versionCode 13 - versionName "0.5.8" + versionCode 14 + versionName "0.5.9" } splits { abi { diff --git a/ios/PrivateKit/Info.plist b/ios/PrivateKit/Info.plist index 25b7e4bf58..9100f0d3e8 100644 --- a/ios/PrivateKit/Info.plist +++ b/ios/PrivateKit/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.8 + 0.5.9 CFBundleSignature ???? CFBundleVersion - 13 + 14 LSRequiresIPhoneOS NSAppTransportSecurity diff --git a/ios/PrivateKitTests/Info.plist b/ios/PrivateKitTests/Info.plist index 3901a001ec..df5a366899 100644 --- a/ios/PrivateKitTests/Info.plist +++ b/ios/PrivateKitTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.0 + 0.5.9 CFBundleSignature ???? CFBundleVersion - 13 + 14 diff --git a/package-lock.json b/package-lock.json index 9ec3d2d4e1..165a839ab1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.8", + "version": "0.5.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d8a5bc7624..b6aa9f8b93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.8", + "version": "0.5.9", "private": true, "scripts": { "install:pod": "cd ios && pod install", From 2b20a2107c47bb3042de032e1f0dbc6923e9e0be Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 27 Mar 2020 18:22:07 -0400 Subject: [PATCH 12/14] 0.5.10 --- android/app/build.gradle | 4 ++-- ios/PrivateKit/Info.plist | 4 ++-- ios/PrivateKitTests/Info.plist | 4 ++-- package-lock.json | 2 +- package.json | 11 ++++++++--- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index a8e504e4dd..fe1a55f99a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -132,8 +132,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled true - versionCode 14 - versionName "0.5.9" + versionCode 15 + versionName "0.5.10" } splits { abi { diff --git a/ios/PrivateKit/Info.plist b/ios/PrivateKit/Info.plist index 9100f0d3e8..aff1738a08 100644 --- a/ios/PrivateKit/Info.plist +++ b/ios/PrivateKit/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.9 + 0.5.10 CFBundleSignature ???? CFBundleVersion - 14 + 15 LSRequiresIPhoneOS NSAppTransportSecurity diff --git a/ios/PrivateKitTests/Info.plist b/ios/PrivateKitTests/Info.plist index df5a366899..06fd4cccd2 100644 --- a/ios/PrivateKitTests/Info.plist +++ b/ios/PrivateKitTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.5.9 + 0.5.10 CFBundleSignature ???? CFBundleVersion - 14 + 15 diff --git a/package-lock.json b/package-lock.json index 34d7709677..0668e15b78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.9", + "version": "0.5.10", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ee07dc926f..b9c4e07def 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "privatekit", - "version": "0.5.9", + "version": "0.5.10", "private": true, "scripts": { "install:pod": "cd ios && pod install", @@ -10,7 +10,10 @@ "test": "jest test" }, "lint-staged": { - "*.js": ["prettier --write", "git add --force"] + "*.js": [ + "prettier --write", + "git add --force" + ] }, "husky": { "hooks": { @@ -74,6 +77,8 @@ }, "jest": { "preset": "react-native", - "setupFiles": ["./jestSetupFile.js"] + "setupFiles": [ + "./jestSetupFile.js" + ] } } From c969c89824809fd436507262e94cbb431499cfb1 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 28 Mar 2020 22:47:43 -0400 Subject: [PATCH 13/14] Saving contacts and Requesting permissions to turn bluetooth on --- app/services/BroadcastingService.js | 256 +++++++++++++++++++++------- package.json | 2 +- 2 files changed, 198 insertions(+), 60 deletions(-) diff --git a/app/services/BroadcastingService.js b/app/services/BroadcastingService.js index 5cc6758340..61b9c974ad 100644 --- a/app/services/BroadcastingService.js +++ b/app/services/BroadcastingService.js @@ -1,127 +1,265 @@ import { GetStoreData, SetStoreData } from '../helpers/General'; - +import { Alert, Platform } from 'react-native'; import BackgroundTimer from 'react-native-background-timer'; import UUIDGenerator from 'react-native-uuid-generator'; import Moment from 'moment'; import AndroidBLEAdvertiserModule from 'react-native-ble-advertiser'; +import { NativeEventEmitter, NativeModules } from 'react-native'; var currentUUID = null; +var onDeviceFound = null; +var onBTStatusChange = null; +var lastSeen = {}; -function saveContact(contact) { - // Persist this contact data in our local storage of time/lat/lon values +const c5_MINS = 1000 * 60 * 5; +const c28_DAYS = 1000 * 60 * 60 * 24 * 28; +const c1_HOUR = 1000 * 60; - GetStoreData('CONTACT_DATA').then(contactArrayString => { - var contactArray; - if (contactArrayString !== null) { - contactArray = JSON.parse(contactArrayString); - } else { - contactArray = []; +const MANUFACTURER_ID = 0xff; +const MANUFACTURER_DATA = [12, 23, 56]; + +function nowStr() { + return Moment(new Date()).format('H:mm') +} + +/* + * Check if the contact is new in the last 5 mins. + */ +function isNewContact(contact) { + var nowLocal = new Date().getTime(); + if (lastSeen[contact['uuid']] && lastSeen[contact['uuid']] > nowLocal - c5_MINS) { + //console.log('[Bluetooth]', nowStr(), currentUUID, 'Ignoring UUID for 5 mins:', contact['uuid']); + return false; // needs a space of 5 mins to log again. + } + + lastSeen[contact['uuid']] = nowLocal; + return true; +} + +/* + * Select only the last 28 days of data. + */ +function filterAfter(arrayIncludingTime, time) { + let curated = []; + for (let i = 0; i < arrayIncludingTime.length; i++) { + if (arrayIncludingTime[i]['time'] > time) { + curated.push(arrayIncludingTime[i]); + } } + return curated; +} - // Always work in UTC, not the local time in the contactData - var nowUTC = new Date().toISOString(); - var unixtimeUTC = Date.parse(nowUTC); - var unixtimeUTC_28daysAgo = unixtimeUTC - 60 * 60 * 24 * 1000 * 28; - - // Save the contact using the current lat-lon and the - // calculated UTC time (maybe a few milliseconds off from - // when the GPS data was collected, but that's unimportant - // for what we are doing.) - console.log('[GPS] Saving point:', contactArray.length); - var lat_lon_time = { - uuid: contact['uuid'], - time: unixtimeUTC, - }; - contactArray.push(lat_lon_time); +function saveContact(contact) { + // Persist this contact data in our local storage of time/uuid values + //console.log('[Bluetooth]', nowStr(), currentUUID, 'New Device Found', contact['uuid']); + if (isNewContact(contact)) { + GetStoreData('CONTACT_DATA', false).then(contactArray => { + if (!contactArray) { + contactArray = []; + } - SetStoreData('CONTACT_DATA', contactArray); - }); + // Always work in UTC, not the local time in the contactData + var nowUTC = new Date().toISOString(); + var unixtimeUTC = Date.parse(nowUTC); + + // Curate the list of contacts, only keep the last 28 days + let curated = filterAfter(contactArray, unixtimeUTC - c28_DAYS); + + var uuid_time = { + uuid: contact['uuid'], + time: unixtimeUTC, + }; + curated.push(uuid_time); + console.log('[Bluetooth]', nowStr(), currentUUID, + 'Saving contact:', contact['uuid'], curated.length); + + SetStoreData('CONTACT_DATA', curated); + }); + } } function saveMyUUID(me) { // Persist this contact data in our local storage of time/lat/lon values - GetStoreData('MY_UUIDs').then(myUUIDArrayString => { - var myUUIDArray; - if (myUUIDArrayString !== null) { - myUUIDArray = JSON.parse(myUUIDArrayString); - } else { + GetStoreData('MY_UUIDs', false).then(myUUIDArray => { + if (!myUUIDArray) { myUUIDArray = []; } // Always work in UTC, not the local time in the contactData var nowUTC = new Date().toISOString(); var unixtimeUTC = Date.parse(nowUTC); - var unixtimeUTC_28daysAgo = unixtimeUTC - 60 * 60 * 24 * 1000 * 28; + + // Curate the list of points, only keep the last 28 days + let curated = filterAfter(myUUIDArray, unixtimeUTC - c28_DAYS); var uuid_time = { uuid: me['uuid'], time: unixtimeUTC, }; + console.log( - '[GPS] Saving myUUID:', - Moment(unixtimeUTC).format('MMM Do, H:mma'), - me['uuid'], - myUUIDArray.length, + '[Bluetooth]', nowStr(), me['uuid'], + 'Saving myUUID:', me['uuid'], curated.length, ); - myUUIDArray.push(uuid_time); + curated.push(uuid_time); - SetStoreData('MY_UUIDs', myUUIDArray); + SetStoreData('MY_UUIDs', curated); }); } function loadLastUUIDAndBroadcast() { - GetStoreData('MY_UUIDs').then(myUUIDArrayString => { - var myUUIDArray; - if (myUUIDArrayString !== null) { - myUUIDArray = JSON.parse(myUUIDArrayString); + GetStoreData('MY_UUIDs', false).then(myUUIDArray => { + if (!myUUIDArray) { console.log( - 'Loading last uuid ', + '[Bluetooth]', nowStr(), myUUIDArray[myUUIDArray.length - 1].uuid, + 'Loading last uuid' ); - currentUUID = myUUIDArray[myUUIDArray.length - 1].uuid; - broadcast(); + var lastUUID = myUUIDArray[myUUIDArray.length - 1].uuid; + broadcast(lastUUID); } else { generateNewUUIDAndBroadcast(); } }); } -function broadcast() { +function broadcast(currentUUID) { + if (!currentUUID) return; // does not allow to start without UUID + // Do not run on iOS for now. if (Platform.OS === 'android') { - console.log('Broadcasting: ', currentUUID); - AndroidBLEAdvertiserModule.setCompanyId(0xff); - AndroidBLEAdvertiserModule.broadcast(currentUUID, [12, 23, 56]) - .then(sucess => { - console.log('Broadcasting Sucessful', sucess); - }) - .catch(error => console.log('Broadcasting Error', error)); + //console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting'); + AndroidBLEAdvertiserModule.setCompanyId(MANUFACTURER_ID); + AndroidBLEAdvertiserModule.broadcast(currentUUID, MANUFACTURER_DATA) + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting Sucessful', success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting Error', error)); + + //console.log('[Bluetooth]', nowStr(), currentUUID, "Starting Scanner"); + AndroidBLEAdvertiserModule.scan(MANUFACTURER_DATA, {}) + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Scan Successful", success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Scan Error", error)); + } +} + +function stopBroadcast(currentUUID) { + if (!currentUUID) return; // does not allow to start without UUID + + // Do not run on iOS for now. + if (Platform.OS === 'android') { + //console.log('[Bluetooth]', nowStr(), currentUUID, 'Stopping Broadcast'); + AndroidBLEAdvertiserModule.stopBroadcast() + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Broadcast Successful", success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Broadcast Error", error)); + + //console.log('[Bluetooth]', nowStr(), currentUUID, "Stopping Scanning"); + AndroidBLEAdvertiserModule.stopScan() + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Scan Successful", success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Scan Error", error)); } } function generateNewUUIDAndBroadcast() { UUIDGenerator.getRandomUUID(uuid => { + console.log('[Bluetooth]', nowStr(), currentUUID, 'Renewing this UUID'); + stopBroadcast(currentUUID); + currentUUID = uuid; saveMyUUID({ uuid: uuid }); - broadcast(); + + broadcast(currentUUID); }); } export default class BroadcastingServices { + static isBTActive() { + AndroidBLEAdvertiserModule.getAdapterState().then(result => { + console.log('[Bluetooth]', nowStr(), currentUUID, 'Bluetooth State', result); + if (result != 12) { + setTimeout(() => + Alert.alert( + 'Private Kit requires bluetooth to be enabled', + 'Would you like to enable Bluetooth?', + [ + { + text: 'Yes', + onPress: () => AndroidBLEAdvertiserModule.enableAdapter(), + }, + { + text: 'No', + onPress: () => console.log('No Pressed'), + style: 'cancel', + }, + ], + ), + 1000); + return false; + } else { + return true; + } + }).catch(error => { + return false; + console.log('[Bluetooth]', nowStr(), currentUUID, "BT Not Enabled") + }); + } + static start() { + const eventEmitter = new NativeEventEmitter(NativeModules.AndroidBLEAdvertiserModule); + onBTStatusChange = eventEmitter.addListener('onBTStatusChange', (status) => { + if (status.enabled) + BroadcastingServices.startAndSetCallbacks(); + else + BroadcastingServices.stopAndClearCallbacks(); + }); + + if (!BroadcastingServices.isBTActive()) return; + + BroadcastingServices.startAndSetCallbacks(); + } + + static stop() { + if (onBTStatusChange) { + onBTStatusChange.remove(); + onBTStatusChange = null; + } + + if (!BroadcastingServices.isBTActive()) return; + + BroadcastingServices.stopAndClearCallbacks(); + } + + static startAndSetCallbacks() { + // if it was already active + if (onDeviceFound) { + BroadcastingServices.stopAndClearCallbacks(); + } + + // listening event. + const eventEmitter = new NativeEventEmitter(NativeModules.AndroidBLEAdvertiserModule); + onDeviceFound = eventEmitter.addListener('onDeviceFound', (event) => { + //console.log('[Bluetooth]', nowStr(), currentUUID, 'New Device', event); + if (event.serviceUuids && event.serviceUuids.length > 0) + saveContact({ uuid: event.serviceUuids[0]}); + }); + + // Get a Valid UUID and start broadcasting and scanning. loadLastUUIDAndBroadcast(); BackgroundTimer.runBackgroundTimer(() => { generateNewUUIDAndBroadcast(); - }, 1000 * 60 * 60); // Every hour, change UUID - - console.log('Starting Bluetooth'); + }, c1_HOUR); // Every hour, change UUID } - static stop(nav) { - console.log('Stopping Bluetooth'); + static stopAndClearCallbacks() { + //console.log('[Bluetooth]', nowStr(), currentUUID, 'Stopping Bluetooth'); + stopBroadcast(currentUUID); + + if (onDeviceFound) { + onDeviceFound.remove(); + onDeviceFound = null; + } + BackgroundTimer.stopBackgroundTimer(); } } diff --git a/package.json b/package.json index b9c4e07def..8562c6c82f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "react-native": "0.61.5", "react-native-app-intro-slider": "^3.0.0", "react-native-background-timer": "^2.2.0", - "react-native-ble-advertiser": "0.0.5", + "react-native-ble-advertiser": "0.0.9", "react-native-extended-stylesheet": "^0.12.0", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "~1.5.0", From e8018a3fa83bf63173f1aef27490b5546787a4e2 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sun, 29 Mar 2020 16:34:23 -0400 Subject: [PATCH 14/14] Fully functioning version of Bluetooth on Android --- app/services/BroadcastingService.js | 149 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 76 insertions(+), 75 deletions(-) diff --git a/app/services/BroadcastingService.js b/app/services/BroadcastingService.js index 61b9c974ad..b2782031e9 100644 --- a/app/services/BroadcastingService.js +++ b/app/services/BroadcastingService.js @@ -14,7 +14,7 @@ var lastSeen = {}; const c5_MINS = 1000 * 60 * 5; const c28_DAYS = 1000 * 60 * 60 * 24 * 28; -const c1_HOUR = 1000 * 60; +const c1_HOUR = 1000 * 60 * 60; const MANUFACTURER_ID = 0xff; const MANUFACTURER_DATA = [12, 23, 56]; @@ -128,36 +128,30 @@ function loadLastUUIDAndBroadcast() { function broadcast(currentUUID) { if (!currentUUID) return; // does not allow to start without UUID - // Do not run on iOS for now. - if (Platform.OS === 'android') { - //console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting'); - AndroidBLEAdvertiserModule.setCompanyId(MANUFACTURER_ID); - AndroidBLEAdvertiserModule.broadcast(currentUUID, MANUFACTURER_DATA) - .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting Sucessful', success)) - .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting Error', error)); - - //console.log('[Bluetooth]', nowStr(), currentUUID, "Starting Scanner"); - AndroidBLEAdvertiserModule.scan(MANUFACTURER_DATA, {}) - .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Scan Successful", success)) - .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Scan Error", error)); - } + //console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting'); + AndroidBLEAdvertiserModule.setCompanyId(MANUFACTURER_ID); + AndroidBLEAdvertiserModule.broadcast(currentUUID, MANUFACTURER_DATA) + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting Sucessful', success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, 'Broadcasting Error', error)); + + //console.log('[Bluetooth]', nowStr(), currentUUID, "Starting Scanner"); + AndroidBLEAdvertiserModule.scan(MANUFACTURER_DATA, {}) + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Scan Successful", success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Scan Error", error)); } function stopBroadcast(currentUUID) { if (!currentUUID) return; // does not allow to start without UUID - // Do not run on iOS for now. - if (Platform.OS === 'android') { - //console.log('[Bluetooth]', nowStr(), currentUUID, 'Stopping Broadcast'); - AndroidBLEAdvertiserModule.stopBroadcast() - .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Broadcast Successful", success)) - .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Broadcast Error", error)); - - //console.log('[Bluetooth]', nowStr(), currentUUID, "Stopping Scanning"); - AndroidBLEAdvertiserModule.stopScan() - .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Scan Successful", success)) - .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Scan Error", error)); - } + //console.log('[Bluetooth]', nowStr(), currentUUID, 'Stopping Broadcast'); + AndroidBLEAdvertiserModule.stopBroadcast() + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Broadcast Successful", success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Broadcast Error", error)); + + //console.log('[Bluetooth]', nowStr(), currentUUID, "Stopping Scanning"); + AndroidBLEAdvertiserModule.stopScan() + .then(success => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Scan Successful", success)) + .catch(error => console.log('[Bluetooth]', nowStr(), currentUUID, "Stop Scan Error", error)); } function generateNewUUIDAndBroadcast() { @@ -173,60 +167,67 @@ function generateNewUUIDAndBroadcast() { } export default class BroadcastingServices { - static isBTActive() { - AndroidBLEAdvertiserModule.getAdapterState().then(result => { - console.log('[Bluetooth]', nowStr(), currentUUID, 'Bluetooth State', result); - if (result != 12) { - setTimeout(() => - Alert.alert( - 'Private Kit requires bluetooth to be enabled', - 'Would you like to enable Bluetooth?', - [ - { - text: 'Yes', - onPress: () => AndroidBLEAdvertiserModule.enableAdapter(), - }, - { - text: 'No', - onPress: () => console.log('No Pressed'), - style: 'cancel', - }, - ], - ), - 1000); - return false; - } else { - return true; - } - }).catch(error => { - return false; - console.log('[Bluetooth]', nowStr(), currentUUID, "BT Not Enabled") - }); + static askBTActive() { + setTimeout(() => + Alert.alert( + 'Private Kit requires bluetooth to be enabled', + 'Would you like to enable Bluetooth?', + [ + { + text: 'Yes', + onPress: () => AndroidBLEAdvertiserModule.enableAdapter(), + }, + { + text: 'No', + onPress: () => console.log('User does not want to activate Bluetooth'), + style: 'cancel', + }, + ], + ), + 1000); } static start() { - const eventEmitter = new NativeEventEmitter(NativeModules.AndroidBLEAdvertiserModule); - onBTStatusChange = eventEmitter.addListener('onBTStatusChange', (status) => { - if (status.enabled) - BroadcastingServices.startAndSetCallbacks(); - else - BroadcastingServices.stopAndClearCallbacks(); - }); - - if (!BroadcastingServices.isBTActive()) return; - - BroadcastingServices.startAndSetCallbacks(); + // Do not run on iOS for now. + if (Platform.OS === 'android') { + const eventEmitter = new NativeEventEmitter(NativeModules.AndroidBLEAdvertiserModule); + onBTStatusChange = eventEmitter.addListener('onBTStatusChange', (status) => { + console.log('[Bluetooth]', nowStr(), currentUUID, 'Bluetooth Status Change', status); + if (status.enabled) + BroadcastingServices.startAndSetCallbacks(); + else + BroadcastingServices.stopAndClearCallbacks(); + }); + + AndroidBLEAdvertiserModule.getAdapterState().then(result => { + console.log('[Bluetooth]', nowStr(), currentUUID, "isBTActive", result) + if (result === "STATE_ON") { + BroadcastingServices.startAndSetCallbacks(); + } else { + BroadcastingServices.askBTActive() + } + }).catch(error => { + console.log('[Bluetooth]', nowStr(), currentUUID, "BT Not Enabled") + }); + } } static stop() { - if (onBTStatusChange) { - onBTStatusChange.remove(); - onBTStatusChange = null; - } - - if (!BroadcastingServices.isBTActive()) return; + if (Platform.OS === 'android') { + if (onBTStatusChange) { + onBTStatusChange.remove(); + onBTStatusChange = null; + } - BroadcastingServices.stopAndClearCallbacks(); + AndroidBLEAdvertiserModule.getAdapterState().then(result => { + console.log('[Bluetooth]', nowStr(), currentUUID, "isBTActive", result) + if (result === "STATE_ON") { + BroadcastingServices.stopAndClearCallbacks(); + } + }).catch(error => { + console.log('[Bluetooth]', nowStr(), currentUUID, "BT Not Enabled") + }); + } } static startAndSetCallbacks() { @@ -238,7 +239,7 @@ export default class BroadcastingServices { // listening event. const eventEmitter = new NativeEventEmitter(NativeModules.AndroidBLEAdvertiserModule); onDeviceFound = eventEmitter.addListener('onDeviceFound', (event) => { - //console.log('[Bluetooth]', nowStr(), currentUUID, 'New Device', event); + console.log('[Bluetooth]', nowStr(), currentUUID, 'New Device', event); if (event.serviceUuids && event.serviceUuids.length > 0) saveContact({ uuid: event.serviceUuids[0]}); }); diff --git a/package.json b/package.json index 8562c6c82f..acc7bf80b4 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "react-native": "0.61.5", "react-native-app-intro-slider": "^3.0.0", "react-native-background-timer": "^2.2.0", - "react-native-ble-advertiser": "0.0.9", + "react-native-ble-advertiser": "0.0.10", "react-native-extended-stylesheet": "^0.12.0", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "~1.5.0",