Skip to content

Feature omniring #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: omniring-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
38646f3
feat: add gatt bluetooth callback
reyvababtista Sep 17, 2024
8c901b5
feat: add BLE service
reyvababtista Oct 11, 2024
60e64cf
refactor: reconfigure bluetooth listener
reyvababtista Oct 11, 2024
78fd2d8
feat: add omniring gatt listener
reyvababtista Oct 11, 2024
d88d905
feat: add omniring constants
reyvababtista Oct 11, 2024
fe8669d
refactor: add omniring timer
reyvababtista Oct 11, 2024
38ad535
chore: add network security config, clear text, and service
reyvababtista Oct 11, 2024
e0de7d1
chore: update gradle
reyvababtista Oct 11, 2024
4873293
refactor: revert bluetooth listener, remove disable bluetooth call
reyvababtista Oct 11, 2024
8fa8374
refactor: change class name
reyvababtista Oct 11, 2024
2a54ee8
refactor: change class name
reyvababtista Oct 11, 2024
391d7bc
refactor: data clean up
reyvababtista Oct 11, 2024
c31e112
refactor: logic clean up
reyvababtista Oct 11, 2024
318d764
fix: on off omniring logic
reyvababtista Oct 11, 2024
4899e1c
fix: on off omniring logic
reyvababtista Oct 11, 2024
4ba9f55
refactor: remove gattcallback
reyvababtista Oct 11, 2024
59f73d6
refactor: revert https
reyvababtista Oct 14, 2024
0b154b3
refactor: fix omniring logic
reyvababtista Oct 14, 2024
f674cfd
chore: fix bluetooth permission
reyvababtista Oct 14, 2024
5f2f9f3
chore: downgrade gradle
reyvababtista Oct 14, 2024
a9bbf42
refactor: add temperature value, change device name
reyvababtista Nov 25, 2024
5fa3bad
fix: omniring listener logic
reyvababtista Dec 2, 2024
449a07e
feat: add UTC to current timezone timestamp converter
reyvababtista Dec 2, 2024
f755896
fix: make on-off logging clearer
reyvababtista Dec 2, 2024
b0c3505
fix: make on-off logging clearer
reyvababtista Dec 2, 2024
7587a8d
fix: omniring on off logic
reyvababtista Dec 2, 2024
05fb7fd
refactor: separate bluetooth & omniring logic
reyvababtista Dec 2, 2024
cddf794
refactor: separate bluetooth & omniring permission logic
reyvababtista Dec 2, 2024
eac92bf
refactor: logging messages
reyvababtista Dec 5, 2024
6d7e893
refactor: logging messages
reyvababtista Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions app/src/main/AndroidManifest.xml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manifest looks fine, we do need to take a look at whether bluetooth permissions changed in the past couple versions.

Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,38 @@
<!-- required on android 13 -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<!-- Bluetooth -->
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />

<!-- Needed only if your app looks for Bluetooth devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Needed only if your app communicates with already-paired Bluetooth devices. - it looks like this is more broad, some call we make requires it. -->
<!--
Needed only if your app communicates with already-paired Bluetooth
devices.
-->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- Needed only if your app makes the device discoverable to Bluetooth devices. This might be incorrect... -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

<!--
Include "neverForLocation" only if you can strongly assert that
your app never derives physical location from Bluetooth scan results.
-->
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" /> <!-- This app is using bluetooth features but not required. -->
<uses-feature
android:name="android.hardware.bluetooth"
android:required="false" />
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="false" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="${appName}${appNameSuffix}"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">

<!-- ACTIVITIES -->

Expand Down Expand Up @@ -162,6 +174,10 @@
</intent-filter>
</service>

<service
android:name=".listeners.OmniringListener"
android:exported="false" />

<!-- RECEIVERS -->

<receiver android:name=".listeners.BootListener"
Expand Down
2,000 changes: 1,037 additions & 963 deletions app/src/main/java/org/beiwe/app/MainService.kt

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion app/src/main/java/org/beiwe/app/PermissionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ object PermissionHandler {
return PersistentData.getBluetoothEnabled() && checkBluetoothPermissions(context)
}

@JvmStatic
fun confirmOmniRing(context: Context): Boolean {
return PersistentData.getOmniRingEnabled() && checkBluetoothPermissions(context)
}

