dwaan / homebridge-adb

Homebridge script to control remote ADB enabled Android device
MIT License
74 stars 14 forks source link

Using alternative command to open apps #45

Closed noenic closed 2 years ago

noenic commented 3 years ago

I am using a Freebox pop wich is an simple AndroidTV. the problem that i am facing is that some apps would not open with the id of the app (like the TV app named OQEE) when using the "adb shell "monkey -p" command but it can open it with this command "adb shell am start -n net.oqee.androidtv"/.MainActivity" with this output : Starting: Intent { cmp=net.oqee.androidtv/.MainActivity } Warning: Activity not started, its current task has been brought to the front

I don't know if there is a way to make this app open with the monkey command, but if it is not possible would it be possible to add an option in the config to tell wich command to run (when the default one is not possible) for specific input? like:

{
                            "name": "OQEETV",
                            "id": "net.oqee.androidtv"
                            "command" : am start -n net.oqee.androidtv"/.MainActivity"
}, 

But still this Plugin is really well made Thank You !👍

dwaan commented 3 years ago

I added your suggestion into the new release. Please if it's working in your device.

noenic commented 3 years ago

I added your suggestion into the new release. Please if it's working in your device.

Hi , I don't know if it is me making a mistake by adding the commands in the config but it is not working : { "name": "OQEETV", "id": "net.oqee.androidtv", "adb": "am start -n \"net.oqee.androidtv/.MainActivity\"" },

I also tried adding adb shell and adb -s {ip} shell but no it still does not open the app, but after my initial post I modified the index.js file. (I want to mention that am not a java coder, I don't know anything about java. Only Python) sadly by updating it crushed the old file, but I successfully added a horrible if statement wich just checked type.includes("OQEE") in the else statement and just copy the same structure as said adb =adb shell am start -n \"net.oqee.androidtv/.MainActivity\";

And after some missing {} and ;, it finally worked kind of so i know it is actually possible but yeah with the new release it's not working but perhaps it's just a typing error in the config.

Still thanks for adding the suggestion 👍

EDIT: I also found out that with some apps the current app thing just pull back to Home I did also make a work around it wich actually worked but i don't know how as i couldn't understand fully the code and certainly just messed up the condition:

line 739 was : if(stdout[1].includes("Launcher") || stdout[1].substr(0, 13) == ".MainActivity" || stdout[1].includes("RecentsTvActivity")) stdout = this.inputs[0].id;

by memorie I think i did: if(stdout[1].includes("Launcher") || stdout[1].substr(0, 13) == ".MainActivity" || stdout[1].includes("RecentsTvActivity")) stdout = this.inputs[this.currentInputIndex].id;

dwaan commented 3 years ago

Have you tried using something like this? { "name": "OQEETV", "id": "net.oqee.androidtv", "adb": "am start -n 'net.oqee.androidtv/.MainActivity'" }

For the last bit, I will check again. The "if" condition is supposed to detect if the current app is the Home Screen in the android device.

noenic commented 3 years ago

Have you tried using something like this? { "name": "OQEETV", "id": "net.oqee.androidtv", "adb": "am start -n 'net.oqee.androidtv/.MainActivity'" }

Yeah still nothing sadly

For the last bit, I will check again. The "if" condition is supposed to detect if the current app is the Home Screen in the android device.

Oh.. That make sense, I will check stdout with these apps because using the command adb -s ${this.ip} shell "dumpsys window windows | grep -E mFocusedApp" with the command prompt actually output correct data.

tried it with Airscreen

mFocusedApp=AppWindowToken{d4bedd0 token=Token{a0a6993 ActivityRecord{6b83e82 u0 com.ionitech.airscreen/.MainActivity t685}}}

I tried to remove stdout[1].substr(0, 13) == ".MainActivity" maybe it is catching .MainActivity

Writing this in repl.it gave me a good reason de believe it may be that :

stdout ='mFocusedApp=AppWindowToken{d4bedd0 token=Token{a0a6993 ActivityRecord{6b83e82 u0 com.ionitech.airscreen/.MainActivity t685}}}'; stdout = stdout.trim(); stdout = stdout.split("/"); stdout[0] = stdout[0].split(" "); stdout[0] = stdout[0][4]; stdout[1]

output : .MainActivity t685}}}

EtherealMochi commented 2 years ago

I am having the same issue. I checked your code where you added the adb command but I still had to change the index.js to get it to run.

homebridge config:

"inputs": [
    {
        "name": "Pluto TV",
        "id": "tv.pluto.android",
        "adb": "am start -p tv.pluto.android"
    }
]

index.js: (i just copied from elseif command. not sure why its still matching the first if statement since adb command is there.)

if(!type.includes(" ") && type.includes("."))
    adb = `adb -s ${this.ip} shell "${this.inputs[this.currentInputIndex].adb}"`;
else if (this.inputs[this.currentInputIndex].adb)
    adb = `adb -s ${this.ip} shell "${this.inputs[this.currentInputIndex].adb}"`;
else
    adb = `adb -s ${this.ip} shell "${this.inputs[this.currentInputIndex].id}"`;
dwaan commented 2 years ago

Closing this issues, as it's already implemented in new version, currently in beta.