-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
30 additions
and
50 deletions.
There are no files selected for viewing
42 changes: 13 additions & 29 deletions
42
app/src/main/java/me/zaine/hapticstoggle/HapticsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,29 @@ | ||
package me.zaine.hapticstoggle | ||
|
||
import android.content.Context; | ||
import android.os.VibrationAttributes; | ||
import android.os.Vibrator; | ||
import android.provider.Settings | ||
import android.util.Log | ||
import com.topjohnwu.superuser.Shell | ||
|
||
class HapticsController { | ||
class HapticsController { | ||
companion object { | ||
|
||
//Gets current haptics state : Active or Inactive | ||
fun getHapticsState(): Boolean{ | ||
var state:Boolean = true | ||
var state = Shell.cmd("cat /sys/class/leds/vibrator/level").exec().out[0].toInt(); | ||
|
||
println("Haptics current state is $state"); | ||
return state | ||
return (state != 0) | ||
} | ||
|
||
//Toggles haptics state | ||
fun toggleHapticsState(): Int { | ||
|
||
|
||
val hapticFeedbackEnabled: Int = VibrationAttributes.USAGE_TOUCH | ||
Log.i("Haptics", "are "+ hapticFeedbackEnabled) | ||
|
||
|
||
|
||
//Checking root access | ||
if(RootController.checkRootAccess()){ | ||
Log.i("Haptics","haptics state is "+ hapticFeedbackEnabled) | ||
//Getting current haptics state | ||
if (Settings.System.HAPTIC_FEEDBACK_ENABLED == "18") { | ||
Log.i("Haptics", "toggled OFF!!!") | ||
return 0 | ||
}else{ | ||
Log.i("Haptics", "toggled ON!!!") | ||
return 1 | ||
} | ||
fun toggleHapticsState(): Boolean { | ||
return if (getHapticsState()){ | ||
//disabling | ||
Shell.cmd("echo 0 > /sys/class/leds/vibrator/level").exec(); | ||
false | ||
}else{ | ||
return -1 | ||
//enabling | ||
Shell.cmd("echo 3 > /sys/class/leds/vibrator/level").exec(); | ||
true | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
app/src/main/java/me/zaine/hapticstoggle/MyQSTileService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package me.zaine.hapticstoggle | ||
|
||
import com.topjohnwu.superuser.Shell; | ||
import com.topjohnwu.superuser.Shell.getShell | ||
|
||
class RootController { | ||
companion object{ | ||
|
||
fun checkRootAccess(): Boolean { | ||
var result: Shell.Result = Shell.cmd("find /dev/block -iname boot").exec(); | ||
return result.isSuccess | ||
return getShell().isRoot | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
id 'com.android.application' version '7.3.0' apply false | ||
id 'com.android.library' version '7.3.0' apply false | ||
id 'com.android.application' version '7.3.1' apply false | ||
id 'com.android.library' version '7.3.1' apply false | ||
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false | ||
} |