Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
android:exported="true"
android:foregroundServiceType="connectedDevice"
android:permission="android.permission.BLUETOOTH_CONNECT" />
<service
android:name=".services.TeamsNotifListener"
android:exported="true"
android:label="LibrePods Teams Mute Sync"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>

<service
android:name=".services.AirPodsQSService"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import me.kavishdevar.librepods.presentation.viewmodel.AirPodsViewModel
import me.kavishdevar.librepods.presentation.viewmodel.AppSettingsViewModel
import me.kavishdevar.librepods.presentation.viewmodel.PurchaseViewModel
import me.kavishdevar.librepods.services.AirPodsService
import me.kavishdevar.librepods.services.TeamsNotifListener
import me.kavishdevar.librepods.utils.XposedState
import me.kavishdevar.librepods.utils.isSupported
import kotlin.io.encoding.ExperimentalEncodingApi
Expand Down Expand Up @@ -694,6 +695,14 @@ fun PermissionsScreen(

val basicPermissionsGranted = permissionState.permissions.all { it.status.isGranted }

var notifAccessGranted by remember { mutableStateOf(TeamsNotifListener.isAccessGranted(context)) }
LaunchedEffect(Unit) {
while (true) {
kotlinx.coroutines.delay(1000)
notifAccessGranted = TeamsNotifListener.isAccessGranted(context)
}
}

val infiniteTransition = rememberInfiniteTransition(label = "pulse")
val pulseScale by infiniteTransition.animateFloat(
initialValue = 1f, targetValue = 1.05f, animationSpec = infiniteRepeatable(
Expand Down Expand Up @@ -819,10 +828,25 @@ fun PermissionsScreen(
accentColor = accentColor
)

PermissionCard(
title = "Notification Access",
description = "To sync mute state with Microsoft Teams",
icon = Icons.Default.Notifications,
isGranted = notifAccessGranted,
backgroundColor = backgroundColor,
textColor = textColor,
accentColor = accentColor
)

Spacer(modifier = Modifier.height(24.dp))

Button(
onClick = { permissionState.launchMultiplePermissionRequest() },
onClick = {
permissionState.launchMultiplePermissionRequest()
if (!notifAccessGranted) {
TeamsNotifListener.openAccessSettings(context)
}
},
modifier = Modifier
.fillMaxWidth()
.height(55.dp),
Expand Down Expand Up @@ -873,6 +897,30 @@ fun PermissionsScreen(
)
}

Spacer(modifier = Modifier.height(12.dp))

Button(
onClick = { TeamsNotifListener.openAccessSettings(context) },
modifier = Modifier
.fillMaxWidth()
.height(55.dp),
colors = ButtonDefaults.buttonColors(
containerColor = if (notifAccessGranted) Color.Gray else accentColor
),
enabled = !notifAccessGranted,
shape = RoundedCornerShape(8.dp)
) {
Text(
if (notifAccessGranted) "Notification Access Granted" else "Grant Notification Access",
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Medium,
fontFamily = FontFamily(Font(R.font.sf_pro)),
color = Color.White
),
)
}

if (!canDrawOverlays && basicPermissionsGranted) {
Spacer(modifier = Modifier.height(12.dp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ enum class StemAction {
PREVIOUS_TRACK,
NEXT_TRACK,
DIGITAL_ASSISTANT,
CYCLE_NOISE_CONTROL_MODES;
CYCLE_NOISE_CONTROL_MODES,
MUTE_CALL;
companion object {
fun fromString(action: String): StemAction? {
return entries.find { it.name == action }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ fun AirPodsSettingsScreen(viewModel: AirPodsViewModel, navController: NavControl
to = "head_tracking",
name = stringResource(R.string.head_gestures),
navController = navController,
currentState = if (sharedPreferences.getBoolean(
"head_gestures", false
)
currentState = if (sharedPreferences.getBoolean("head_gestures_enabled", true) &&
(sharedPreferences.getBoolean("head_gestures_answer_call", true)
|| sharedPreferences.getBoolean("head_gestures_mute_call", true))
) stringResource(R.string.on) else stringResource(R.string.off)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,30 @@ fun HeadTrackingScreen(viewModel: AirPodsViewModel, navController: NavController
}

StyledToggle(
label = "Head Gestures",
label = "Head gestures",
checked = state.headGesturesEnabled,
onCheckedChange = { viewModel.setHeadGesturesEnabled(it) },
enabled = state.isPremium || state.headGesturesEnabled,
description = stringResource(R.string.head_gestures_details)
description = "Master switch for all head gesture features."
)

StyledToggle(
label = "Answer/decline incoming calls",
checked = state.headGesturesAnswerCall,
onCheckedChange = { viewModel.setHeadGesturesAnswerCall(it) },
enabled = state.headGesturesEnabled && (state.isPremium || state.headGesturesAnswerCall),
description = "Nod to answer an incoming call, shake your head to decline."
)

StyledToggle(
label = "Mute/unmute during a call",
checked = state.headGesturesMuteCall,
onCheckedChange = { viewModel.setHeadGesturesMuteCall(it) },
enabled = state.headGesturesEnabled && (state.isPremium || state.headGesturesMuteCall),
description = "Shake your head during an active call to mute the mic, nod to unmute."
)


Spacer(modifier = Modifier.height(16.dp))
Text(
"Head Orientation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ data class AirPodsUiState(

val headTrackingActive: Boolean = false,
val headGesturesEnabled: Boolean = true,
val headGesturesAnswerCall: Boolean = true,
val headGesturesMuteCall: Boolean = true,

val eqData: FloatArray = floatArrayOf(),

Expand Down Expand Up @@ -178,6 +180,8 @@ class AirPodsViewModel(
false
)
setHeadGesturesEnabled(false)
setHeadGesturesAnswerCall(false)
setHeadGesturesMuteCall(false)
}
_uiState.update { it.copy(isPremium = premium) }
}
Expand Down Expand Up @@ -340,7 +344,9 @@ class AirPodsViewModel(
sharedPreferences.getBoolean("automatic_ear_detection", true)
val automaticConnectionEnabled =
sharedPreferences.getBoolean("automatic_connection_ctrl_cmd", true)
val headGesturesEnabled = sharedPreferences.getBoolean("head_gestures", true)
val headGesturesEnabled = sharedPreferences.getBoolean("head_gestures_enabled", true)
val headGesturesAnswerCall = sharedPreferences.getBoolean("head_gestures_answer_call", true)
val headGesturesMuteCall = sharedPreferences.getBoolean("head_gestures_mute_call", true)
val leftAction = StemAction.valueOf(
sharedPreferences.getString(
"left_long_press_action",
Expand All @@ -364,6 +370,8 @@ class AirPodsViewModel(
automaticEarDetectionEnabled = automaticEarDetectionEnabled,
automaticConnectionEnabled = automaticConnectionEnabled,
headGesturesEnabled = headGesturesEnabled,
headGesturesAnswerCall = headGesturesAnswerCall,
headGesturesMuteCall = headGesturesMuteCall,
leftAction = leftAction,
rightAction = rightAction,
vendorIdHook = vendorIdHook,
Expand All @@ -382,12 +390,26 @@ class AirPodsViewModel(
}

fun setHeadGesturesEnabled(enabled: Boolean) {
sharedPreferences.edit { putBoolean("head_gestures", enabled) }
sharedPreferences.edit { putBoolean("head_gestures_enabled", enabled) }
_uiState.update {
it.copy(headGesturesEnabled = enabled)
}
}

fun setHeadGesturesAnswerCall(enabled: Boolean) {
sharedPreferences.edit { putBoolean("head_gestures_answer_call", enabled) }
_uiState.update {
it.copy(headGesturesAnswerCall = enabled)
}
}

fun setHeadGesturesMuteCall(enabled: Boolean) {
sharedPreferences.edit { putBoolean("head_gestures_mute_call", enabled) }
_uiState.update {
it.copy(headGesturesMuteCall = enabled)
}
}

fun setDynamicEndOfCharge(enabled: Boolean) {
service.aacpManager.sendControlCommand(ControlCommandIdentifiers.DYNAMIC_END_OF_CHARGE.value, enabled)
sharedPreferences.edit { putBoolean("dynamic_end_of_charge", enabled) }
Expand Down
Loading