Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 52d3993

Browse files
author
Android Build Coastguard Worker
committed
Snap for 13605992 from d1eb479 to 25Q3-release
Change-Id: I4b86079a002d3d63a9e253dbd832e2c2ea110027
2 parents 0a83138 + d1eb479 commit 52d3993

13 files changed

Lines changed: 148 additions & 24 deletions

‎tools/winscope/src/app/components/app_component_test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ describe('AppComponent', () => {
415415
snackbar = dom.getSnackBar();
416416
snackbar.checkText(firstMessage.getMessage());
417417

418-
snackbar.findAndClick('.snack-bar-action');
418+
snackbar.findAndClick('.snack-bar-actions .close-button');
419419
await dom.whenRenderingDone();
420420
snackbar = dom.getSnackBar();
421421
snackbar.checkText(secondMessage.getMessage());

‎tools/winscope/src/app/components/collect_traces_component_test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import {ClipboardModule} from '@angular/cdk/clipboard';
1617
import {CommonModule} from '@angular/common';
1718
import {
1819
Component,
@@ -97,6 +98,7 @@ describe('CollectTracesComponent', () => {
9798
MatSelectModule,
9899
MatFormFieldModule,
99100
MatInputModule,
101+
ClipboardModule,
100102
],
101103
providers: [MatSnackBar],
102104
declarations: [

‎tools/winscope/src/app/components/snack_bar_component.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {MatSnackBarRef, MAT_SNACK_BAR_DATA} from '@angular/material/snack-bar';
2626
{{ message }}
2727
</p>
2828
</div>
29-
<div class="snackbar-actions">
29+
<div class="snack-bar-actions">
3030
<button
3131
color="primary"
3232
mat-button
@@ -57,7 +57,7 @@ import {MatSnackBarRef, MAT_SNACK_BAR_DATA} from '@angular/material/snack-bar';
5757
.message {
5858
padding-block-end: 4px;
5959
}
60-
.snackbar-actions {
60+
.snack-bar-actions {
6161
display: flex;
6262
justify-content: center;
6363
}

‎tools/winscope/src/app/components/snack_bar_component_test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ describe('SnackBarComponent', () => {
5454
});
5555

5656
it('dismisses snackbar on close button click', () => {
57-
dom.findAndClick('.snackbar-actions .close-button');
57+
dom.findAndClick('.snack-bar-actions .close-button');
5858
expect(mockSnackbarRef.dismiss).toHaveBeenCalledTimes(1);
5959
});
6060

6161
it('copies messages on copy button click', () => {
62-
dom.findAndClick('.snackbar-actions .copy-button');
62+
dom.findAndClick('.snack-bar-actions .copy-button');
6363
expect(mockCopyText).toHaveBeenCalledOnceWith(messages.join('\n\n'));
6464
});
6565
});

‎tools/winscope/src/app/components/snack_bar_opener_test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {ClipboardModule} from '@angular/cdk/clipboard';
1718
import {Overlay} from '@angular/cdk/overlay';
1819
import {TestBed} from '@angular/core/testing';
1920
import {MatSnackBar, MatSnackBarRef} from '@angular/material/snack-bar';
@@ -39,7 +40,7 @@ describe('SnackBarOpener', () => {
3940
beforeEach(() => {
4041
TestBed.configureTestingModule({
4142
providers: [SnackBarOpener, MatSnackBar, Overlay],
42-
imports: [BrowserAnimationsModule],
43+
imports: [BrowserAnimationsModule, ClipboardModule],
4344
declarations: [SnackBarComponent],
4445
});
4546
snackBarOpener = TestBed.inject(SnackBarOpener);

‎tools/winscope/src/app/components/upload_traces_component_test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import {ClipboardModule} from '@angular/cdk/clipboard';
1617
import {TestBed} from '@angular/core/testing';
1718
import {MatCardModule} from '@angular/material/card';
1819
import {MatCheckboxModule} from '@angular/material/checkbox';
@@ -63,6 +64,7 @@ describe('UploadTracesComponent', () => {
6364
MatProgressBarModule,
6465
MatTooltipModule,
6566
MatCheckboxModule,
67+
ClipboardModule,
6668
],
6769
providers: [MatSnackBar],
6870
declarations: [UploadTracesComponent, LoadProgressComponent],

‎tools/winscope/src/trace_collection/adb/adb_device_connection.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export abstract class AdbDeviceConnection {
6464
return `${status}${this.model} (${this.id})`;
6565
}
6666

67+
async checkRoot(): Promise<boolean> {
68+
const root = await this.runShellCommand('su root id -u');
69+
return root === '0';
70+
}
71+
6772
async updateAvailableTraces() {
6873
if (
6974
this.state === AdbDeviceState.AVAILABLE &&
@@ -81,22 +86,25 @@ export abstract class AdbDeviceConnection {
8186
}
8287

8388
async findFiles(path: string, matchers: string[]): Promise<string[]> {
89+
const errors = ['No such file', 'Permission denied'];
8490
if (matchers.length === 0) {
8591
matchers.push('');
8692
}
93+
const isRoot = await this.checkRoot();
8794
for (const matcher of matchers) {
88-
let matchingFiles: string;
95+
let findCmd = `find ${path}`;
8996
if (matcher.length > 0) {
90-
matchingFiles = await this.runShellCommand(
91-
`su root find ${path} -name ${matcher}`,
92-
);
93-
} else {
94-
matchingFiles = await this.runShellCommand(`su root find ${path}`);
97+
findCmd += ` -name ${matcher}`;
98+
}
99+
if (isRoot) {
100+
findCmd = 'su root ' + findCmd;
95101
}
102+
const matchingFiles = await this.runShellCommand(findCmd);
96103
const files = matchingFiles
97104
.split('\n')
98105
.filter(
99-
(file) => !file.includes('No such file') && file.trim().length > 0,
106+
(maybeFile) =>
107+
!errors.includes(maybeFile) && maybeFile.trim().length > 0,
100108
);
101109
if (files.length > 0) {
102110
return files;

‎tools/winscope/src/trace_collection/adb/adb_device_connection_test.ts‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,25 @@ describe('AdbDeviceConnection', () => {
169169
});
170170

171171
it('finds files via exact filepath', async () => {
172+
runShellCmdSpy.withArgs('find filepath').and.returnValue('file');
173+
expect(await connection.findFiles('filepath', [])).toEqual(['file']);
174+
});
175+
176+
it('finds files via exact filepath as root', async () => {
177+
setDeviceAsRoot();
172178
runShellCmdSpy.withArgs('su root find filepath').and.returnValue('file');
173179
expect(await connection.findFiles('filepath', [])).toEqual(['file']);
174180
});
175181

176182
it('finds files via first matcher', async () => {
183+
runShellCmdSpy.withArgs('find filepath -name m1').and.returnValue('file');
184+
expect(await connection.findFiles('filepath', ['m1', 'm2'])).toEqual([
185+
'file',
186+
]);
187+
});
188+
189+
it('finds files via first matcher as root', async () => {
190+
setDeviceAsRoot();
177191
runShellCmdSpy
178192
.withArgs('su root find filepath -name m1')
179193
.and.returnValue('file');
@@ -183,6 +197,14 @@ describe('AdbDeviceConnection', () => {
183197
});
184198

185199
it('finds files via second matcher', async () => {
200+
runShellCmdSpy.withArgs('find filepath -name m2').and.returnValue('file');
201+
expect(await connection.findFiles('filepath', ['m1', 'm2'])).toEqual([
202+
'file',
203+
]);
204+
});
205+
206+
it('finds files via second matcher as root', async () => {
207+
setDeviceAsRoot();
186208
runShellCmdSpy
187209
.withArgs('su root find filepath -name m2')
188210
.and.returnValue('file');
@@ -192,16 +214,33 @@ describe('AdbDeviceConnection', () => {
192214
});
193215

194216
it('handles "No such file" error', async () => {
217+
runShellCmdSpy.withArgs('find filepath').and.returnValue('No such file');
218+
expect(await connection.findFiles('filepath', [])).toEqual([]);
219+
});
220+
221+
it('handles "Permission denied" error', async () => {
195222
runShellCmdSpy
196223
.withArgs('su root find filepath')
197-
.and.returnValue('No such file');
224+
.and.returnValue('Permission denied');
198225
expect(await connection.findFiles('filepath', [])).toEqual([]);
199226
});
200227

201228
it('ignores whitespace', async () => {
202-
runShellCmdSpy
203-
.withArgs('su root find filepath')
204-
.and.returnValue('file\n ');
229+
runShellCmdSpy.withArgs('find filepath').and.returnValue('file\n ');
205230
expect(await connection.findFiles('filepath', [])).toEqual(['file']);
206231
});
232+
233+
it('checks root and returns true for "0" output', async () => {
234+
setDeviceAsRoot();
235+
expect(await connection.checkRoot()).toBeTrue();
236+
});
237+
238+
it('checks root and returns false for non "0" output', async () => {
239+
setDeviceAsRoot();
240+
expect(await connection.checkRoot()).toBeTrue();
241+
});
242+
243+
function setDeviceAsRoot() {
244+
runShellCmdSpy.withArgs('su root id -u').and.returnValue('0');
245+
}
207246
});

‎tools/winscope/src/trace_collection/controller/tracing_session.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class TracingSession {
4848
}
4949

5050
async moveFiles(device: AdbDeviceConnection) {
51+
const isRoot = await device.checkRoot();
52+
const maybeRootParam = isRoot ? 'su root ' : '';
53+
5154
for (const file of this.target.fileIdentifiers) {
5255
const filepaths = await device.findFiles(file.path, file.matchers);
5356

@@ -57,7 +60,12 @@ export class TracingSession {
5760
);
5861
try {
5962
await device.runShellCommand(
60-
`su root [ ! -f ${filepath} ] || su root mv ${filepath} ${WINSCOPE_BACKUP_DIR}${file.destName}`,
63+
maybeRootParam +
64+
`[ -f ${filepath} ] && ` +
65+
maybeRootParam +
66+
`cp ${filepath} ${WINSCOPE_BACKUP_DIR}${file.destName} && ` +
67+
maybeRootParam +
68+
`rm -f ${filepath}`,
6169
);
6270
console.debug(
6371
`Moved ${filepath} to ${WINSCOPE_BACKUP_DIR}${file.destName} on device`,

‎tools/winscope/src/trace_collection/controller/tracing_session_test.ts‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ describe('TracingSession', () => {
3636
listener,
3737
);
3838
const fileIdentifiers = [
39-
new AdbFileIdentifier('test path 1', ['matcher'], 'saved file 1'),
40-
new AdbFileIdentifier('test path 2', ['matcher'], 'saved file 2'),
39+
new AdbFileIdentifier('test path 1', ['matcher'], 'saved_file_1'),
40+
new AdbFileIdentifier('test path 2', ['matcher'], 'saved_file_2'),
4141
];
4242
const sessionName = 'TestSession';
4343
const stopCmd = 'test stop cmd';
@@ -108,19 +108,45 @@ describe('TracingSession', () => {
108108
['test path 2', ['matcher']],
109109
]);
110110
expect(runShellCmdSpy.calls.allArgs()).toEqual([
111+
['su root id -u'],
111112
[
112-
`su root [ ! -f file ] || su root mv file ${WINSCOPE_BACKUP_DIR}saved file 1`,
113+
`[ -f file ] && cp file ${WINSCOPE_BACKUP_DIR}saved_file_1 && rm -f file`,
113114
],
114115
[
115-
`su root [ ! -f file ] || su root mv file ${WINSCOPE_BACKUP_DIR}saved file 2`,
116+
`[ -f file ] && cp file ${WINSCOPE_BACKUP_DIR}saved_file_2 && rm -f file`,
117+
],
118+
]);
119+
});
120+
121+
it('moves files as root', async () => {
122+
runShellCmdSpy.and.returnValue(Promise.resolve(''));
123+
setDeviceAsRoot();
124+
await session.moveFiles(mockDevice);
125+
expect(findFilesSpy.calls.allArgs()).toEqual([
126+
['test path 1', ['matcher']],
127+
['test path 2', ['matcher']],
128+
]);
129+
expect(runShellCmdSpy.calls.allArgs()).toEqual([
130+
['su root id -u'],
131+
[
132+
`su root [ -f file ] && su root cp file ${WINSCOPE_BACKUP_DIR}saved_file_1 && su root rm -f file`,
133+
],
134+
[
135+
`su root [ -f file ] && su root cp file ${WINSCOPE_BACKUP_DIR}saved_file_2 && su root rm -f file`,
116136
],
117137
]);
118138
});
119139

120140
it('handles error in move command', async () => {
141+
runShellCmdSpy.and.returnValue(Promise.resolve(''));
142+
runShellCmdSpy
143+
.withArgs(
144+
`[ -f file ] && cp file ${WINSCOPE_BACKUP_DIR}saved_file_1 && rm -f file`,
145+
)
146+
.and.throwError(new Error());
121147
runShellCmdSpy
122148
.withArgs(
123-
`su root [ ! -f file ] || su root mv file ${WINSCOPE_BACKUP_DIR}saved file 1`,
149+
`[ -f file ] && cp file ${WINSCOPE_BACKUP_DIR}saved_file_2 && rm -f file`,
124150
)
125151
.and.throwError(new Error());
126152
await expectAsync(session.moveFiles(mockDevice)).toBeResolved();
@@ -133,4 +159,10 @@ describe('TracingSession', () => {
133159
expect(endTraceSpy).toHaveBeenCalledWith(...endArgs);
134160
}
135161
}
162+
163+
function setDeviceAsRoot() {
164+
runShellCmdSpy
165+
.withArgs('su root id -u')
166+
.and.returnValue(Promise.resolve('0'));
167+
}
136168
});

0 commit comments

Comments
 (0)