homebridge-adb icon indicating copy to clipboard operation
homebridge-adb copied to clipboard

Remote button can't execute shell command

Open 665465 opened this issue 2 years ago • 5 comments

Describe the bug

Shell command timeout on Remote button in IOS control center but work in Inputs. KEYCODEs work also.

Expected behavior

adb command runs correctly on TV.

Log output

[7/10/2023, 10:42:39 PM] [HomebridgeADB] oppo - 🐞 Remote Control - Can't send: am start com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity
[7/10/2023, 10:42:39 PM] [HomebridgeADB] oppo - 🐞 Remote error message:
Timeout

Device (please complete the following information):

  • Name: OPPO k9

Additional context

{
            "accessories": [
                {
                    "name": "oppo",
                    "ip": "192.168.1.103",
                    "path": "/usr/bin/adb",
                    "debug": true,
                    "category": "TELEVISION",
                    "timeout": 5000,
                    "inputs": [
                        {
                            "name": "Select Source",
                            "id": "com.heytap.tv.livetv",
                            "adb": "am start com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity" // this work
                        } 
                    ],
                    "hidenumber": true,
                    "hideother": true,
                    "upbutton": "KEYCODE_DPAD_UP",
                    "downbutton": "KEYCODE_DPAD_DOWN",
                    "leftbutton": "KEYCODE_DPAD_LEFT",
                    "rightbutton": "KEYCODE_DPAD_RIGHT",
                    "selectbutton": "KEYCODE_ENTER",
                    "backbutton": "KEYCODE_BACK",
                    "playpausebutton": "KEYCODE_MEDIA_PLAY",
                    "infobutton": "am start com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity",  // doesn't work
                    "poweron": "KEYCODE_POWER",
                    "poweroff": "KEYCODE_POWER",
                    "volumeup": "KEYCODE_VOLUME_UP",
                    "volumedown": "KEYCODE_VOLUME_DOWN"
                }
            ],
            "platform": "HomebridgeADB"
        }

665465 avatar Jul 10 '23 15:07 665465

Not sure what causing it, since both have the same underlaying code. But will look into that.

dwaan avatar Jul 12 '23 06:07 dwaan

Any other log I can get for you?

665465 avatar Aug 27 '23 04:08 665465

shell command in the "inputs" section will go into the launchApp routine

  "inputs": [
      {
          "name": "Select Source",
          "id": "com.heytap.tv.livetv",
          "adb": "am start com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity" // this work
      } 
  ],
handleInputs() {
  if (this.input.length <= 0) return;
  
  this.accessoryService.getCharacteristic(Characteristic.ActiveIdentifier)
	  .onSet(state => {
		  ...
		  this.adb.launchApp(adb).then(({ result, message }) => {
		  ...
}

but in the handleRemoteControl the sendKeycode route doesn't seem to handle the command correctly

"infobutton": "am start com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity",  // doesn't work
      /**
       * Send keycode(s) or run OS shell command
       * @param {string} keycode - one or more keycodes seperated by space, or os shell command(s) with `shell` identifier at the beginning.
       */
      this.sendKeycode = async (keycode = ``) => {
          const keycodes = keycode.split(` `);
          let finalKeycodes = ``;

          if (keycodes[0].toLowerCase() == `shell`) {
              // It's a shell command becuase it have 'shell' indenfier in the front
              for (let i = 1; i < keycodes.length; i++) finalKeycodes += `${keycodes[i]} `;
              return await this.osShell(finalKeycodes);
          } else {
              this.log(`Keycode(s): ${keycodes}`);
              // It's a keycode or combination of keycodes
              for (let i = 0; i < keycodes.length; i++) {
                  finalKeycodes += `input keyevent ${keycodes[i]}`;
                  if (i < keycodes.length - 1) finalKeycodes += ` && `;
              }
              finalKeycodes = `${finalKeycodes}`;
              await this.adbShell(finalKeycodes); // input keyevent doesn't output anything
              return { result: true, message: keycode };
          }
      }

It'll generate a shell command like this:

input keyevent am && input keyevent start && input keyevent com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity

Maybe you should mention that the Remote control section only support KEYCODE and os shell command(not adb shell command)?

image

665465 avatar Feb 17 '24 13:02 665465

If I put it in the way, it'll work:

"infobutton": "shell adb shell am start com.heytap.tv.livetv/com.heytap.tv.support.SourceListActivity"

665465 avatar Feb 17 '24 13:02 665465

Thank you for the head up. Yes, I think I miss out that part on remote. Will update test it again and update accordingly.

dwaan avatar Feb 17 '24 13:02 dwaan