Skip to content

Commit

Permalink
include instance source into VolumeHandler logs
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Aug 31, 2024
1 parent f4e2c7a commit 48bb0b5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class MainActivity : AppCompatActivity(), TimerInterface {
supportActionBar?.setDisplayShowTitleEnabled(false)

mTrigger = Trigger(this)
mVolumeHandler = VolumeHandler(this)
mVolumeHandler = VolumeHandler(this, "MainActivity")

button_check = getString(R.string.timecheck_stopped)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SET
import de.felixnuesse.timedsilence.util.PermissionManager
import de.felixnuesse.timedsilence.extensions.TAG

class VolumeHandler(private var mContext: Context) {
class VolumeHandler(private var mContext: Context, private var mInstanceContext: String) {

private var mPreferencesManager = PreferencesManager(mContext)
private var volumeState = VolumeState(PreferencesManager(mContext).getDefaultUnsetVolume())
Expand Down Expand Up @@ -77,7 +77,7 @@ class VolumeHandler(private var mContext: Context) {
}

private fun applySilent() {
Log.e(TAG(), "VolumeHandler: Apply: Silent!")
Log.e(TAG(), "VolumeHandler - $mInstanceContext: Apply: Silent!")
val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager


Expand All @@ -94,7 +94,7 @@ class VolumeHandler(private var mContext: Context) {


if(mPreferencesManager.changeRingerVolume()){
Log.d(TAG(), "VolumeHandler: Setting Ringer! This might be not what you want!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Setting Ringer! This might be not what you want!")
setStreamToPercent(
manager,
AudioManager.STREAM_RING,
Expand All @@ -113,7 +113,7 @@ class VolumeHandler(private var mContext: Context) {
}

private fun applyLoud() {
Log.d(TAG(), "VolumeHandler: Apply: Loud!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Apply: Loud!")
val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager

val mNotificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
Expand All @@ -132,9 +132,9 @@ class VolumeHandler(private var mContext: Context) {
setMediaVolume(mediaVolume, manager)
}

Log.d(TAG(), "VolumeHandler: STREAM_MEDIA: $mediaVolume")
Log.d(TAG(), "VolumeHandler: STREAM_ALARM: $alarmVolume")
Log.d(TAG(), "VolumeHandler: STREAM_NOTIFICATION: $notifcationVolume")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_MEDIA: $mediaVolume")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_ALARM: $alarmVolume")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_NOTIFICATION: $notifcationVolume")


setStreamToPercent(
Expand All @@ -149,8 +149,8 @@ class VolumeHandler(private var mContext: Context) {
)

if(mPreferencesManager.changeRingerVolume()){
Log.d(TAG(), "VolumeHandler: STREAM_RING: $ringerVolume")
Log.d(TAG(), "VolumeHandler: Setting Ringer! This might be not what you want!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: STREAM_RING: $ringerVolume")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Setting Ringer! This might be not what you want!")
setStreamToPercent(
manager,
AudioManager.STREAM_RING,
Expand All @@ -161,7 +161,7 @@ class VolumeHandler(private var mContext: Context) {
}

private fun applyVibrate() {
Log.d(TAG(), "VolumeHandler: Apply: Vibrate!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Apply: Vibrate!")
val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager

val mNotificationManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
Expand Down Expand Up @@ -190,7 +190,7 @@ class VolumeHandler(private var mContext: Context) {
)

if(mPreferencesManager.changeRingerVolume()){
Log.d(TAG(), "VolumeHandler: Silencing Ringer! This might be not what you want!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Silencing Ringer! This might be not what you want!")
setStreamToPercent(
manager,
AudioManager.STREAM_RING,
Expand All @@ -208,11 +208,11 @@ class VolumeHandler(private var mContext: Context) {

private fun setMediaVolume(percentage: Int, manager: AudioManager){

Log.d(TAG(), "VolumeHandler: Setting Audio Volume!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Setting Audio Volume!")
val ignoreCheckWhenConnected = mPreferencesManager.checkIfHeadsetIsConnected()

if(HeadsetHandler.headphonesConnected(mContext) && ignoreCheckWhenConnected){
Log.d(TAG(), "VolumeHandler: Found headset, skipping...")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Found headset, skipping...")
return
}

Expand All @@ -221,11 +221,11 @@ class VolumeHandler(private var mContext: Context) {
AudioManager.STREAM_MUSIC,
percentage
)
Log.d(TAG(), "VolumeHandler: Mediavolume set.")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Mediavolume set.")
}

fun isButtonClickAudible(): Boolean{
Log.d(TAG(), "VolumeHandler: Check if Buttonclicks are audible")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Check if Buttonclicks are audible")
val manager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
if(0>=manager.getStreamVolume(AudioManager.STREAM_RING)){
return false
Expand All @@ -235,29 +235,29 @@ class VolumeHandler(private var mContext: Context) {

fun applyVolume(){
if(!PermissionManager(mContext).grantedDoNotDisturbAndNotify()){
Log.d(TAG(), "VolumeHandler: VolumeSetting: Do not disturb not granted! Not changing Volume!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: VolumeSetting: Do not disturb not granted! Not changing Volume!")
return
}

Log.d(TAG(), "VolumeHandler: VolumeSetting: ${getVolume()}")
LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(getVolume())} - ${volumeState.getReason()}")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: VolumeSetting: ${getVolume()}")
LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(getVolume())} - ${volumeState.getReason()}")

when (getVolume()) {
TIME_SETTING_SILENT -> {
applySilent()
LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_SILENT)} - ${volumeState.getReason()}")
LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_SILENT)} - ${volumeState.getReason()}")
}
TIME_SETTING_VIBRATE -> {
applyVibrate()
LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_VIBRATE)} - ${volumeState.getReason()}")
LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_VIBRATE)} - ${volumeState.getReason()}")
}
TIME_SETTING_LOUD -> {
applyLoud()
LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_LOUD)} - ${volumeState.getReason()}")
LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","${VolumeState.timeSettingToReadable(TIME_SETTING_LOUD)} - ${volumeState.getReason()}")
}
else -> {
Log.d(TAG(), "VolumeHandler: Apply: Nothing, because no volume was selecteds!")
LogHandler.writeLog(mContext,"VolumeHandler", "because applyVolume was called","Nothing, because no volume was selected!")
Log.d(TAG(), "VolumeHandler - $mInstanceContext: Apply: Nothing, because no volume was selecteds!")
LogHandler.writeLog(mContext,"VolumeHandler - $mInstanceContext", "because applyVolume was called","Nothing, because no volume was selected!")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AlarmBroadcastReciever : BroadcastReceiver() {

if (intent?.getStringExtra(Constants.BROADCAST_INTENT_ACTION).equals(Constants.BROADCAST_INTENT_ACTION_UPDATE_VOLUME)) {
Log.d(TAG(), "Alarmintent: Content is to \"check the time\"")
VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))
VolumeHandler(context, "AlarmBroadcastReciever").setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))
Trigger(context).createAlarmIntime()

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BluetoothBroadcastReciever : BroadcastReceiver(){

HeadsetHandler.getPairedDevicesWithDatabaseState(context).forEach {
if(address == it.address) {
val volumeHandler = VolumeHandler(context)
val volumeHandler = VolumeHandler(context, "BluetoothBroadcastReciever")
volumeHandler.ignoreMusicPlaying(true)

val state = VolumeState(it.volumeState)
Expand Down Expand Up @@ -72,7 +72,7 @@ class BluetoothBroadcastReciever : BroadcastReceiver(){
}

if(Trigger(context).checkIfNextAlarmExists()){
var volumeHandler = VolumeHandler(context)
var volumeHandler = VolumeHandler(context, "BluetoothBroadcastReciever")
// is this what we want? Override existing playing content?
// yes, but only if the device we are loosing are headphones.
// Todo: Check if headphones disconnected!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BootReciever : BroadcastReceiver(){
override fun onReceive(context: Context, intent: Intent) {
if(intent.action==Intent.ACTION_BOOT_COMPLETED){
Log.e(TAG(), "BootReciever: Started Device!")
VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))
VolumeHandler(context, "BootReciever").setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))

val prefs = PreferencesManager(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NoisyBroadcastReciever : BroadcastReceiver(){
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == AudioManager.ACTION_AUDIO_BECOMING_NOISY) {
Log.e(TAG(), "NoisyBroadcastReciever: Becoming Noisy! Checking Volume Again!")
VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))
VolumeHandler(context, "NoisyBroadcastReciever").setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))
}
}

Expand Down

0 comments on commit 48bb0b5

Please sign in to comment.