mirror of
https://github.com/basti564/Oculess.git
synced 2024-11-24 11:12:36 +01:00
Fix audioservice crashing when packagemanager fails
This commit is contained in:
parent
f9409f2b85
commit
8dbed6b927
@ -7,11 +7,11 @@
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Resizable_Experimental_API_33.avd" />
|
||||
<value value="C:\Users\ethan\.android\avd\Pixel_XL_API_30.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-07-29T12:10:10.340825Z" />
|
||||
<timeTargetWasSelectedWithDropDown value="2023-09-03T18:44:40.532833300Z" />
|
||||
</component>
|
||||
</project>
|
@ -11,8 +11,8 @@ android {
|
||||
applicationId "com.bos.oculess"
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 33
|
||||
versionCode 13
|
||||
versionName "1.5.0"
|
||||
versionCode 14
|
||||
versionName "1.5.1"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
@ -11,6 +11,8 @@ import android.provider.Settings.SettingNotFoundException
|
||||
import android.util.Log
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import com.bos.oculess.util.AppOpsUtil
|
||||
import java.lang.Exception
|
||||
|
||||
class AudioService : AccessibilityService() {
|
||||
companion object {
|
||||
private const val TAG = "OculessAudioService"
|
||||
@ -43,11 +45,9 @@ class AudioService : AccessibilityService() {
|
||||
}
|
||||
override fun onAccessibilityEvent(e: AccessibilityEvent?) {
|
||||
if (e?.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
||||
Log.i(TAG, "Trigger: TYPE_WINDOW_STATE_CHANGED")
|
||||
checkUpdateAppList()
|
||||
audioFix()
|
||||
} else if (e?.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
|
||||
Log.i(TAG, "Trigger: TYPE_WINDOW_CONTENT_CHANGED")
|
||||
audioFix()
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,11 @@ class AudioService : AccessibilityService() {
|
||||
|
||||
private fun checkUpdateAppList() {
|
||||
if (canUpdateAppList) {
|
||||
try {
|
||||
updateAudioPackages()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
val handler: Handler = Handler()
|
||||
canUpdateAppList = false
|
||||
handler.postDelayed({
|
||||
@ -75,6 +79,7 @@ class AudioService : AccessibilityService() {
|
||||
enableAudioPermission()
|
||||
}
|
||||
handler.postDelayed(r, 250)
|
||||
handler.postDelayed(r, 750)
|
||||
}
|
||||
private fun updateAudioPackages() {
|
||||
Log.i(TAG, "Start package scan...")
|
||||
@ -88,13 +93,23 @@ class AudioService : AccessibilityService() {
|
||||
val packageInfoList = applicationContext.packageManager?.getInstalledPackages(0)
|
||||
val packageNames = arrayListOf<String>()
|
||||
for (packageInfo in packageInfoList!!) {
|
||||
try {
|
||||
packageNames.add(packageInfo.packageName)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Error while iterating packages")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
// Remove system apps
|
||||
val packageInfoListSystem = applicationContext.packageManager?.getInstalledPackages(
|
||||
PackageManager.MATCH_SYSTEM_ONLY)
|
||||
for (packageInfoSystem in packageInfoListSystem!!) {
|
||||
try {
|
||||
packageNames.remove(packageInfoSystem.packageName)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Error while iterating packages")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
// Commit to app list
|
||||
audioApps = packageNames.toTypedArray()
|
||||
@ -108,14 +123,16 @@ class AudioService : AccessibilityService() {
|
||||
Log.i(TAG, "AudioApps is null!")
|
||||
return
|
||||
}
|
||||
var first = true
|
||||
for (app in audioApps!!) {
|
||||
val info: ApplicationInfo?= applicationContext.packageManager?.getApplicationInfo(app, 0)
|
||||
// https://cs.android.com/android/platform/superproject/+/master:frameworks/proto_logging/stats/enums/app/enums.proto;l=138?q=PLAY_AUDIO
|
||||
try {
|
||||
val info: ApplicationInfo?= applicationContext.packageManager?.getApplicationInfo(app, 0)
|
||||
AppOpsUtil.allowOp(applicationContext, 27, info?.uid!!, app) // Record audio (Future-proofing)
|
||||
AppOpsUtil.allowOp(applicationContext, 28, info?.uid!!, app) // Play audio
|
||||
} catch (e: SecurityException) {
|
||||
Log.w(TAG, "Audio service lacks permission to set appops. Is Oculess device owner?")
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "An exception occurred while setting permissions")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,3 +22,15 @@ kotlin.code.style=official
|
||||
android.defaults.buildfeatures.buildconfig=true
|
||||
android.nonTransitiveRClass=false
|
||||
android.nonFinalResIds=false
|
||||
|
||||
# TetherFi
|
||||
systemProp.http.proxyHost=192.168.49.1
|
||||
systemProp.http.proxyPort=8282
|
||||
systemProp.http.proxyUser=userid
|
||||
systemProp.http.proxyPassword=password
|
||||
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
|
||||
systemProp.https.proxyHost=192.168.49.1
|
||||
systemProp.https.proxyPort=8282
|
||||
systemProp.https.proxyUser=userid
|
||||
systemProp.https.proxyPassword=password
|
||||
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost
|
Loading…
Reference in New Issue
Block a user