-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: media session as scope provider
- Loading branch information
Showing
9 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package android.app; | ||
|
||
public class ActivityThread { | ||
public static ActivityThread currentActivityThread() { | ||
throw new RuntimeException("STUB"); | ||
} | ||
|
||
public ContextImpl getSystemContext() { | ||
throw new RuntimeException("STUB"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package android.app; | ||
|
||
import android.content.Context; | ||
|
||
public abstract class ContextImpl extends Context { | ||
|
||
} |
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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/xyz/mufanc/applock/core/scope/provider/MediaSessionProvider.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package xyz.mufanc.applock.core.scope.provider | ||
|
||
import android.media.session.MediaSessionManager | ||
import android.media.session.MediaSessionManager.OnActiveSessionsChangedListener | ||
import android.app.ActivityThread | ||
import io.github.libxposed.api.XposedInterface | ||
import xyz.mufanc.applock.core.util.Log | ||
|
||
@Suppress("Unused") | ||
data object MediaSessionProvider : ScopeProvider() { | ||
|
||
private const val TAG = "MediaSessionProvider" | ||
|
||
private val manager: MediaSessionManager by lazy { | ||
ActivityThread.currentActivityThread() | ||
.systemContext | ||
.getSystemService(MediaSessionManager::class.java) | ||
} | ||
|
||
private val listener = OnActiveSessionsChangedListener { controllers -> | ||
if (controllers != null) { | ||
emit(controllers.map { it.packageName }.toSet()) | ||
} | ||
} | ||
|
||
override fun isAvailable(): Boolean = true | ||
|
||
override fun init(ixp: XposedInterface) { | ||
manager.addOnActiveSessionsChangedListener(listener, null) | ||
Log.d(TAG, "initialized") | ||
} | ||
} |
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
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