add pigreceiver
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
android:configChanges="screenSize|screenLayout|orientation|smallestScreenSize"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsPictureInPicture="true">
|
||||
|
||||
<intent-filter>
|
||||
@@ -98,6 +99,7 @@
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity-alias>
|
||||
|
||||
<receiver
|
||||
android:name=".SecretCodeReceiver"
|
||||
android:exported="true">
|
||||
@@ -108,5 +110,14 @@
|
||||
android:scheme="android_secret_code" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".PigReceiver"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.SET_DEBUG_APP">
|
||||
<intent-filter>
|
||||
<action android:name="ru.shadowsparky.videobox.ACTION_SWITCH_PIGGY_ICON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class MainActivity : ComponentActivity() {
|
||||
.setData(null)
|
||||
.setAction(null)
|
||||
}
|
||||
val isPiggyActivity = componentName?.className == SecretCodeReceiver.PIGGY_CLS
|
||||
val isPiggyActivity = componentName?.className == PigReceiver.PIGGY_CLS
|
||||
setContent {
|
||||
if (isPiggyActivity) {
|
||||
CompositionLocalProvider(LocalColorSchemeProvider provides getPiggyColorScheme()) {
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package ru.shadowsparky.videobox.multiplatform
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.util.Log
|
||||
|
||||
// adb shell am broadcast -a ru.shadowsparky.videobox.ACTION_SWITCH_PIGGY_ICON -p ru.shadowsparky.videobox.multiplatform.debug
|
||||
// adb shell am broadcast -a ru.shadowsparky.videobox.ACTION_SWITCH_PIGGY_ICON -p ru.shadowsparky.videobox.multiplatform
|
||||
open class PigReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d("PigReceiver", "intent ${intent?.action} received. context $context")
|
||||
if (context == null) return
|
||||
when (intent?.action) {
|
||||
"android.provider.Telephony.SECRET_CODE",
|
||||
"ru.shadowsparky.videobox.ACTION_SWITCH_PIGGY_ICON" -> {
|
||||
val pm = context.packageManager
|
||||
val mainActivity = ComponentName(context, MainActivity::class.java)
|
||||
val piggyActivityAlias = ComponentName(context, PIGGY_CLS)
|
||||
val isMainEnabled = pm.getComponentEnabledSetting(mainActivity) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
pm.setState(piggyActivityAlias, isMainEnabled)
|
||||
pm.setState(mainActivity, !isMainEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun PackageManager.setState(cn: ComponentName, isEnabled: Boolean) {
|
||||
setComponentEnabledSetting(
|
||||
cn,
|
||||
if (isEnabled) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PIGGY_CLS = "ru.shadowsparky.videobox.multiplatform.PiggyActivity"
|
||||
}
|
||||
}
|
||||
|
||||
class SecretCodeReceiver : PigReceiver()
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package ru.shadowsparky.videobox.multiplatform
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
|
||||
// adb shell am broadcast -a android.provider.Telephony.SECRET_CODE -d android_secret_code://676767
|
||||
class SecretCodeReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context == null || intent?.action != "android.provider.Telephony.SECRET_CODE") return
|
||||
val pm = context.packageManager
|
||||
val mainActivity = ComponentName(context, MainActivity::class.java)
|
||||
val piggyActivityAlias = ComponentName(context, PIGGY_CLS)
|
||||
val isMainEnabled = pm.getComponentEnabledSetting(mainActivity) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
pm.setState(piggyActivityAlias, isMainEnabled)
|
||||
pm.setState(mainActivity, !isMainEnabled)
|
||||
}
|
||||
|
||||
private fun PackageManager.setState(cn: ComponentName, isEnabled: Boolean) {
|
||||
setComponentEnabledSetting(
|
||||
cn,
|
||||
if (isEnabled) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PIGGY_CLS = "ru.shadowsparky.videobox.multiplatform.PiggyActivity"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user