1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16import {Component, EventEmitter, Input, Output} from '@angular/core'; 17import {proxyClient, ProxyClient, ProxyState} from 'trace_collection/proxy_client'; 18 19@Component({ 20 selector: 'adb-proxy', 21 template: ` 22 <ng-container [ngSwitch]="proxy.state"> 23 <ng-container *ngSwitchCase="states.NO_PROXY"> 24 <div class="further-adb-info-text"> 25 <p class="mat-body-1"> 26 Launch the Winscope ADB Connect proxy to capture traces directly from your browser. 27 </p> 28 <p class="mat-body-1">Python 3.5+ and ADB are required.</p> 29 <p class="mat-body-1"> 30 Run: 31 <code> 32 python3 $ANDROID_BUILD_TOP/development/tools/winscope/src/adb/winscope_proxy.py 33 </code> 34 </p> 35 <p class="mat-body-1">Or get it from the AOSP repository.</p> 36 </div> 37 38 <div class="further-adb-info-actions"> 39 <button color="primary" mat-stroked-button (click)="downloadFromAosp()"> 40 Download from AOSP 41 </button> 42 <button color="primary" mat-stroked-button class="retry" (click)="restart()"> 43 Retry 44 </button> 45 </div> 46 </ng-container> 47 48 <ng-container *ngSwitchCase="states.INVALID_VERSION"> 49 <div class="further-adb-info-text"> 50 <p class="icon-information mat-body-1"> 51 <mat-icon class="adb-icon">update</mat-icon> 52 <span class="adb-info">Your local proxy version is incompatible with Winscope.</span> 53 </p> 54 <p class="mat-body-1">Please update the proxy to version {{ proxyVersion }}.</p> 55 <p class="mat-body-1"> 56 Run: 57 <code> 58 python3 $ANDROID_BUILD_TOP/development/tools/winscope/src/adb/winscope_proxy.py 59 </code> 60 </p> 61 <p class="mat-body-1">Or get it from the AOSP repository.</p> 62 </div> 63 64 <div class="further-adb-info-actions"> 65 <button color="primary" mat-stroked-button (click)="downloadFromAosp()"> 66 Download from AOSP 67 </button> 68 <button color="primary" mat-stroked-button class="retry" (click)="restart()"> 69 Retry 70 </button> 71 </div> 72 </ng-container> 73 74 <ng-container *ngSwitchCase="states.UNAUTH"> 75 <div class="further-adb-info-text"> 76 <p class="icon-information mat-body-1"> 77 <mat-icon class="adb-icon">lock</mat-icon> 78 <span class="adb-info">Proxy authorisation required.</span> 79 </p> 80 <p class="mat-body-1">Enter Winscope proxy token:</p> 81 <mat-form-field> 82 <input matInput [(ngModel)]="proxyKeyItem" name="proxy-key" /> 83 </mat-form-field> 84 <p class="mat-body-1"> 85 The proxy token is printed to console on proxy launch, copy and paste it above. 86 </p> 87 </div> 88 89 <div class="further-adb-info-actions"> 90 <button color="primary" mat-stroked-button class="retry" (click)="restart()"> 91 Connect 92 </button> 93 </div> 94 </ng-container> 95 96 <ng-container *ngSwitchDefault></ng-container> 97 </ng-container> 98 `, 99 styles: [ 100 ` 101 .icon-information { 102 display: flex; 103 flex-direction: row; 104 align-items: center; 105 } 106 .further-adb-info-text { 107 display: flex; 108 flex-direction: column; 109 overflow-wrap: break-word; 110 gap: 10px; 111 margin-bottom: 10px; 112 } 113 .further-adb-info-actions { 114 display: flex; 115 flex-direction: row; 116 flex-wrap: wrap; 117 gap: 10px; 118 } 119 .adb-info { 120 margin-left: 5px; 121 } 122 `, 123 ], 124}) 125export class AdbProxyComponent { 126 @Input() 127 proxy: ProxyClient = proxyClient; 128 129 @Output() 130 proxyChange = new EventEmitter<ProxyClient>(); 131 132 @Output() 133 addKey = new EventEmitter<string>(); 134 135 states = ProxyState; 136 proxyKeyItem = ''; 137 readonly proxyVersion = this.proxy.VERSION; 138 readonly downloadProxyUrl: string = 139 'https://android.googlesource.com/platform/development/+/master/tools/winscope/adb_proxy/winscope_proxy.py'; 140 141 restart() { 142 this.addKey.emit(this.proxyKeyItem); 143 this.proxy.setState(this.states.CONNECTING); 144 this.proxyChange.emit(this.proxy); 145 } 146 147 downloadFromAosp() { 148 window.open(this.downloadProxyUrl, '_blank')?.focus(); 149 } 150} 151