Skip to content

Commit

Permalink
add force reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Jun 2, 2024
1 parent a5b0157 commit 44ef6f7
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PreferencesHolder(@Transient val mDefaultVolumeValue: Int = 80) {

@EncodeDefault var headsetConnectionCheck = true
@Transient var shouldRestartOnBoot = false
@EncodeDefault var forceRestartOnBoot = false
@EncodeDefault var showNotifications = true
@EncodeDefault var runWhenIdle = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PreferencesManager(private var mContext: Context) {
checkIfHeadsetIsConnected()
shouldShowNotification()
shouldRestartOnBoot()
forceRestartOnBoot()
runWhenIdle()
changeRingerVolume()

Expand Down Expand Up @@ -51,6 +52,16 @@ class PreferencesManager(private var mContext: Context) {
mPreferencesEditor.apply()
}

fun forceRestartOnBoot(): Boolean {
mPreferencesHolder.forceRestartOnBoot = mPreferences.getBoolean(getKey(R.string.pref_general_boot_force_restart), mPreferencesHolder.forceRestartOnBoot)
return mPreferencesHolder.shouldRestartOnBoot
}

fun setForceRestartOnBoot(restart: Boolean) {
mPreferencesEditor.putBoolean(getKey(R.string.pref_general_boot_force_restart), restart)
mPreferencesEditor.apply()
}

fun shouldShowNotification(): Boolean {
mPreferencesHolder.showNotifications = mPreferences.getBoolean(getKey(R.string.pref_general_show_notifications_when_paused), mPreferencesHolder.showNotifications)
return mPreferencesHolder.showNotifications
Expand Down Expand Up @@ -144,6 +155,7 @@ class PreferencesManager(private var mContext: Context) {
mPreferencesEditor.putBoolean(getKey(R.string.pref_calendar_ignore_free), preferences.ignoreFree)

mPreferencesEditor.putBoolean(getKey(R.string.pref_general_change_ringer), preferences.changeRingerVolume)
mPreferencesEditor.putBoolean(getKey(R.string.pref_general_boot_force_restart), preferences.forceRestartOnBoot)
mPreferencesEditor.apply()
}

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

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

var state = VolumeState(it.volumeState)
val state = VolumeState(it.volumeState)
state.setReason(REASON_BLUETOOTH_CONNECTED, it.alias)
var supposedState = StateGenerator(context).stateAt(System.currentTimeMillis())
val supposedState = StateGenerator(context).stateAt(System.currentTimeMillis())

if (supposedState.state > state.state) {
volumeHandler.setVolumeStateAndApply(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class BootReciever : BroadcastReceiver(){
Log.e(TAG(), "BootReciever: Started Device!")
VolumeHandler(context).setVolumeStateAndApply(StateGenerator(context).stateAt(System.currentTimeMillis()))

if(PreferencesManager(context).shouldRestartOnBoot()){
val prefs = PreferencesManager(context)

if(prefs.shouldRestartOnBoot() || prefs.forceRestartOnBoot()){
Log.e(TAG(), "BootReciever: Started Checks!")
Trigger(context).createAlarmIntime()
return
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/stringpreferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="pref_general_change_ringer" translatable="false">PREF_INFLUENCE_RINGER_VOLUME</string>

<string name="pref_general_boot_restart" translatable="false">PREF_BOOT_RESTART</string>
<string name="pref_general_boot_force_restart" translatable="false">PREF_BOOT_FORCE_RESTART</string>



Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,5 @@
<string name="dnd_missing_permissions_title">Missing Permissions!</string>
<string name="dnd_missing_permission_action_title">Fix!</string>
<string name="bluetooth_missing_permissions">Bluetooth Access not granted.</string>
<string name="force_restart_checks_after_reboot">When the device restarted, also restart checks, regardless of their pre-reboot-state.</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/general_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
android:defaultValue="true"
android:title="@string/enablePauseNotification"
android:key="@string/pref_general_show_notifications_when_paused"/>

<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="@string/force_restart_checks_after_reboot"
android:key="@string/pref_general_boot_force_restart" />
</PreferenceCategory>

</PreferenceScreen>

0 comments on commit 44ef6f7

Please sign in to comment.