Compare commits
11 Commits
pr1313
...
name_param
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
870ced088e | ||
|
|
a845ea0794 | ||
|
|
a0d98fe4ae | ||
|
|
74ece9b45b | ||
|
|
c77024314d | ||
|
|
828327365a | ||
|
|
4668638ee1 | ||
|
|
dbb0df607c | ||
|
|
2f74ec2518 | ||
|
|
8c6799297b | ||
|
|
62c0c1321f |
6
.github/ISSUE_TEMPLATE/bug_report.md
vendored
6
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -21,9 +21,5 @@ assignees: ''
|
|||||||
A clear and concise description of what the bug is.
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
On errors, please provide the output of the console (and `adb logcat` if relevant).
|
On errors, please provide the output of the console (and `adb logcat` if relevant).
|
||||||
|
Format them between code blocks (delimited by ```).
|
||||||
```
|
|
||||||
Please paste terminal output in a code block.
|
|
||||||
```
|
|
||||||
|
|
||||||
Please do not post screenshots of your terminal, just post the content as text instead.
|
Please do not post screenshots of your terminal, just post the content as text instead.
|
||||||
|
|||||||
23
README.md
23
README.md
@@ -396,8 +396,16 @@ The list of display ids can be retrieved by:
|
|||||||
adb shell dumpsys display # search "mDisplayId=" in the output
|
adb shell dumpsys display # search "mDisplayId=" in the output
|
||||||
```
|
```
|
||||||
|
|
||||||
The secondary display may only be controlled if the device runs at least Android
|
#### Stay awake
|
||||||
10 (otherwise it is mirrored in read-only).
|
|
||||||
|
To prevent the device to sleep after some delay:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --stay-awake
|
||||||
|
scrcpy -w
|
||||||
|
```
|
||||||
|
|
||||||
|
The initial state is restored when scrcpy is closed.
|
||||||
|
|
||||||
|
|
||||||
#### Turn screen off
|
#### Turn screen off
|
||||||
@@ -414,6 +422,14 @@ Or by pressing `Ctrl`+`o` at any time.
|
|||||||
|
|
||||||
To turn it back on, press `POWER` (or `Ctrl`+`p`).
|
To turn it back on, press `POWER` (or `Ctrl`+`p`).
|
||||||
|
|
||||||
|
It can be useful to also prevent the device to sleep:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --turn-screen-off --stay-awake
|
||||||
|
scrcpy -Sw
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Render expired frames
|
#### Render expired frames
|
||||||
|
|
||||||
By default, to minimize latency, _scrcpy_ always renders the last decoded frame
|
By default, to minimize latency, _scrcpy_ always renders the last decoded frame
|
||||||
@@ -433,7 +449,8 @@ device).
|
|||||||
|
|
||||||
Android provides this feature in _Developers options_.
|
Android provides this feature in _Developers options_.
|
||||||
|
|
||||||
_Scrcpy_ provides an option to enable this feature on start and disable on exit:
|
_Scrcpy_ provides an option to enable this feature on start and restore the
|
||||||
|
initial value on exit:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scrcpy --show-touches
|
scrcpy --show-touches
|
||||||
|
|||||||
529
README.pt_BR.md
529
README.pt_BR.md
@@ -1,529 +0,0 @@
|
|||||||
# scrcpy (v1.12.1)
|
|
||||||
|
|
||||||
Esta aplicação fornece visualização e controle de dispositivos Android conectados via
|
|
||||||
USB (ou [via TCP/IP][article-tcpip]). Não requer nenhum acesso root.
|
|
||||||
Funciona em _GNU/Linux_, _Windows_ e _macOS_.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Foco em:
|
|
||||||
|
|
||||||
- **leveza** (Nativo, mostra apenas a tela do dispositivo)
|
|
||||||
- **performance** (30~60fps)
|
|
||||||
- **qualidade** (1920×1080 ou acima)
|
|
||||||
- **baixa latência** ([35~70ms][lowlatency])
|
|
||||||
- **baixo tempo de inicialização** (~1 segundo para mostrar a primeira imagem)
|
|
||||||
- **não intrusivo** (nada é deixado instalado no dispositivo)
|
|
||||||
|
|
||||||
[lowlatency]: https://github.com/Genymobile/scrcpy/pull/646
|
|
||||||
|
|
||||||
|
|
||||||
## Requisitos
|
|
||||||
|
|
||||||
O Dispositivo Android requer pelo menos a API 21 (Android 5.0).
|
|
||||||
|
|
||||||
|
|
||||||
Tenha certeza de ter [ativado a depuração USB][enable-adb] no(s) seu(s) dispositivo(s).
|
|
||||||
|
|
||||||
[enable-adb]: https://developer.android.com/studio/command-line/adb.html#Enabling
|
|
||||||
|
|
||||||
|
|
||||||
Em alguns dispositivos, você também precisará ativar [uma opção adicional][control] para controlá-lo usando o teclado e mouse.
|
|
||||||
|
|
||||||
[control]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
|
||||||
|
|
||||||
|
|
||||||
## Obtendo o app
|
|
||||||
|
|
||||||
|
|
||||||
### Linux
|
|
||||||
|
|
||||||
No Debian (_em testes_ e _sid_ por enquanto):
|
|
||||||
|
|
||||||
```
|
|
||||||
apt install scrcpy
|
|
||||||
```
|
|
||||||
|
|
||||||
O pacote [Snap] está disponível: [`scrcpy`][snap-link].
|
|
||||||
|
|
||||||
[snap-link]: https://snapstats.org/snaps/scrcpy
|
|
||||||
|
|
||||||
[snap]: https://en.wikipedia.org/wiki/Snappy_(package_manager)
|
|
||||||
|
|
||||||
Para Arch Linux, um pacote [AUR] está disponível: [`scrcpy`][aur-link].
|
|
||||||
|
|
||||||
[AUR]: https://wiki.archlinux.org/index.php/Arch_User_Repository
|
|
||||||
[aur-link]: https://aur.archlinux.org/packages/scrcpy/
|
|
||||||
|
|
||||||
Para Gentoo, uma [Ebuild] está disponível: [`scrcpy/`][ebuild-link].
|
|
||||||
|
|
||||||
[Ebuild]: https://wiki.gentoo.org/wiki/Ebuild
|
|
||||||
[ebuild-link]: https://github.com/maggu2810/maggu2810-overlay/tree/master/app-mobilephone/scrcpy
|
|
||||||
|
|
||||||
|
|
||||||
Você também pode [compilar a aplicação manualmente][BUILD] (não se preocupe, não é tão difícil).
|
|
||||||
|
|
||||||
|
|
||||||
### Windows
|
|
||||||
|
|
||||||
Para Windows, para simplicidade, um arquivo pré-compilado com todas as dependências
|
|
||||||
(incluindo `adb`) está disponível:
|
|
||||||
|
|
||||||
- [`scrcpy-win64-v1.12.1.zip`][direct-win64]
|
|
||||||
_(SHA-256: 57d34b6d16cfd9fe169bc37c4df58ebd256d05c1ea3febc63d9cb0a027ab47c9)_
|
|
||||||
|
|
||||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.12.1/scrcpy-win64-v1.12.1.zip
|
|
||||||
|
|
||||||
Também disponível em [Chocolatey]:
|
|
||||||
|
|
||||||
[Chocolatey]: https://chocolatey.org/
|
|
||||||
|
|
||||||
```bash
|
|
||||||
choco install scrcpy
|
|
||||||
choco install adb # se você ainda não o tem
|
|
||||||
```
|
|
||||||
|
|
||||||
E no [Scoop]:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scoop install scrcpy
|
|
||||||
scoop install adb # se você ainda não o tem
|
|
||||||
```
|
|
||||||
|
|
||||||
[Scoop]: https://scoop.sh
|
|
||||||
|
|
||||||
Você também pode [compilar a aplicação manualmente][BUILD].
|
|
||||||
|
|
||||||
|
|
||||||
### macOS
|
|
||||||
|
|
||||||
A aplicação está disponível em [Homebrew]. Apenas a instale:
|
|
||||||
|
|
||||||
[Homebrew]: https://brew.sh/
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew install scrcpy
|
|
||||||
```
|
|
||||||
|
|
||||||
Você precisa do `adb`, acessível através do seu `PATH`. Se você ainda não o tem:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew cask install android-platform-tools
|
|
||||||
```
|
|
||||||
|
|
||||||
Você também pode [compilar a aplicação manualmente][BUILD].
|
|
||||||
|
|
||||||
|
|
||||||
## Executar
|
|
||||||
|
|
||||||
Plugue um dispositivo Android e execute:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy
|
|
||||||
```
|
|
||||||
|
|
||||||
Também aceita argumentos de linha de comando, listados por:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --help
|
|
||||||
```
|
|
||||||
|
|
||||||
## Funcionalidades
|
|
||||||
|
|
||||||
### Configuração de captura
|
|
||||||
|
|
||||||
#### Redução de tamanho
|
|
||||||
|
|
||||||
Algumas vezes, é útil espelhar um dispositivo Android em uma resolução menor para
|
|
||||||
aumentar performance.
|
|
||||||
|
|
||||||
Para limitar ambos(largura e altura) para algum valor (ex: 1024):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --max-size 1024
|
|
||||||
scrcpy -m 1024 # versão reduzida
|
|
||||||
```
|
|
||||||
|
|
||||||
A outra dimensão é calculada para que a proporção do dispositivo seja preservada.
|
|
||||||
Dessa forma, um dispositivo em 1920x1080 será espelhado em 1024x576.
|
|
||||||
|
|
||||||
|
|
||||||
#### Mudanças no bit-rate
|
|
||||||
|
|
||||||
O Padrão de bit-rate é 8 mbps. Para mudar o bitrate do vídeo (ex: para 2 Mbps):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --bit-rate 2M
|
|
||||||
scrcpy -b 2M # versão reduzida
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Limitar frame rates
|
|
||||||
|
|
||||||
Em dispositivos com Android >= 10, a captura de frame rate pode ser limitada:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --max-fps 15
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Cortar
|
|
||||||
|
|
||||||
A tela do dispositivo pode ser cortada para espelhar apenas uma parte da tela.
|
|
||||||
|
|
||||||
Isso é útil por exemplo, ao espelhar apenas um olho do Oculus Go:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --crop 1224:1440:0:0 # 1224x1440 no deslocamento (0,0)
|
|
||||||
```
|
|
||||||
|
|
||||||
Se `--max-size` também for especificado, redimensionar é aplicado após os cortes.
|
|
||||||
|
|
||||||
|
|
||||||
### Gravando
|
|
||||||
|
|
||||||
É possível gravar a tela enquanto ocorre o espelhamento:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --record file.mp4
|
|
||||||
scrcpy -r file.mkv
|
|
||||||
```
|
|
||||||
|
|
||||||
Para desativar o espelhamento durante a gravação:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --no-display --record file.mp4
|
|
||||||
scrcpy -Nr file.mkv
|
|
||||||
# interrompe a gravação com Ctrl+C
|
|
||||||
# Ctrl+C não encerrar propriamente no Windows, então desconecte o dispositivo
|
|
||||||
```
|
|
||||||
|
|
||||||
"Frames pulados" são gravados, mesmo que não sejam mostrado em tempo real (por motivos de performance).
|
|
||||||
Frames tem seu _horário_ _carimbado_ no dispositivo, então [Variação de atraso nos pacotes] não impacta na gravação do arquivo.
|
|
||||||
|
|
||||||
[Variação de atraso de pacote]: https://en.wikipedia.org/wiki/Packet_delay_variation
|
|
||||||
|
|
||||||
|
|
||||||
### Conexão
|
|
||||||
|
|
||||||
#### Wireless/Sem fio
|
|
||||||
|
|
||||||
_Scrcpy_ usa `adb` para se comunicar com o dispositivo, e `adb` pode [conectar-se] à um dispositivo via TCP/IP:
|
|
||||||
|
|
||||||
1. Conecte o dispositivo a mesma rede Wi-Fi do seu computador.
|
|
||||||
2. Pegue o endereço de IP do seu dispositivo (Em Configurações → Sobre o Telefone → Status).
|
|
||||||
3. Ative o adb via TCP/IP no seu dispositivo: `adb tcpip 5555`.
|
|
||||||
4. Desplugue seu dispositivo.
|
|
||||||
5. Conecte-se ao seu dispositivo: `adb connect DEVICE_IP:5555` _(substitua o `DEVICE_IP`)_.
|
|
||||||
6. Execute `scrcpy` como de costume.
|
|
||||||
|
|
||||||
Pode ser útil diminuir o bit-rate e a resolução:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --bit-rate 2M --max-size 800
|
|
||||||
scrcpy -b2M -m800 # versão reduzida
|
|
||||||
```
|
|
||||||
|
|
||||||
[conectar-se]: https://developer.android.com/studio/command-line/adb.html#wireless
|
|
||||||
|
|
||||||
|
|
||||||
#### N-dispositivos
|
|
||||||
|
|
||||||
Se alguns dispositivos estão listados em `adb devices`, você precisa especificar o _serial_:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --serial 0123456789abcdef
|
|
||||||
scrcpy -s 0123456789abcdef # versão reduzida
|
|
||||||
```
|
|
||||||
|
|
||||||
Se o dispositivo está conectado via TCP/IP:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --serial 192.168.0.1:5555
|
|
||||||
scrcpy -s 192.168.0.1:5555 # versão reduzida
|
|
||||||
```
|
|
||||||
|
|
||||||
Você pode iniciar algumas instâncias do _scrcpy_ para alguns dispositivos.
|
|
||||||
|
|
||||||
#### Conexão via SSH
|
|
||||||
|
|
||||||
Para conectar-se à um dispositivo remoto, é possível se conectar um cliente local `adb` à um servidor `adb` remoto (contanto que eles usem a mesma versão do protocolo _adb_):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
adb kill-server # encerra o servidor local na 5037
|
|
||||||
ssh -CN -L5037:localhost:5037 -R27183:localhost:27183 your_remote_computer
|
|
||||||
# mantém isso aberto
|
|
||||||
```
|
|
||||||
|
|
||||||
De outro terminal:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy
|
|
||||||
```
|
|
||||||
|
|
||||||
Igual para conexões sem fio, pode ser útil reduzir a qualidade:
|
|
||||||
|
|
||||||
```
|
|
||||||
scrcpy -b2M -m800 --max-fps 15
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configurações de Janela
|
|
||||||
|
|
||||||
#### Título
|
|
||||||
|
|
||||||
Por padrão, o título da janela é o modelo do dispositivo. Isto pode ser mudado:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --window-title 'Meu dispositivo'
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Posição e tamanho
|
|
||||||
|
|
||||||
A posição e tamanho iniciais da janela podem ser especificados:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Sem bordas
|
|
||||||
|
|
||||||
Para desativar decorações da janela:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --window-borderless
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Sempre visível
|
|
||||||
|
|
||||||
Para manter a janela do scrcpy sempre visível:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --always-on-top
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Tela cheia
|
|
||||||
|
|
||||||
A aplicação pode ser iniciada diretamente em tela cheia:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --fullscreen
|
|
||||||
scrcpy -f # versão reduzida
|
|
||||||
```
|
|
||||||
|
|
||||||
Tela cheia pode ser alternada dinamicamente com `Ctrl`+`f`.
|
|
||||||
|
|
||||||
|
|
||||||
### Outras opções de espelhamento
|
|
||||||
|
|
||||||
#### Apenas leitura
|
|
||||||
|
|
||||||
Para desativar controles (tudo que possa interagir com o dispositivo: teclas de entrada, eventos de mouse, arrastar e soltar arquivos):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --no-control
|
|
||||||
scrcpy -n
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Desligar a tela
|
|
||||||
|
|
||||||
É possível desligar a tela do dispositivo durante o início do espelhamento com uma opção de linha de comando:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --turn-screen-off
|
|
||||||
scrcpy -S
|
|
||||||
```
|
|
||||||
|
|
||||||
Ou apertando `Ctrl`+`o` durante qualquer momento.
|
|
||||||
|
|
||||||
Para ligar novamente, pressione `POWER` (ou `Ctrl`+`p`).
|
|
||||||
|
|
||||||
#### Frames expirados de renderização
|
|
||||||
|
|
||||||
Por padrão, para minimizar a latência, _scrcpy_ sempre renderiza o último frame decodificado disponível e descarta o anterior.
|
|
||||||
|
|
||||||
Para forçar a renderização de todos os frames ( com o custo de aumento de latência), use:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --render-expired-frames
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Mostrar toques
|
|
||||||
|
|
||||||
Para apresentações, pode ser útil mostrar toques físicos(dispositivo físico).
|
|
||||||
|
|
||||||
Android fornece esta funcionalidade nas _Opções do Desenvolvedor_.
|
|
||||||
|
|
||||||
_Scrcpy_ fornece esta opção de ativar esta funcionalidade no início e desativar no encerramento:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --show-touches
|
|
||||||
scrcpy -t
|
|
||||||
```
|
|
||||||
|
|
||||||
Note que isto mostra apenas toques _físicos_ (com o dedo no dispositivo).
|
|
||||||
|
|
||||||
|
|
||||||
### Controle de entrada
|
|
||||||
|
|
||||||
#### Rotacionar a tela do dispositivo
|
|
||||||
|
|
||||||
Pressione `Ctrl`+`r` para mudar entre os modos Retrato e Paisagem.
|
|
||||||
|
|
||||||
Note que só será rotacionado se a aplicação em primeiro plano tiver suporte para o modo requisitado.
|
|
||||||
|
|
||||||
#### Copiar-Colar
|
|
||||||
|
|
||||||
É possível sincronizar áreas de transferência entre computador e o dispositivo,
|
|
||||||
para ambas direções:
|
|
||||||
|
|
||||||
- `Ctrl`+`c` copia a área de transferência do dispositivo para a área de trasferência do computador;
|
|
||||||
- `Ctrl`+`Shift`+`v` copia a área de transferência do computador para a área de transferência do dispositivo;
|
|
||||||
- `Ctrl`+`v` _cola_ a área de transferência do computador como uma sequência de eventos de texto (mas
|
|
||||||
quebra caracteres não-ASCII).
|
|
||||||
|
|
||||||
#### Preferências de injeção de texto
|
|
||||||
|
|
||||||
Existe dois tipos de [eventos][textevents] gerados ao digitar um texto:
|
|
||||||
- _eventos de teclas_, sinalizando que a tecla foi pressionada ou solta;
|
|
||||||
- _eventos de texto_, sinalizando que o texto foi inserido.
|
|
||||||
|
|
||||||
Por padrão, letras são injetadas usando eventos de teclas, assim teclados comportam-se
|
|
||||||
como esperado em jogos (normalmente para tecladas WASD)
|
|
||||||
|
|
||||||
Mas isto pode [causar problemas][prefertext]. Se você encontrar tal problema,
|
|
||||||
pode evitá-lo usando:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --prefer-text
|
|
||||||
```
|
|
||||||
|
|
||||||
(mas isto vai quebrar o comportamento do teclado em jogos)
|
|
||||||
|
|
||||||
[textevents]: https://blog.rom1v.com/2018/03/introducing-scrcpy/#handle-text-input
|
|
||||||
[prefertext]: https://github.com/Genymobile/scrcpy/issues/650#issuecomment-512945343
|
|
||||||
|
|
||||||
|
|
||||||
### Transferência de arquivo
|
|
||||||
|
|
||||||
#### Instalar APK
|
|
||||||
|
|
||||||
Para instalar um APK, arraste e solte o arquivo APK(com extensão `.apk`) na janela _scrcpy_.
|
|
||||||
|
|
||||||
Não existe feedback visual, um log é imprimido no console.
|
|
||||||
|
|
||||||
|
|
||||||
#### Enviar arquivo para o dispositivo
|
|
||||||
|
|
||||||
Para enviar um arquivo para o diretório `/sdcard/` no dispositivo, arraste e solte um arquivo não APK para a janela do
|
|
||||||
_scrcpy_.
|
|
||||||
|
|
||||||
Não existe feedback visual, um log é imprimido no console.
|
|
||||||
|
|
||||||
O diretório alvo pode ser mudado ao iniciar:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scrcpy --push-target /sdcard/foo/bar/
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Encaminhamento de áudio
|
|
||||||
|
|
||||||
Áudio não é encaminhando pelo _scrcpy_. Use [USBaudio] (Apenas linux).
|
|
||||||
|
|
||||||
Também veja [issue #14].
|
|
||||||
|
|
||||||
[USBaudio]: https://github.com/rom1v/usbaudio
|
|
||||||
[issue #14]: https://github.com/Genymobile/scrcpy/issues/14
|
|
||||||
|
|
||||||
|
|
||||||
## Atalhos
|
|
||||||
|
|
||||||
| Ação | Atalho | Atalho (macOS)
|
|
||||||
| ------------------------------------------------------------- |:------------------------------- |:-----------------------------
|
|
||||||
| Alternar para modo de tela cheia | `Ctrl`+`f` | `Cmd`+`f`
|
|
||||||
| Redimensionar janela para pixel-perfect(Escala 1:1) | `Ctrl`+`g` | `Cmd`+`g`
|
|
||||||
| Redimensionar janela para tirar as bordas pretas | `Ctrl`+`x` \| _Clique-duplo¹_ | `Cmd`+`x` \| _Clique-duplo¹_
|
|
||||||
| Clicar em `HOME` | `Ctrl`+`h` \| _Clique-central_ | `Ctrl`+`h` \| _Clique-central_
|
|
||||||
| Clicar em `BACK` | `Ctrl`+`b` \| _Clique-direito²_ | `Cmd`+`b` \| _Clique-direito²_
|
|
||||||
| Clicar em `APP_SWITCH` | `Ctrl`+`s` | `Cmd`+`s`
|
|
||||||
| Clicar em `MENU` | `Ctrl`+`m` | `Ctrl`+`m`
|
|
||||||
| Clicar em `VOLUME_UP` | `Ctrl`+`↑` _(cima)_ | `Cmd`+`↑` _(cima)_
|
|
||||||
| Clicar em `VOLUME_DOWN` | `Ctrl`+`↓` _(baixo)_ | `Cmd`+`↓` _(baixo)_
|
|
||||||
| Clicar em `POWER` | `Ctrl`+`p` | `Cmd`+`p`
|
|
||||||
| Ligar | _Clique-direito²_ | _Clique-direito²_
|
|
||||||
| Desligar a tela do dispositivo | `Ctrl`+`o` | `Cmd`+`o`
|
|
||||||
| Rotacionar tela do dispositivo | `Ctrl`+`r` | `Cmd`+`r`
|
|
||||||
| Expandir painel de notificação | `Ctrl`+`n` | `Cmd`+`n`
|
|
||||||
| Esconder painel de notificação | `Ctrl`+`Shift`+`n` | `Cmd`+`Shift`+`n`
|
|
||||||
| Copiar área de transferência do dispositivo para o computador | `Ctrl`+`c` | `Cmd`+`c`
|
|
||||||
| Colar área de transferência do computador para o dispositivo | `Ctrl`+`v` | `Cmd`+`v`
|
|
||||||
| Copiar área de transferência do computador para dispositivo | `Ctrl`+`Shift`+`v` | `Cmd`+`Shift`+`v`
|
|
||||||
| Ativar/desativar contador de FPS(Frames por segundo) | `Ctrl`+`i` | `Cmd`+`i`
|
|
||||||
|
|
||||||
_¹Clique-duplo em bordas pretas para removê-las._
|
|
||||||
_²Botão direito liga a tela se ela estiver desligada, clique BACK para o contrário._
|
|
||||||
|
|
||||||
|
|
||||||
## Caminhos personalizados
|
|
||||||
|
|
||||||
Para usar um binário específico _adb_, configure seu caminho na variável de ambiente `ADB`:
|
|
||||||
|
|
||||||
ADB=/caminho/para/adb scrcpy
|
|
||||||
|
|
||||||
Para sobrepor o caminho do arquivo `scrcpy-server`, configure seu caminho em
|
|
||||||
`SCRCPY_SERVER_PATH`.
|
|
||||||
|
|
||||||
[useful]: https://github.com/Genymobile/scrcpy/issues/278#issuecomment-429330345
|
|
||||||
|
|
||||||
|
|
||||||
## Por quê _scrcpy_?
|
|
||||||
|
|
||||||
Um colega me desafiou a encontrar um nome impronunciável como [gnirehtet].
|
|
||||||
|
|
||||||
[`strcpy`] copia uma **str**ing; `scrcpy` copia uma **scr**een.
|
|
||||||
|
|
||||||
[gnirehtet]: https://github.com/Genymobile/gnirehtet
|
|
||||||
[`strcpy`]: http://man7.org/linux/man-pages/man3/strcpy.3.html
|
|
||||||
|
|
||||||
|
|
||||||
## Como compilar?
|
|
||||||
|
|
||||||
Veja [BUILD].
|
|
||||||
|
|
||||||
[BUILD]: BUILD.md
|
|
||||||
|
|
||||||
|
|
||||||
## Problemas comuns
|
|
||||||
|
|
||||||
Veja [FAQ](FAQ.md).
|
|
||||||
|
|
||||||
|
|
||||||
## Desenvolvedores
|
|
||||||
|
|
||||||
Leia a [developers page].
|
|
||||||
|
|
||||||
[developers page]: DEVELOP.md
|
|
||||||
|
|
||||||
|
|
||||||
## Licença
|
|
||||||
|
|
||||||
Copyright (C) 2018 Genymobile
|
|
||||||
Copyright (C) 2018-2020 Romain Vimont
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
## Artigos
|
|
||||||
|
|
||||||
- [Introducing scrcpy][article-intro]
|
|
||||||
- [Scrcpy now works wirelessly][article-tcpip]
|
|
||||||
|
|
||||||
[article-intro]: https://blog.rom1v.com/2018/03/introducing-scrcpy/
|
|
||||||
[article-tcpip]: https://www.genymotion.com/blog/open-source-project-scrcpy-now-works-wirelessly/
|
|
||||||
@@ -136,7 +136,7 @@ Turn the device screen off immediately.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-t, \-\-show\-touches
|
.B \-t, \-\-show\-touches
|
||||||
Enable "show touches" on start, disable on quit.
|
Enable "show touches" on start, restore the initial value on exit..
|
||||||
|
|
||||||
It only shows physical touches (not clicks from scrcpy).
|
It only shows physical touches (not clicks from scrcpy).
|
||||||
|
|
||||||
@@ -144,6 +144,10 @@ It only shows physical touches (not clicks from scrcpy).
|
|||||||
.B \-v, \-\-version
|
.B \-v, \-\-version
|
||||||
Print the version of scrcpy.
|
Print the version of scrcpy.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-w, \-\-stay-awake
|
||||||
|
Keep the device on while scrcpy is running.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-\-window\-borderless
|
.B \-\-window\-borderless
|
||||||
Disable window decorations (display borderless window).
|
Disable window decorations (display borderless window).
|
||||||
|
|||||||
@@ -130,12 +130,16 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
" Turn the device screen off immediately.\n"
|
" Turn the device screen off immediately.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -t, --show-touches\n"
|
" -t, --show-touches\n"
|
||||||
" Enable \"show touches\" on start, disable on quit.\n"
|
" Enable \"show touches\" on start, restore the initial value\n"
|
||||||
|
" on exit.\n"
|
||||||
" It only shows physical touches (not clicks from scrcpy).\n"
|
" It only shows physical touches (not clicks from scrcpy).\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -v, --version\n"
|
" -v, --version\n"
|
||||||
" Print the version of scrcpy.\n"
|
" Print the version of scrcpy.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" -w, --stay-awake\n"
|
||||||
|
" Keep the device on while scrcpy is running.\n"
|
||||||
|
"\n"
|
||||||
" --window-borderless\n"
|
" --window-borderless\n"
|
||||||
" Disable window decorations (display borderless window).\n"
|
" Disable window decorations (display borderless window).\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -486,6 +490,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
{"no-display", no_argument, NULL, 'N'},
|
{"no-display", no_argument, NULL, 'N'},
|
||||||
{"no-mipmaps", no_argument, NULL, OPT_NO_MIPMAPS},
|
{"no-mipmaps", no_argument, NULL, OPT_NO_MIPMAPS},
|
||||||
{"port", required_argument, NULL, 'p'},
|
{"port", required_argument, NULL, 'p'},
|
||||||
|
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
|
||||||
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
|
{"push-target", required_argument, NULL, OPT_PUSH_TARGET},
|
||||||
{"record", required_argument, NULL, 'r'},
|
{"record", required_argument, NULL, 'r'},
|
||||||
{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},
|
{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},
|
||||||
@@ -495,8 +500,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
{"rotation", required_argument, NULL, OPT_ROTATION},
|
{"rotation", required_argument, NULL, OPT_ROTATION},
|
||||||
{"serial", required_argument, NULL, 's'},
|
{"serial", required_argument, NULL, 's'},
|
||||||
{"show-touches", no_argument, NULL, 't'},
|
{"show-touches", no_argument, NULL, 't'},
|
||||||
|
{"stay-awake", no_argument, NULL, 'w'},
|
||||||
{"turn-screen-off", no_argument, NULL, 'S'},
|
{"turn-screen-off", no_argument, NULL, 'S'},
|
||||||
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
|
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
||||||
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
||||||
@@ -513,7 +518,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
optind = 0; // reset to start from the first argument in tests
|
optind = 0; // reset to start from the first argument in tests
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
|
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTvw", long_options,
|
||||||
NULL)) != -1) {
|
NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
@@ -593,6 +598,9 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
case 'v':
|
case 'v':
|
||||||
args->version = true;
|
args->version = true;
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
|
opts->stay_awake = true;
|
||||||
|
break;
|
||||||
case OPT_RENDER_EXPIRED_FRAMES:
|
case OPT_RENDER_EXPIRED_FRAMES:
|
||||||
opts->render_expired_frames = true;
|
opts->render_expired_frames = true;
|
||||||
break;
|
break;
|
||||||
@@ -675,5 +683,10 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!opts->control && opts->stay_awake) {
|
||||||
|
LOGE("Could not request to stay awake if control is disabled");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,21 +229,6 @@ event_loop(bool display, bool control) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static process_t
|
|
||||||
set_show_touches_enabled(const char *serial, bool enabled) {
|
|
||||||
const char *value = enabled ? "1" : "0";
|
|
||||||
const char *const adb_cmd[] = {
|
|
||||||
"shell", "settings", "put", "system", "show_touches", value
|
|
||||||
};
|
|
||||||
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
wait_show_touches(process_t process) {
|
|
||||||
// reap the process, ignore the result
|
|
||||||
process_check_success(process, "show_touches");
|
|
||||||
}
|
|
||||||
|
|
||||||
static SDL_LogPriority
|
static SDL_LogPriority
|
||||||
sdl_priority_from_av_level(int level) {
|
sdl_priority_from_av_level(int level) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
@@ -292,19 +277,13 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
.lock_video_orientation = options->lock_video_orientation,
|
.lock_video_orientation = options->lock_video_orientation,
|
||||||
.control = options->control,
|
.control = options->control,
|
||||||
.display_id = options->display_id,
|
.display_id = options->display_id,
|
||||||
|
.show_touches = options->show_touches,
|
||||||
|
.stay_awake = options->stay_awake,
|
||||||
};
|
};
|
||||||
if (!server_start(&server, options->serial, ¶ms)) {
|
if (!server_start(&server, options->serial, ¶ms)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_t proc_show_touches = PROCESS_NONE;
|
|
||||||
bool show_touches_waited;
|
|
||||||
if (options->show_touches) {
|
|
||||||
LOGI("Enable show_touches");
|
|
||||||
proc_show_touches = set_show_touches_enabled(options->serial, true);
|
|
||||||
show_touches_waited = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
bool fps_counter_initialized = false;
|
bool fps_counter_initialized = false;
|
||||||
@@ -421,11 +400,6 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->show_touches) {
|
|
||||||
wait_show_touches(proc_show_touches);
|
|
||||||
show_touches_waited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
input_manager.prefer_text = options->prefer_text;
|
input_manager.prefer_text = options->prefer_text;
|
||||||
|
|
||||||
ret = event_loop(options->display, options->control);
|
ret = event_loop(options->display, options->control);
|
||||||
@@ -482,16 +456,6 @@ end:
|
|||||||
fps_counter_destroy(&fps_counter);
|
fps_counter_destroy(&fps_counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->show_touches) {
|
|
||||||
if (!show_touches_waited) {
|
|
||||||
// wait the process which enabled "show touches"
|
|
||||||
wait_show_touches(proc_show_touches);
|
|
||||||
}
|
|
||||||
LOGI("Disable show_touches");
|
|
||||||
proc_show_touches = set_show_touches_enabled(options->serial, false);
|
|
||||||
wait_show_touches(proc_show_touches);
|
|
||||||
}
|
|
||||||
|
|
||||||
server_destroy(&server);
|
server_destroy(&server);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ struct scrcpy_options {
|
|||||||
bool prefer_text;
|
bool prefer_text;
|
||||||
bool window_borderless;
|
bool window_borderless;
|
||||||
bool mipmaps;
|
bool mipmaps;
|
||||||
|
bool stay_awake;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCRCPY_OPTIONS_DEFAULT { \
|
#define SCRCPY_OPTIONS_DEFAULT { \
|
||||||
@@ -72,6 +73,7 @@ struct scrcpy_options {
|
|||||||
.prefer_text = false, \
|
.prefer_text = false, \
|
||||||
.window_borderless = false, \
|
.window_borderless = false, \
|
||||||
.mipmaps = true, \
|
.mipmaps = true, \
|
||||||
|
.stay_awake = false, \
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -231,22 +231,17 @@ enable_tunnel_any_port(struct server *server, struct port_range port_range) {
|
|||||||
|
|
||||||
static process_t
|
static process_t
|
||||||
execute_server(struct server *server, const struct server_params *params) {
|
execute_server(struct server *server, const struct server_params *params) {
|
||||||
char max_size_string[6];
|
process_t result = PROCESS_NONE;
|
||||||
char bit_rate_string[11];
|
|
||||||
char max_fps_string[6];
|
char *cmd[128];
|
||||||
char lock_video_orientation_string[3];
|
int i = 0;
|
||||||
char display_id_string[6];
|
cmd[i++] = "shell";
|
||||||
sprintf(max_size_string, "%"PRIu16, params->max_size);
|
cmd[i++] = "CLASSPATH=" DEVICE_SERVER_PATH;
|
||||||
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
cmd[i++] = "app_process";
|
||||||
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
|
|
||||||
sprintf(lock_video_orientation_string, "%"PRIi8, params->lock_video_orientation);
|
|
||||||
sprintf(display_id_string, "%"PRIu16, params->display_id);
|
|
||||||
const char *const cmd[] = {
|
|
||||||
"shell",
|
|
||||||
"CLASSPATH=" DEVICE_SERVER_PATH,
|
|
||||||
"app_process",
|
|
||||||
#ifdef SERVER_DEBUGGER
|
#ifdef SERVER_DEBUGGER
|
||||||
# define SERVER_DEBUGGER_PORT "5005"
|
# define SERVER_DEBUGGER_PORT "5005"
|
||||||
|
cmd[i++] =
|
||||||
# ifdef SERVER_DEBUGGER_METHOD_NEW
|
# ifdef SERVER_DEBUGGER_METHOD_NEW
|
||||||
/* Android 9 and above */
|
/* Android 9 and above */
|
||||||
"-XjdwpProvider:internal -XjdwpOptions:transport=dt_socket,suspend=y,server=y,address="
|
"-XjdwpProvider:internal -XjdwpOptions:transport=dt_socket,suspend=y,server=y,address="
|
||||||
@@ -254,21 +249,38 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||||||
/* Android 8 and below */
|
/* Android 8 and below */
|
||||||
"-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address="
|
"-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address="
|
||||||
# endif
|
# endif
|
||||||
SERVER_DEBUGGER_PORT,
|
SERVER_DEBUGGER_PORT;
|
||||||
#endif
|
#endif
|
||||||
"/", // unused
|
|
||||||
"com.genymobile.scrcpy.Server",
|
cmd[i++] = "/"; // unused
|
||||||
SCRCPY_VERSION,
|
cmd[i++] = "com.genymobile.scrcpy.Server";
|
||||||
max_size_string,
|
cmd[i++] = SCRCPY_VERSION;
|
||||||
bit_rate_string,
|
|
||||||
max_fps_string,
|
int dyn_index = i; // from there, the strings are allocated
|
||||||
lock_video_orientation_string,
|
#define ADD_PARAM(fmt, ...) \
|
||||||
server->tunnel_forward ? "true" : "false",
|
cmd[i] = sc_asprintf(fmt, ## __VA_ARGS__); \
|
||||||
params->crop ? params->crop : "-",
|
if (!cmd[i++]) { \
|
||||||
"true", // always send frame meta (packet boundaries + timestamp)
|
goto end; \
|
||||||
params->control ? "true" : "false",
|
}
|
||||||
display_id_string,
|
|
||||||
};
|
#define STRBOOL(p) (p ? "true" : "false")
|
||||||
|
|
||||||
|
ADD_PARAM("max_size=%"PRIu16, params->max_size);
|
||||||
|
ADD_PARAM("bit_rate=%"PRIu32, params->bit_rate);
|
||||||
|
ADD_PARAM("max_fps=%"PRIu16, params->max_fps);
|
||||||
|
ADD_PARAM("lock_video_orientation=%"PRIi8, params->lock_video_orientation);
|
||||||
|
ADD_PARAM("tunnel_forward=%s", STRBOOL(server->tunnel_forward));
|
||||||
|
ADD_PARAM("crop=%s", params->crop ? params->crop : "");
|
||||||
|
// always send frame meta (packet boundaries + timestamp)
|
||||||
|
ADD_PARAM("send_frame_meta=true");
|
||||||
|
ADD_PARAM("control=%s", STRBOOL(params->control));
|
||||||
|
ADD_PARAM("display_id=%"PRIu16, params->display_id);
|
||||||
|
ADD_PARAM("show_touches=%s", STRBOOL(params->show_touches));
|
||||||
|
ADD_PARAM("stay_awake=%s", STRBOOL(params->stay_awake));
|
||||||
|
|
||||||
|
#undef ADD_PARAM
|
||||||
|
#undef STRBOOL
|
||||||
|
|
||||||
#ifdef SERVER_DEBUGGER
|
#ifdef SERVER_DEBUGGER
|
||||||
LOGI("Server debugger waiting for a client on device port "
|
LOGI("Server debugger waiting for a client on device port "
|
||||||
SERVER_DEBUGGER_PORT "...");
|
SERVER_DEBUGGER_PORT "...");
|
||||||
@@ -280,7 +292,14 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||||||
// Port: 5005
|
// Port: 5005
|
||||||
// Then click on "Debug"
|
// Then click on "Debug"
|
||||||
#endif
|
#endif
|
||||||
return adb_execute(server->serial, cmd, sizeof(cmd) / sizeof(cmd[0]));
|
result = adb_execute(server->serial, (const char **) cmd, i);
|
||||||
|
|
||||||
|
end:
|
||||||
|
for (int j = i; j > dyn_index; --j) {
|
||||||
|
free(cmd[j - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static socket_t
|
static socket_t
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ struct server_params {
|
|||||||
int8_t lock_video_orientation;
|
int8_t lock_video_orientation;
|
||||||
bool control;
|
bool control;
|
||||||
uint16_t display_id;
|
uint16_t display_id;
|
||||||
|
bool show_touches;
|
||||||
|
bool stay_awake;
|
||||||
};
|
};
|
||||||
|
|
||||||
// init default values
|
// init default values
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -195,3 +197,33 @@ utf8_from_wide_char(const wchar_t *ws) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *
|
||||||
|
sc_asprintf(const char *fmt, ...) {
|
||||||
|
va_list va;
|
||||||
|
va_start(va, fmt);
|
||||||
|
char *s = sc_vasprintf(fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
sc_vasprintf(const char *fmt, va_list ap) {
|
||||||
|
va_list va;
|
||||||
|
va_copy(va, ap);
|
||||||
|
int len = vsnprintf(NULL, 0, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
char *str = malloc(len + 1);
|
||||||
|
if (!str) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_copy(va, ap);
|
||||||
|
int len2 = vsprintf(str, fmt, va);
|
||||||
|
(void) len2;
|
||||||
|
assert(len == len2);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#ifndef STRUTIL_H
|
#ifndef STRUTIL_H
|
||||||
#define STRUTIL_H
|
#define STRUTIL_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@@ -57,4 +59,13 @@ char *
|
|||||||
utf8_from_wide_char(const wchar_t *s);
|
utf8_from_wide_char(const wchar_t *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// compatibility function similar to asprintf()
|
||||||
|
// (but returning the resulting string for convenience)
|
||||||
|
char *
|
||||||
|
sc_asprintf(const char *fmt, ...)
|
||||||
|
__attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
|
char *
|
||||||
|
sc_vasprintf(const char *fmt, va_list ap);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
77
server/src/main/java/com/genymobile/scrcpy/CleanUp.java
Normal file
77
server/src/main/java/com/genymobile/scrcpy/CleanUp.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
||||||
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the cleanup of scrcpy, even if the main process is killed.
|
||||||
|
* <p>
|
||||||
|
* This is useful to restore some state when scrcpy is closed, even on device disconnection (which kills the scrcpy process).
|
||||||
|
*/
|
||||||
|
public final class CleanUp {
|
||||||
|
|
||||||
|
public static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
|
||||||
|
|
||||||
|
private CleanUp() {
|
||||||
|
// not instantiable
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void configure(boolean disableShowTouches, int restoreStayOn) throws IOException {
|
||||||
|
boolean needProcess = disableShowTouches || restoreStayOn != -1;
|
||||||
|
if (needProcess) {
|
||||||
|
startProcess(disableShowTouches, restoreStayOn);
|
||||||
|
} else {
|
||||||
|
// There is no additional clean up to do when scrcpy dies
|
||||||
|
unlinkSelf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void startProcess(boolean disableShowTouches, int restoreStayOn) throws IOException {
|
||||||
|
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches), String.valueOf(restoreStayOn)};
|
||||||
|
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||||
|
builder.environment().put("CLASSPATH", SERVER_PATH);
|
||||||
|
builder.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unlinkSelf() {
|
||||||
|
try {
|
||||||
|
new File(SERVER_PATH).delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Ln.e("Could not unlink server", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
unlinkSelf();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Wait for the server to die
|
||||||
|
System.in.read();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Expected when the server is dead
|
||||||
|
}
|
||||||
|
|
||||||
|
Ln.i("Cleaning up");
|
||||||
|
|
||||||
|
boolean disableShowTouches = Boolean.parseBoolean(args[0]);
|
||||||
|
int restoreStayOn = Integer.parseInt(args[1]);
|
||||||
|
|
||||||
|
if (disableShowTouches || restoreStayOn != -1) {
|
||||||
|
ServiceManager serviceManager = new ServiceManager();
|
||||||
|
try (ContentProvider settings = serviceManager.getActivityManager().createSettingsProvider()) {
|
||||||
|
if (disableShowTouches) {
|
||||||
|
Ln.i("Disabling \"show touches\"");
|
||||||
|
settings.putValue(ContentProvider.TABLE_SYSTEM, "show_touches", "0");
|
||||||
|
}
|
||||||
|
if (restoreStayOn != -1) {
|
||||||
|
Ln.i("Restoring \"stay awake\"");
|
||||||
|
settings.putValue(ContentProvider.TABLE_GLOBAL, "stay_on_while_plugged_in", String.valueOf(restoreStayOn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.genymobile.scrcpy;
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
||||||
import com.genymobile.scrcpy.wrappers.InputManager;
|
import com.genymobile.scrcpy.wrappers.InputManager;
|
||||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||||
@@ -199,4 +200,8 @@ public final class Device {
|
|||||||
wm.thawRotation();
|
wm.thawRotation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContentProvider createSettingsProvider() {
|
||||||
|
return serviceManager.getActivityManager().createSettingsProvider();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ public class Options {
|
|||||||
private int maxSize;
|
private int maxSize;
|
||||||
private int bitRate;
|
private int bitRate;
|
||||||
private int maxFps;
|
private int maxFps;
|
||||||
private int lockedVideoOrientation;
|
private int lockedVideoOrientation = -1;
|
||||||
private boolean tunnelForward;
|
private boolean tunnelForward;
|
||||||
private Rect crop;
|
private Rect crop;
|
||||||
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
||||||
private boolean control;
|
private boolean control;
|
||||||
private int displayId;
|
private int displayId;
|
||||||
|
private boolean showTouches;
|
||||||
|
private boolean stayAwake;
|
||||||
|
|
||||||
public int getMaxSize() {
|
public int getMaxSize() {
|
||||||
return maxSize;
|
return maxSize;
|
||||||
@@ -84,4 +86,20 @@ public class Options {
|
|||||||
public void setDisplayId(int displayId) {
|
public void setDisplayId(int displayId) {
|
||||||
this.displayId = displayId;
|
this.displayId = displayId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getShowTouches() {
|
||||||
|
return showTouches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowTouches(boolean showTouches) {
|
||||||
|
this.showTouches = showTouches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStayAwake() {
|
||||||
|
return stayAwake;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStayAwake(boolean stayAwake) {
|
||||||
|
this.stayAwake = stayAwake;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,21 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||||||
|
|
||||||
public void streamScreen(Device device, FileDescriptor fd) throws IOException {
|
public void streamScreen(Device device, FileDescriptor fd) throws IOException {
|
||||||
Workarounds.prepareMainLooper();
|
Workarounds.prepareMainLooper();
|
||||||
Workarounds.fillAppInfo();
|
|
||||||
|
|
||||||
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL);
|
try {
|
||||||
|
internalStreamScreen(device, fd);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
// Retry with workarounds enabled:
|
||||||
|
// <https://github.com/Genymobile/scrcpy/issues/365>
|
||||||
|
// <https://github.com/Genymobile/scrcpy/issues/940>
|
||||||
|
Ln.d("Applying workarounds to avoid NullPointerException");
|
||||||
|
Workarounds.fillAppInfo();
|
||||||
|
internalStreamScreen(device, fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
|
||||||
|
MediaFormat format = createFormat(bitRate, maxFps);
|
||||||
device.setRotationListener(this);
|
device.setRotationListener(this);
|
||||||
boolean alive;
|
boolean alive;
|
||||||
try {
|
try {
|
||||||
@@ -139,14 +151,14 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||||||
return MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
|
return MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval) {
|
private static MediaFormat createFormat(int bitRate, int maxFps) {
|
||||||
MediaFormat format = new MediaFormat();
|
MediaFormat format = new MediaFormat();
|
||||||
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC);
|
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC);
|
||||||
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
|
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
|
||||||
// must be present to configure the encoder, but does not impact the actual frame rate, which is variable
|
// must be present to configure the encoder, but does not impact the actual frame rate, which is variable
|
||||||
format.setInteger(MediaFormat.KEY_FRAME_RATE, 60);
|
format.setInteger(MediaFormat.KEY_FRAME_RATE, 60);
|
||||||
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
|
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
|
||||||
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval);
|
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, DEFAULT_I_FRAME_INTERVAL);
|
||||||
// display the very first frame, and recover from bad quality when no new frames
|
// display the very first frame, and recover from bad quality when no new frames
|
||||||
format.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, REPEAT_FRAME_DELAY_US); // µs
|
format.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, REPEAT_FRAME_DELAY_US); // µs
|
||||||
if (maxFps > 0) {
|
if (maxFps > 0) {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.genymobile.scrcpy;
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
||||||
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.media.MediaCodec;
|
import android.media.MediaCodec;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class Server {
|
public final class Server {
|
||||||
|
|
||||||
private static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
|
|
||||||
|
|
||||||
private Server() {
|
private Server() {
|
||||||
// not instantiable
|
// not instantiable
|
||||||
@@ -18,6 +19,35 @@ public final class Server {
|
|||||||
private static void scrcpy(Options options) throws IOException {
|
private static void scrcpy(Options options) throws IOException {
|
||||||
Ln.i("Device: " + Build.MANUFACTURER + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
Ln.i("Device: " + Build.MANUFACTURER + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
||||||
final Device device = new Device(options);
|
final Device device = new Device(options);
|
||||||
|
|
||||||
|
boolean mustDisableShowTouchesOnCleanUp = false;
|
||||||
|
int restoreStayOn = -1;
|
||||||
|
if (options.getShowTouches() || options.getStayAwake()) {
|
||||||
|
try (ContentProvider settings = device.createSettingsProvider()) {
|
||||||
|
if (options.getShowTouches()) {
|
||||||
|
String oldValue = settings.getAndPutValue(ContentProvider.TABLE_SYSTEM, "show_touches", "1");
|
||||||
|
// If "show touches" was disabled, it must be disabled back on clean up
|
||||||
|
mustDisableShowTouchesOnCleanUp = !"1".equals(oldValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.getStayAwake()) {
|
||||||
|
int stayOn = BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||||
|
String oldValue = settings.getAndPutValue(ContentProvider.TABLE_GLOBAL, "stay_on_while_plugged_in", String.valueOf(stayOn));
|
||||||
|
try {
|
||||||
|
restoreStayOn = Integer.parseInt(oldValue);
|
||||||
|
if (restoreStayOn == stayOn) {
|
||||||
|
// No need to restore
|
||||||
|
restoreStayOn = -1;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
restoreStayOn = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CleanUp.configure(mustDisableShowTouchesOnCleanUp, restoreStayOn);
|
||||||
|
|
||||||
boolean tunnelForward = options.isTunnelForward();
|
boolean tunnelForward = options.isTunnelForward();
|
||||||
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
||||||
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps());
|
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps());
|
||||||
@@ -79,45 +109,73 @@ public final class Server {
|
|||||||
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length != 10) {
|
|
||||||
throw new IllegalArgumentException("Expecting 10 parameters");
|
|
||||||
}
|
|
||||||
|
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
|
||||||
int maxSize = Integer.parseInt(args[1]) & ~7; // multiple of 8
|
for (int i = 1; i < args.length; ++i) {
|
||||||
options.setMaxSize(maxSize);
|
String arg = args[i];
|
||||||
|
int equalIndex = arg.indexOf('=');
|
||||||
|
if (equalIndex == -1) {
|
||||||
|
throw new IllegalArgumentException("Invalid key=value pair: \"" + arg + "\"");
|
||||||
|
}
|
||||||
|
String key = arg.substring(0, equalIndex);
|
||||||
|
String value = arg.substring(equalIndex + 1);
|
||||||
|
|
||||||
int bitRate = Integer.parseInt(args[2]);
|
switch (key) {
|
||||||
options.setBitRate(bitRate);
|
case "max_size":
|
||||||
|
int maxSize = Integer.parseInt(value) & ~7; // multiple of 8
|
||||||
int maxFps = Integer.parseInt(args[3]);
|
options.setMaxSize(maxSize);
|
||||||
options.setMaxFps(maxFps);
|
break;
|
||||||
|
case "bit_rate":
|
||||||
int lockedVideoOrientation = Integer.parseInt(args[4]);
|
int bitRate = Integer.parseInt(value);
|
||||||
options.setLockedVideoOrientation(lockedVideoOrientation);
|
options.setBitRate(bitRate);
|
||||||
|
break;
|
||||||
// use "adb forward" instead of "adb tunnel"? (so the server must listen)
|
case "max_fps":
|
||||||
boolean tunnelForward = Boolean.parseBoolean(args[5]);
|
int maxFps = Integer.parseInt(value);
|
||||||
options.setTunnelForward(tunnelForward);
|
options.setMaxFps(maxFps);
|
||||||
|
break;
|
||||||
Rect crop = parseCrop(args[6]);
|
case "lock_video_orientation":
|
||||||
options.setCrop(crop);
|
int lockedVideoOrientation = Integer.parseInt(value);
|
||||||
|
options.setLockedVideoOrientation(lockedVideoOrientation);
|
||||||
boolean sendFrameMeta = Boolean.parseBoolean(args[7]);
|
break;
|
||||||
options.setSendFrameMeta(sendFrameMeta);
|
case "tunnel_forward":
|
||||||
|
// use "adb forward" instead of "adb tunnel"? (so the server must listen)
|
||||||
boolean control = Boolean.parseBoolean(args[8]);
|
boolean tunnelForward = Boolean.parseBoolean(value);
|
||||||
options.setControl(control);
|
options.setTunnelForward(tunnelForward);
|
||||||
|
break;
|
||||||
int displayId = Integer.parseInt(args[9]);
|
case "crop":
|
||||||
options.setDisplayId(displayId);
|
Rect crop = parseCrop(value);
|
||||||
|
options.setCrop(crop);
|
||||||
|
break;
|
||||||
|
case "send_frame_meta":
|
||||||
|
boolean sendFrameMeta = Boolean.parseBoolean(value);
|
||||||
|
options.setSendFrameMeta(sendFrameMeta);
|
||||||
|
break;
|
||||||
|
case "control":
|
||||||
|
boolean control = Boolean.parseBoolean(value);
|
||||||
|
options.setControl(control);
|
||||||
|
break;
|
||||||
|
case "display_id":
|
||||||
|
int displayId = Integer.parseInt(value);
|
||||||
|
options.setDisplayId(displayId);
|
||||||
|
break;
|
||||||
|
case "show_touches":
|
||||||
|
boolean showTouches = Boolean.parseBoolean(value);
|
||||||
|
options.setShowTouches(showTouches);
|
||||||
|
break;
|
||||||
|
case "stay_awake":
|
||||||
|
boolean stayAwake = Boolean.parseBoolean(value);
|
||||||
|
options.setStayAwake(stayAwake);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown parameter: " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Rect parseCrop(String crop) {
|
private static Rect parseCrop(String crop) {
|
||||||
if ("-".equals(crop)) {
|
if (crop.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// input format: "width:height:x:y"
|
// input format: "width:height:x:y"
|
||||||
@@ -132,14 +190,6 @@ public final class Server {
|
|||||||
return new Rect(x, y, x + width, y + height);
|
return new Rect(x, y, x + width, y + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void unlinkSelf() {
|
|
||||||
try {
|
|
||||||
new File(SERVER_PATH).delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Ln.e("Could not unlink server", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void suggestFix(Throwable e) {
|
private static void suggestFix(Throwable e) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (e instanceof MediaCodec.CodecException) {
|
if (e instanceof MediaCodec.CodecException) {
|
||||||
@@ -172,7 +222,6 @@ public final class Server {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
unlinkSelf();
|
|
||||||
Options options = createOptions(args);
|
Options options = createOptions(args);
|
||||||
scrcpy(options);
|
scrcpy(options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.genymobile.scrcpy.wrappers;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.Ln;
|
||||||
|
|
||||||
|
import android.os.Binder;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.IInterface;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class ActivityManager {
|
||||||
|
|
||||||
|
private final IInterface manager;
|
||||||
|
private Method getContentProviderExternalMethod;
|
||||||
|
private boolean getContentProviderExternalMethodLegacy;
|
||||||
|
private Method removeContentProviderExternalMethod;
|
||||||
|
|
||||||
|
public ActivityManager(IInterface manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getGetContentProviderExternalMethod() throws NoSuchMethodException {
|
||||||
|
if (getContentProviderExternalMethod == null) {
|
||||||
|
try {
|
||||||
|
getContentProviderExternalMethod = manager.getClass()
|
||||||
|
.getMethod("getContentProviderExternal", String.class, int.class, IBinder.class, String.class);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// old version
|
||||||
|
getContentProviderExternalMethod = manager.getClass().getMethod("getContentProviderExternal", String.class, int.class, IBinder.class);
|
||||||
|
getContentProviderExternalMethodLegacy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getContentProviderExternalMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getRemoveContentProviderExternalMethod() throws NoSuchMethodException {
|
||||||
|
if (removeContentProviderExternalMethod == null) {
|
||||||
|
removeContentProviderExternalMethod = manager.getClass().getMethod("removeContentProviderExternal", String.class, IBinder.class);
|
||||||
|
}
|
||||||
|
return removeContentProviderExternalMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContentProvider getContentProviderExternal(String name, IBinder token) {
|
||||||
|
try {
|
||||||
|
Method method = getGetContentProviderExternalMethod();
|
||||||
|
Object[] args;
|
||||||
|
if (!getContentProviderExternalMethodLegacy) {
|
||||||
|
// new version
|
||||||
|
args = new Object[]{name, ServiceManager.USER_ID, token, null};
|
||||||
|
} else {
|
||||||
|
// old version
|
||||||
|
args = new Object[]{name, ServiceManager.USER_ID, token};
|
||||||
|
}
|
||||||
|
// ContentProviderHolder providerHolder = getContentProviderExternal(...);
|
||||||
|
Object providerHolder = method.invoke(manager, args);
|
||||||
|
if (providerHolder == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// IContentProvider provider = providerHolder.provider;
|
||||||
|
Field providerField = providerHolder.getClass().getDeclaredField("provider");
|
||||||
|
providerField.setAccessible(true);
|
||||||
|
Object provider = providerField.get(providerHolder);
|
||||||
|
if (provider == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ContentProvider(this, provider, name, token);
|
||||||
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | NoSuchFieldException e) {
|
||||||
|
Ln.e("Could not invoke method", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeContentProviderExternal(String name, IBinder token) {
|
||||||
|
try {
|
||||||
|
Method method = getRemoveContentProviderExternalMethod();
|
||||||
|
method.invoke(manager, name, token);
|
||||||
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
|
Ln.e("Could not invoke method", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentProvider createSettingsProvider() {
|
||||||
|
return getContentProviderExternal("settings", new Binder());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ClipboardManager {
|
public class ClipboardManager {
|
||||||
|
|
||||||
private static final String PACKAGE_NAME = "com.android.shell";
|
|
||||||
private static final int USER_ID = 0;
|
|
||||||
|
|
||||||
private final IInterface manager;
|
private final IInterface manager;
|
||||||
private Method getPrimaryClipMethod;
|
private Method getPrimaryClipMethod;
|
||||||
private Method setPrimaryClipMethod;
|
private Method setPrimaryClipMethod;
|
||||||
@@ -46,17 +42,17 @@ public class ClipboardManager {
|
|||||||
|
|
||||||
private static ClipData getPrimaryClip(Method method, IInterface manager) throws InvocationTargetException, IllegalAccessException {
|
private static ClipData getPrimaryClip(Method method, IInterface manager) throws InvocationTargetException, IllegalAccessException {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
return (ClipData) method.invoke(manager, PACKAGE_NAME);
|
return (ClipData) method.invoke(manager, ServiceManager.PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
return (ClipData) method.invoke(manager, PACKAGE_NAME, USER_ID);
|
return (ClipData) method.invoke(manager, ServiceManager.PACKAGE_NAME, ServiceManager.USER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setPrimaryClip(Method method, IInterface manager, ClipData clipData)
|
private static void setPrimaryClip(Method method, IInterface manager, ClipData clipData)
|
||||||
throws InvocationTargetException, IllegalAccessException {
|
throws InvocationTargetException, IllegalAccessException {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
method.invoke(manager, clipData, PACKAGE_NAME);
|
method.invoke(manager, clipData, ServiceManager.PACKAGE_NAME);
|
||||||
} else {
|
} else {
|
||||||
method.invoke(manager, clipData, PACKAGE_NAME, USER_ID);
|
method.invoke(manager, clipData, ServiceManager.PACKAGE_NAME, ServiceManager.USER_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package com.genymobile.scrcpy.wrappers;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.Ln;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class ContentProvider implements Closeable {
|
||||||
|
|
||||||
|
public static final String TABLE_SYSTEM = "system";
|
||||||
|
public static final String TABLE_SECURE = "secure";
|
||||||
|
public static final String TABLE_GLOBAL = "global";
|
||||||
|
|
||||||
|
// See android/providerHolder/Settings.java
|
||||||
|
private static final String CALL_METHOD_GET_SYSTEM = "GET_system";
|
||||||
|
private static final String CALL_METHOD_GET_SECURE = "GET_secure";
|
||||||
|
private static final String CALL_METHOD_GET_GLOBAL = "GET_global";
|
||||||
|
|
||||||
|
private static final String CALL_METHOD_PUT_SYSTEM = "PUT_system";
|
||||||
|
private static final String CALL_METHOD_PUT_SECURE = "PUT_secure";
|
||||||
|
private static final String CALL_METHOD_PUT_GLOBAL = "PUT_global";
|
||||||
|
|
||||||
|
private static final String CALL_METHOD_USER_KEY = "_user";
|
||||||
|
|
||||||
|
private static final String NAME_VALUE_TABLE_VALUE = "value";
|
||||||
|
|
||||||
|
private final ActivityManager manager;
|
||||||
|
// android.content.IContentProvider
|
||||||
|
private final Object provider;
|
||||||
|
private final String name;
|
||||||
|
private final IBinder token;
|
||||||
|
|
||||||
|
private Method callMethod;
|
||||||
|
private boolean callMethodLegacy;
|
||||||
|
|
||||||
|
ContentProvider(ActivityManager manager, Object provider, String name, IBinder token) {
|
||||||
|
this.manager = manager;
|
||||||
|
this.provider = provider;
|
||||||
|
this.name = name;
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getCallMethod() throws NoSuchMethodException {
|
||||||
|
if (callMethod == null) {
|
||||||
|
try {
|
||||||
|
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, String.class, Bundle.class);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// old version
|
||||||
|
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, Bundle.class);
|
||||||
|
callMethodLegacy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return callMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bundle call(String callMethod, String arg, Bundle extras) {
|
||||||
|
try {
|
||||||
|
Method method = getCallMethod();
|
||||||
|
Object[] args;
|
||||||
|
if (!callMethodLegacy) {
|
||||||
|
args = new Object[]{ServiceManager.PACKAGE_NAME, "settings", callMethod, arg, extras};
|
||||||
|
} else {
|
||||||
|
args = new Object[]{ServiceManager.PACKAGE_NAME, callMethod, arg, extras};
|
||||||
|
}
|
||||||
|
return (Bundle) method.invoke(provider, args);
|
||||||
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
|
Ln.e("Could not invoke method", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
manager.removeContentProviderExternal(name, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getGetMethod(String table) {
|
||||||
|
switch (table) {
|
||||||
|
case TABLE_SECURE:
|
||||||
|
return CALL_METHOD_GET_SECURE;
|
||||||
|
case TABLE_SYSTEM:
|
||||||
|
return CALL_METHOD_GET_SYSTEM;
|
||||||
|
case TABLE_GLOBAL:
|
||||||
|
return CALL_METHOD_GET_GLOBAL;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid table: " + table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPutMethod(String table) {
|
||||||
|
switch (table) {
|
||||||
|
case TABLE_SECURE:
|
||||||
|
return CALL_METHOD_PUT_SECURE;
|
||||||
|
case TABLE_SYSTEM:
|
||||||
|
return CALL_METHOD_PUT_SYSTEM;
|
||||||
|
case TABLE_GLOBAL:
|
||||||
|
return CALL_METHOD_PUT_GLOBAL;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid table: " + table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue(String table, String key) {
|
||||||
|
String method = getGetMethod(table);
|
||||||
|
Bundle arg = new Bundle();
|
||||||
|
arg.putInt(CALL_METHOD_USER_KEY, ServiceManager.USER_ID);
|
||||||
|
Bundle bundle = call(method, key, arg);
|
||||||
|
if (bundle == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return bundle.getString("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putValue(String table, String key, String value) {
|
||||||
|
String method = getPutMethod(table);
|
||||||
|
Bundle arg = new Bundle();
|
||||||
|
arg.putInt(CALL_METHOD_USER_KEY, ServiceManager.USER_ID);
|
||||||
|
arg.putString(NAME_VALUE_TABLE_VALUE, value);
|
||||||
|
call(method, key, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAndPutValue(String table, String key, String value) {
|
||||||
|
String oldValue = getValue(table, key);
|
||||||
|
if (!value.equals(oldValue)) {
|
||||||
|
putValue(table, key, value);
|
||||||
|
}
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,10 @@ import java.lang.reflect.Method;
|
|||||||
|
|
||||||
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
@SuppressLint("PrivateApi,DiscouragedPrivateApi")
|
||||||
public final class ServiceManager {
|
public final class ServiceManager {
|
||||||
|
|
||||||
|
public static final String PACKAGE_NAME = "com.android.shell";
|
||||||
|
public static final int USER_ID = 0;
|
||||||
|
|
||||||
private final Method getServiceMethod;
|
private final Method getServiceMethod;
|
||||||
|
|
||||||
private WindowManager windowManager;
|
private WindowManager windowManager;
|
||||||
@@ -16,6 +20,7 @@ public final class ServiceManager {
|
|||||||
private PowerManager powerManager;
|
private PowerManager powerManager;
|
||||||
private StatusBarManager statusBarManager;
|
private StatusBarManager statusBarManager;
|
||||||
private ClipboardManager clipboardManager;
|
private ClipboardManager clipboardManager;
|
||||||
|
private ActivityManager activityManager;
|
||||||
|
|
||||||
public ServiceManager() {
|
public ServiceManager() {
|
||||||
try {
|
try {
|
||||||
@@ -76,4 +81,21 @@ public final class ServiceManager {
|
|||||||
}
|
}
|
||||||
return clipboardManager;
|
return clipboardManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActivityManager getActivityManager() {
|
||||||
|
if (activityManager == null) {
|
||||||
|
try {
|
||||||
|
// On old Android versions, the ActivityManager is not exposed via AIDL,
|
||||||
|
// so use ActivityManagerNative.getDefault()
|
||||||
|
Class<?> cls = Class.forName("android.app.ActivityManagerNative");
|
||||||
|
Method getDefaultMethod = cls.getDeclaredMethod("getDefault");
|
||||||
|
IInterface am = (IInterface) getDefaultMethod.invoke(null);
|
||||||
|
activityManager = new ActivityManager(am);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return activityManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user