abrenoch / hyperion-android-grabber

Screen grabber for hyperion
MIT License
196 stars 34 forks source link

Intent to start grabber #189

Closed durag5 closed 1 year ago

durag5 commented 2 years ago

Is there an intent I can call to start grabbing? I want to make a work around in home assistant by detecting the TV turns on then pushing it the grabber intent.

I saw an old response that used toggle activity which doesn't seem to work with Nvidia shield pro.

boralyl commented 2 years ago

I use this service call to start the grabber in home assistant with the androidtv integration on my Nvidia shield pro:

service: androidtv.adb_command
data:
  command: "am start com.abrenoch.hyperiongrabber/com.abrenoch.hyperiongrabber.common.BootActivity"

I call it when media starts playing for apps without DRM like kodi, youtube, etc.

durag5 commented 2 years ago

Thank you for the reply! I will try this soon.

On Wed, Sep 7, 2022, 9:10 PM Aaron Godfrey @.***> wrote:

I use this service call to start the grabber in home assistant with the androidtv integration https://www.home-assistant.io/integrations/androidtv/ on my Nvidia shield pro:

service: androidtv.adb_commanddata: command: "am start com.abrenoch.hyperiongrabber/com.abrenoch.hyperiongrabber.common.BootActivity"

I call it when media starts playing for apps without DRM like kodi, youtube, etc.

— Reply to this email directly, view it on GitHub https://github.com/abrenoch/hyperion-android-grabber/issues/189#issuecomment-1240193865, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKBETN5KF6I2NYPRBWEKDDV5FRMLANCNFSM556LAIEA . You are receiving this because you authored the thread.Message ID: @.***>

durag5 commented 2 years ago

I wanted to follow up and this worked perfectly. I have it set to run (home assistant) when my tv turns on to get around the shield tv bug that stops the process while sleeping sometimes.

On Wed, Sep 7, 2022, 9:10 PM Aaron Godfrey @.***> wrote:

I use this service call to start the grabber in home assistant with the androidtv integration https://www.home-assistant.io/integrations/androidtv/ on my Nvidia shield pro:

service: androidtv.adb_commanddata: command: "am start com.abrenoch.hyperiongrabber/com.abrenoch.hyperiongrabber.common.BootActivity"

I call it when media starts playing for apps without DRM like kodi, youtube, etc.

— Reply to this email directly, view it on GitHub https://github.com/abrenoch/hyperion-android-grabber/issues/189#issuecomment-1240193865, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKBETN5KF6I2NYPRBWEKDDV5FRMLANCNFSM556LAIEA . You are receiving this because you authored the thread.Message ID: @.***>

LordBoos commented 1 year ago

Unfortunately this doesn't work for me. Looks like new Android version requires the app activity to be exported, but this one isn't.

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.abrenoch.hyperiongrabber/.common.BootActivity }

Exception occurred while executing 'start':
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.abrenoch.hyperiongrabber/.common.BootActivity } from null (pid=19499, uid=2000) not exported from uid 10091
        at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1043)
        at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:1052)
        at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:712)
        at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1151)
        at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1123)
        at com.android.server.am.ActivityManagerService.startActivityAsUserWithFeature(ActivityManagerService.java:3694)
        at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:543)
        at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:185)
        at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
        at android.os.ShellCommand.exec(ShellCommand.java:44)
        at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:10611)
        at android.os.Binder.shellCommand(Binder.java:929)
        at android.os.Binder.onTransact(Binder.java:813)
        at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:5073)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2899)
        at android.os.Binder.execTransactInternal(Binder.java:1159)
        at android.os.Binder.execTransact(Binder.java:1123)

EDIT: It works in 1.1 Beta 1.

LordBoos commented 1 year ago

I have managed to came up with what I think is a clever way to ensure that the service is running. It was annoying for me that the BootActivity remained open on my screen after launching it so I came up with a way that checks if the service is running or not and needs to be launched and if launch is executed, it will return back to home screen.

If you want to use this automation, just replace id, device_id and entity_id in whole automation.

