Skip to content

Commit

Permalink
Build 1.4.1 : SoundMaster shows Ui on system volume change as well
Browse files Browse the repository at this point in the history
  • Loading branch information
legendsayantan committed Jun 10, 2024
1 parent 5e9db8c commit 586180f
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 75 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdk 27
targetSdk 34
versionCode 1
versionName "1.4.0"
versionName "1.4.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.4.0",
"versionName": "1.4.1",
"outputFile": "app-release.apk"
}
],
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
Expand All @@ -29,6 +29,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.AdbTools"
tools:targetApi="31">

<service
android:name=".services.SoundMasterService"
android:enabled="true"
Expand All @@ -49,8 +50,9 @@

<activity
android:name=".SoundMasterActivity"
android:exported="false"
android:exported="true"
android:label=""
android:excludeFromRecents="true"
android:theme="@style/DialogActivityTheme" />
<activity
android:name=".MixedAudioActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DebloatActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_debloat)
initialiseStatusBar()
list = findViewById<ListView>(R.id.apps_list)
list = findViewById(R.id.apps_list)
ShizukuRunner.runAdbCommand("pm grant $packageName android.permission.QUERY_ALL_PACKAGES",
object : ShizukuRunner.CommandResultListener {
override fun onCommandResult(output: String, done: Boolean) {}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/legendsayantan/adbtools/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.legendsayantan.adbtools.lib.ShizukuRunner
import com.legendsayantan.adbtools.lib.Utils.Companion.initialiseStatusBar
import com.legendsayantan.adbtools.services.SoundMasterService
import java.util.UUID
/**
* @author legendsayantan
Expand Down Expand Up @@ -92,6 +93,7 @@ class MainActivity : AppCompatActivity() {
//create notification
val intent = Intent(this, SoundMasterActivity::class.java)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
SoundMasterService.uiIntent = intent
val channelId = "notifications"
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.outline_info_24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.content.Context
import android.content.Intent
import android.media.projection.MediaProjectionManager
import android.os.Bundle
import android.view.Gravity
import android.os.Handler
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
Expand Down Expand Up @@ -56,16 +56,20 @@ class SoundMasterActivity : AppCompatActivity() {
@SuppressLint("ApplySharedPref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
showing = true
setContentView(R.layout.activity_sound_master)
initialiseStatusBar()
interacted()
//new slider
findViewById<MaterialCardView>(R.id.newSlider).setOnClickListener {
lastInteractionAt = -1
NewSliderDialog(this@SoundMasterActivity) { pkg ->
val newPackages = packages
newPackages.add(pkg)
packages = newPackages
if (SoundMasterService.running) SoundMasterService.onDynamicAttach(pkg)
updateSliders()
interacted()
}.show()
}

Expand All @@ -79,6 +83,18 @@ class SoundMasterActivity : AppCompatActivity() {
findViewById<ConstraintLayout>(R.id.main).setOnClickListener {
finish()
}

setupAutoHide()
}

private fun setupAutoHide(){
Timer().schedule(timerTask {
if (lastInteractionAt>=0
&& lastInteractionAt+hideTimerInterval < System.currentTimeMillis()) {
finish()
cancel()
}
}, hideTimerInterval,hideTimerInterval)
}

override fun onResume() {
Expand All @@ -100,8 +116,7 @@ class SoundMasterActivity : AppCompatActivity() {
applicationContext,
"No apps selected to control",
Toast.LENGTH_SHORT
)
.show()
).show()
} else {
ShizukuRunner.runAdbCommand("pm grant ${baseContext.packageName} android.permission.RECORD_AUDIO",
object : ShizukuRunner.CommandResultListener {
Expand All @@ -125,6 +140,12 @@ class SoundMasterActivity : AppCompatActivity() {
})
}
}

override fun onCommandError(error: String) {
Handler(mainLooper).post {
Toast.makeText(applicationContext,"Shizuku Error", Toast.LENGTH_SHORT).show()
}
}
})
}
}
Expand All @@ -136,6 +157,7 @@ class SoundMasterActivity : AppCompatActivity() {
cancel()
} else count++
if (count > 50) cancel()
interacted()
}, 500, 500)
}
}
Expand All @@ -153,16 +175,24 @@ class SoundMasterActivity : AppCompatActivity() {
startService(Intent(this, SoundMasterService::class.java).apply {
putExtra("packages", packages.toTypedArray())
})
interacted()
} else {
Toast.makeText(
this, "Request to obtain MediaProjection denied.",
Toast.LENGTH_SHORT
).show()
interacted()
}
}
}

override fun finish() {
showing = false
super.finish()
}

private fun updateSliders() {
interacted()
findViewById<TextView>(R.id.none).visibility =
if (packages.size > 0) View.GONE else View.VISIBLE
Thread {
Expand All @@ -173,17 +203,21 @@ class SoundMasterActivity : AppCompatActivity() {
}
val adapter =
VolumeBarAdapter(this@SoundMasterActivity, sliderMap, { app, vol ->
interacted()
SoundMasterService.setVolumeOf(app, vol)
}, {
interacted()
val newPackages = packages
newPackages.remove(it)
packages = newPackages
updateSliders()
SoundMasterService.onDynamicDetach(it)
}, { app, sliderIndex ->
interacted()
if (sliderIndex == 0) SoundMasterService.getBalanceOf(app)
else SoundMasterService.getBandValueOf(app, sliderIndex - 1)
}, { app, slider, value ->
interacted()
if (slider == 0) SoundMasterService.setBalanceOf(app, value)
else SoundMasterService.setBandValueOf(app, slider - 1, value)
})
Expand All @@ -195,6 +229,12 @@ class SoundMasterActivity : AppCompatActivity() {
}

companion object {
var showing = false
private const val hideTimerInterval = 2000L
var lastInteractionAt = 0L
var interacted = {
lastInteractionAt = System.currentTimeMillis()
}
private const val FILENAME_SOUNDMASTER = "soundmaster.txt"
private const val MEDIA_PROJECTION_REQUEST_CODE = 13
}
Expand Down
32 changes: 19 additions & 13 deletions app/src/main/java/com/legendsayantan/adbtools/lib/ShizukuRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,33 @@ import java.io.InputStreamReader
class ShizukuRunner {
interface CommandResultListener {
fun onCommandResult(output: String, done:Boolean)
fun onCommandError(error: String){}
}

companion object {
fun runAdbCommand(command: String, listener: CommandResultListener) {
Thread {
val process = Shizuku.newProcess(arrayOf("sh", "-c", command), null, "/")
val reader = BufferedReader(InputStreamReader(process.inputStream))
val output = StringBuilder()
try{
val process = Shizuku.newProcess(arrayOf("sh", "-c", command), null, "/")
val reader = BufferedReader(InputStreamReader(process.inputStream))
val output = StringBuilder()

var line: String?
var linecount = 0
while (reader.readLine().also { line = it } != null) {
linecount++
output.append(line).append("\n")
if (linecount == 50) {
linecount = 0
listener.onCommandResult(output.toString(),false)
var line: String?
var linecount = 0
while (reader.readLine().also { line = it } != null) {
linecount++
output.append(line).append("\n")
if (linecount == 50) {
linecount = 0
listener.onCommandResult(output.toString(),false)
}
}
listener.onCommandResult(output.toString(),true)
process.waitFor()
}catch (e:Exception){
listener.onCommandError(e.message?:"No Shizuku")
}
listener.onCommandResult(output.toString(),true)
process.waitFor()

}.start()
}
}
Expand Down
Loading

0 comments on commit 586180f

Please sign in to comment.