Skip to content

Commit

Permalink
Simplify run shell as root (#2055)
Browse files Browse the repository at this point in the history
* Simplify run as root for Android Command

* hepp
  • Loading branch information
soulgalore authored Jan 5, 2024
1 parent d25f85b commit 79b382c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/core/engine/command/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const log = intel.getLogger('browsertime.command.android');
/**
* Provides functionality to interact with an Android device through shell commands.
*
* @class
* @see https://www.sitespeed.io/documentation/sitespeed.io/mobile-phones/#test-on-android
* @class
*/
export class AndroidCommand {
constructor(options) {
Expand Down Expand Up @@ -36,4 +36,29 @@ export class AndroidCommand {
}
} else throw new Error('Android is not configured');
}

/**
* Runs a shell command on the connected Android device as the root user.
* This method requires the Android device to be properly configured and that you
* rooted the device.
*
* @async
* @param {string} command - The shell command to run on the Android device as root.
* @returns {Promise<string>} A promise that resolves with the result of the command or rejects if there's an error.
* @throws {Error} Throws an error if Android is not configured or if the command fails.
*/
async shellAsRoot(command) {
if (isAndroidConfigured(this.options)) {
log.debug('Run %s', command);
try {
this.a = new Android(this.options);
return this.a._runAsRootAndGet(command);
} catch (error) {
log.error('Could not run shell command as root %s', command, error);
throw new Error(
`Could not run Android shell commmand as root ${command}`
);
}
} else throw new Error('Android is not configured');
}
}

0 comments on commit 79b382c

Please sign in to comment.