My Home Assistant automation does the following:

  1. Checks if SHILED (or you Android TV of choice) became "idle" (that happens basically everytime the device is not playing something eg. HOME screen is opened).
  2. Turns ON Hyperion light
  3. Sends ADB command to the device to list Hyperion Services
  4. Waits for a response for up to 5s
  5. If response contains HyperionScreenService it continues to next step, if not, automation is cancelled
  6. Sends ADB command to launch Hyperion Grabber BootActivity which starts the grabbing automatically
  7. Sends command to return to Home screen
- id: '1614616689639'
  alias: Hyperion SHIELD on
  description: ''
  trigger:
  - platform: device
    device_id: fcb82293a93b4ceea92046d14dc33a60
    domain: media_player
    entity_id: media_player.android_tv_2
    type: idle
  condition: []
  action:
  - type: turn_on
    device_id: 940a1adf8c486685fab1d992910b1812
    entity_id: light.hyperion
    domain: light
    brightness_pct: 100
  - service: androidtv.adb_command
    data:
      command: dumpsys activity services hyperion
    target:
      entity_id: media_player.android_tv_2
  - wait_template: "{% if 'HyperionScreenService' in state_attr('media_player.android_tv_2',
      'adb_response') %}\n    false\n{% else %}\n    true\n{% endif %}"
    continue_on_timeout: false
    timeout: 00:00:05
  - service: androidtv.adb_command
    data:
      command: am start com.abrenoch.hyperiongrabber/com.abrenoch.hyperiongrabber.common.BootActivity
    target:
      entity_id:
      - media_player.android_tv_2
  - service: androidtv.adb_command
    data:
      command: am start -a android.intent.action.MAIN -c android.intent.category.HOME
    target:
      entity_id: media_player.android_tv_2
  mode: single
durag5 commented 1 year ago

Very nice! On my shield just brute forcing the adb every time my tv is turned on worked for me. I don't have boot activity showing on my screen by the time everything is on. My tv is a Samsung which takes a second to boot which may be the difference.

On Mon, Oct 31, 2022, 6:17 AM Jakub Kolář @.***> wrote:

I have managed to came up with I think is a clever way to ensure that the service is running. It was annoying for me that the BootActivity remained open on my screen after launching it so I came up with a way that checks if the service is running or not and needs to be launched and if launch is executed, it will return back to home screen.

If you want to use this automation, just replace id, device_id and entity_id in whole automation.

My Home Assistant automation does the following:

  1. Checks if SHILED (or you Android TV of choice) became "idle" (that happens basically everytime the device is not playing something eg. HOME screen is opened).
  2. Turns ON Hyperion light
  3. Sends ADB command to the device to list Hyperion Services
  4. Waits for a response for up to 5s
  5. If response contains HyperionScreenService it continues to next step, if not, automation is cancelled
  6. Sends ADB command to launch Hyperion Grabber BootActivity which starts the grabbing automatically
  7. Sends command to return to Home screen
  • id: '1614616689639' alias: Hyperion SHIELD on description: '' trigger:
    • platform: device device_id: fcb82293a93b4ceea92046d14dc33a60 domain: media_player entity_id: media_player.android_tv_2 type: idle condition: [] action:
    • type: turn_on device_id: 940a1adf8c486685fab1d992910b1812 entity_id: light.hyperion domain: light brightness_pct: 100
    • service: androidtv.adb_command data: command: dumpsys activity services hyperion target: entity_id: media_player.android_tv_2
    • wait_template: "{% if 'HyperionScreenService' in state_attr('media_player.android_tv_2', 'adb_response') %}\n false\n{% else %}\n true\n{% endif %}" continue_on_timeout: false timeout: 00:00:05
    • service: androidtv.adb_command data: command: am start com.abrenoch.hyperiongrabber/com.abrenoch.hyperiongrabber.common.BootActivity target: entity_id:
      • media_player.android_tv_2
    • service: androidtv.adb_command data: command: am start -a android.intent.action.MAIN -c android.intent.category.HOME target: entity_id: media_player.android_tv_2 mode: single

— Reply to this email directly, view it on GitHub https://github.com/abrenoch/hyperion-android-grabber/issues/189#issuecomment-1297075174, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKBETK7PQCTQMV5DRPZJGTWF7BGRANCNFSM556LAIEA . You are receiving this because you authored the thread.Message ID: @.***>