@JvmStatic
fun confirmAmbientAudioCollection(context: Context): Boolean {
return PersistentData.getAmbientAudioEnabled() && checkAccessRecordAudio(context)
Expand All @@ -264,7 +269,7 @@ object PermissionHandler {
if (!checkAccessCoarseLocation(context)) return Manifest.permission.ACCESS_COARSE_LOCATION
if (!checkAccessFineLocation(context)) return Manifest.permission.ACCESS_FINE_LOCATION
}
if (PersistentData.getBluetoothEnabled()) {
if (PersistentData.getBluetoothEnabled() || PersistentData.getOmniRingEnabled()) {
// android versions below 12 use permission.BLUETOOTH and permission.BLUETOOTH_ADMIN,
// 12+ uses permission.BLUETOOTH_CONNECT and permission.BLUETOOTH_SCAN
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Expand Down Expand Up @@ -361,6 +366,8 @@ object PermissionHandler {
permissions.put("most_recent_ambient_audio_stop", PersistentData.ambientAudioStop)
permissions.put("most_recent_bluetooth_start", PersistentData.bluetoothStart)
permissions.put("most_recent_bluetooth_stop", PersistentData.bluetoothStop)
permissions.put("most_recent_omniring_start", PersistentData.omniringStart)
permissions.put("most_recent_omniring_stop", PersistentData.omniringStop)
permissions.put("most_recent_gps_start", PersistentData.gpsStart)
permissions.put("most_recent_gps_stop", PersistentData.gpsStop)
permissions.put("most_recent_gyroscope_start", PersistentData.gyroscopeStart)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/beiwe/app/Timer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Timer(mainService: MainService) {
lateinit var gyroscopeOnIntent: Intent
lateinit var bluetoothOffIntent: Intent
lateinit var bluetoothOnIntent: Intent
lateinit var omniRingOffIntent: Intent
lateinit var omniRingOnIntent: Intent

lateinit var gpsOffIntent: Intent
lateinit var gpsOnIntent: Intent
Expand Down Expand Up @@ -77,6 +79,8 @@ class Timer(mainService: MainService) {
gyroscopeOnIntent = setupIntent(appContext.getString(R.string.turn_gyroscope_on))
bluetoothOffIntent = setupIntent(appContext.getString(R.string.turn_bluetooth_off))
bluetoothOnIntent = setupIntent(appContext.getString(R.string.turn_bluetooth_on))
omniRingOffIntent = setupIntent(appContext.getString(R.string.turn_omniring_off))
omniRingOnIntent = setupIntent(appContext.getString(R.string.turn_omniring_on))
gpsOffIntent = setupIntent(appContext.getString(R.string.turn_gps_off))
gpsOnIntent = setupIntent(appContext.getString(R.string.turn_gps_on))

Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/beiwe/app/listeners/BluetoothListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.bluetooth.BluetoothAdapter.LeScanCallback
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import org.beiwe.app.storage.EncryptionEngine
import org.beiwe.app.storage.PersistentData
Expand Down Expand Up @@ -97,9 +96,9 @@ class BluetoothListener : BroadcastReceiver() {
// this check was incorrect for 13 months, however bonded devices are not the same as connected devices.
// This check was never relevent before (nobody ever noticed), so now we are just removing the check entirely.
// If we want to implement more bluetooth safety checks, see http://stackoverflow.com/questions/3932228/list-connected-bluetooth-devices
// if ( bluetoothAdapter.getBondedDevices().isEmpty() ) {
// Log.d("BluetoothListener", "found a bonded bluetooth device, will not be turning off bluetooth.");
// externalBluetoothState = true; }
// if ( bluetoothAdapter.getBondedDevices().isEmpty() ) {
// Log.d("BluetoothListener", "found a bonded bluetooth device, will not be turning off bluetooth.");
// externalBluetoothState = true; }

if (!externalBluetoothState) { // if the outside world and us agree that it should be off, turn it off
bluetoothAdapter!!.disable()
Expand Down Expand Up @@ -159,7 +158,7 @@ class BluetoothListener : BroadcastReceiver() {
Log.i("BluetoothListener", "disable BLE scan.")
scanActive = false
bluetoothAdapter!!.stopLeScan(bluetoothCallback)
disableBluetooth()
// disableBluetooth()
}

/** Intelligently ACTUALLY STARTS a Bluetooth LE scan.
Expand All @@ -183,7 +182,8 @@ class BluetoothListener : BroadcastReceiver() {
@SuppressLint("NewApi")
private val bluetoothCallback = LeScanCallback { device, rssi, scanRecord ->
TextFileManager.getBluetoothLogFile().writeEncrypted(
System.currentTimeMillis().toString() + "," + EncryptionEngine.hashMAC(device.toString()) + "," + rssi
System.currentTimeMillis()
.toString() + "," + EncryptionEngine.hashMAC(device.toString()) + "," + rssi
)
// Log.i("Bluetooth", System.currentTimeMillis() + "," + device.toString() + ", " + rssi )
}
Expand Down
Loading