renyuneyun / Easer

User-defined explicit automation for Android
https://renyuneyun.github.io/Easer/
GNU General Public License v3.0
818 stars 93 forks source link

Broadcast not accepted by Android system #470

Open Zimbelstern opened 1 year ago

Zimbelstern commented 1 year ago

Easer version 0.8.3-beta3

To Reproduce Settings of Send Broadcast to reproduce the behavior:

Error log (warning) from BroadcastQueue:

Background execution not allowed: receiving Intent { act=info.varden.hauk.START_ALONE_THEN_MAKE_TOAST flg=0x10 } to info.varden.hauk/.global.Receiver

Sending broadcast through command isn't possible either:

am broadcast -a info.varden.hauk.START_ALONE_THEN_MAKE_TOAST -n info.varden.hauk/.global.Receiver -e source test -e requestLink test

results in the warning

Permission Denial: broadcast asks to run as user -2 but is calling from uid u0a189; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS

from ActivityManager.

Extra phone info: Bug reproduced on

Additional context The broadcast is addressed to Hauk.

sudomain commented 1 year ago

I think I'm experiencing the same issue but with sending a broadcast to a different app (KeyMapper). I'm trying to send an intent to KeyMapper with the following settings: Screenshot_20230515-125337

I know it works from the KeyMapper side because I can trigger it with Termux's version on am: am broadcast -a io.github.sds100.keymapper.ACTION_TRIGGER_KEYMAP_BY_UID --es io.github.sds100.keymapper.EXTRA_KEYMAP_UID 5344b82e-e269-473b-a19f-9c01cf4ed634

It seems the broadcast profile is broken

bfabiszewski commented 1 year ago

The problem is that applyDynamics method ignores target package and target class. Without the data the broadcast is implicit which is not allowed on Android 8+. Also extras are lost here. A quick fix is as follows. I did not go any deeper though, so it may break some other stuff as the class is used in other Intent actions. I also add ACCESS_BACKGROUND_LOCATION permission. I think it is needed to start background location in controlled app.

diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0b8d99ca..cf238990 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -8,6 +8,7 @@

     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
diff --git a/app/src/main/java/ryey/easer/skills/operation/intent/IntentOperationData.java b/app/src/main/java/ryey/easer/skills/operation/intent/IntentOperationData.java
index e39fbfac..c568bbd0 100644
--- a/app/src/main/java/ryey/easer/skills/operation/intent/IntentOperationData.java
+++ b/app/src/main/java/ryey/easer/skills/operation/intent/IntentOperationData.java
@@ -225,7 +225,13 @@ public class IntentOperationData implements OperationData, Reused {
                 String type = extra.type;
                 extras.add(new ExtraItem(key, value, type));
             }
-            data.extras = Extras.mayConstruct(extras);
+            intentData.extras = Extras.mayConstruct(extras);
+        }
+        if (data.target_package != null) {
+            intentData.target_package = data.target_package;
+        }
+        if (data.target_class != null) {
+            intentData.target_class = data.target_class;
         }
         IntentOperationData ret = new IntentOperationData(intentData);
         ret.setSkillID(skillID());