Skip to content

Commit

Permalink
feat: add tizen: listApps (#560)
Browse files Browse the repository at this point in the history
* feat: add tizen: listApps

* docs: add command in the readme

* fix lint

* correct the test case. It had \r\n
  • Loading branch information
KazuCocoa committed Jan 19, 2024
1 parent a386d0b commit eb77924
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
12 changes: 12 additions & 0 deletions packages/appium-tizen-tv-driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ exported by the [@headspinio/tizen-remote](https://github.com/headspinio/appium-

Refer to your Appium client library for how to use this method.

### Get the list of installed applications

> The list of installed applications.
> Each item has `appName` and `appPackage`.
- `POST /session/:sessionId/execute`

#### Arguments

- `script`: `tizen: listApps`


### Proxied Commands

Once a session is started, all commands other than the ones mentioned above are proxied to
Expand Down
21 changes: 15 additions & 6 deletions packages/appium-tizen-tv-driver/lib/cli/sdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import log from '../logger';
import {runCmd, SDB_BIN_NAME} from './helpers';

const DEBUG_PORT_RE = /^(?:.*port:\s)(?<port>\d{1,5})$/;
const APP_LIST_RE = /^[^']*'(?<name>[^']+)'[^']+'(?<id>[^']+)'.*$/;
const APP_LIST_RE = /^[^']*'(?<name>[^']*)'[^']+'(?<id>[^']+)'.*$/;

/**
*
Expand Down Expand Up @@ -50,24 +50,32 @@ async function launchApp({appPackage, udid}) {
}

/**
* Return the list of installed applications with the pair of
* an application name and the package name.
* @param {Pick<StrictTizenTVDriverCaps, 'udid'>} caps
* @returns {Promise<[appName: string, appPackage: string]>}
*/
async function listApps({udid}) {
log.info(`Listing apps installed on '${udid}'`);
const {stdout} = await runSDBCmd(udid, ['shell', '0', 'applist']);
const apps = stdout
.split('\n')
const apps = _parseListAppsCmd(stdout);
log.info(`There are ${apps.length} apps installed`);
return apps;
}

// FIXME: change to a class method and use #
function _parseListAppsCmd(input) {
return input
// the new string by tizen was '\r\n', so here should consider the case as well.
.split(/\r\n|\n/)
.map((line) => {
// TODO WIP fix this regex
const match = line.match(APP_LIST_RE);
if (!match?.groups) {
return false;
}
return {appName: match.groups.name, appPackage: match.groups.id};
})
.filter(Boolean);
log.info(`There are ${apps.length} apps installed`);
return apps;
}

/**
Expand Down Expand Up @@ -115,6 +123,7 @@ export {
debugApp,
launchApp,
listApps,
_parseListAppsCmd,
forwardPort,
removeForwardedPorts,
connectDevice,
Expand Down
14 changes: 14 additions & 0 deletions packages/appium-tizen-tv-driver/lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
debugApp,
disconnectDevice,
forwardPort,
listApps,
removeForwardedPort,
} from './cli/sdb';
import {tizenInstall, tizenRun, tizenUninstall} from './cli/tizen';
Expand Down Expand Up @@ -119,6 +120,10 @@ class TizenTVDriver extends BaseDriver {
command: 'longPressKey',
params: {required: ['key'], optional: ['duration']},
}),
'tizen: listApps': Object.freeze({
command: 'tizentvListApps',
params: {},
}),
});

/** @type {TizenRemote|undefined} */
Expand Down Expand Up @@ -608,6 +613,15 @@ class TizenTVDriver extends BaseDriver {

return await this.proxyCommand(`/element/${elId}/value`, 'POST', {text});
}

/**
* Return the list of installed applications with the pair of
* an application name and the package name.
* @returns {Promise<[appName: string, appPackage: string]>}
*/
async tizentvListApps() {
return await listApps({udid: this.opts.udid});
}
}

export {TizenTVDriver, Keys};
Expand Down
35 changes: 35 additions & 0 deletions packages/appium-tizen-tv-driver/test/unit/sdb.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unexpected from 'unexpected';
import unexpectedSinon from 'unexpected-sinon';
import {_parseListAppsCmd} from '../../lib/cli/sdb';

const expect = unexpected.clone().use(unexpectedSinon);

describe('sdb', function () {
describe('_parseListAppsCmd', function () {
it('should return the list of apps', function () {
const returnValue = "\tApplication List for user 5001\r\n\tUser's Application \r\n\t Name \t AppID \r\n\t=================================================\r\n\t'alexa-fullscreen-app'\t 'com.samsung.tv.alexa-client-xapp-ut-on-tv'\r\n\t'ContentSharing.Provider.Ftp'\t 'com.samsung.tv.coss.provider.d2d'\r\n\t'Xbox'\t 'GHI3a0zMSx.XboxGamePass'\r\n\t'cloning'\t 'org.tizen.cloning'\r\n\t'csfs'\t 'com.samsung.tv.csfs'\r\n\t'あ'\t 'pIaMf8YZyZ.service'\r\n\t'service-application'\t 'org.tizen.was-appsync'\r\n\t'fuzzy-search-engine'\t 'com.samsung.tv.fuzzy-search-engine'\r\n\t'pisa-control-service'\t 'org.tizen.pisa-control-service'\r\n\t'SmartThings Home CCTV Service'\t 'com.samsung.tv.iot-service-home-cctv_FLUX'\r\n\t'samsung-pass'\t 'com.samsung.tizen.samsung-pass-agent'\r\n\t'pluginplatform'\t 'com.samsung.tizen.smartthings-plugin-platform'\r\n\t'LibAriaFW'\t 'lib-ariafw-tv'\r\n\t'com.samsung.tv.ondevice-voice'\t 'com.samsung.tv.ondevice-voice'\r\n\t'PBS Video'\t '70fRFUwYlD.OtterGAProd'\r\n\t'iacr'\t 'com.samsung.tv.iacr'\r\n\t'Samsung Health'\t 'com.samsung.tv.samsung-health'\r\n\t''\t 'com.samsung.tv.remoteapp.local_stream'\r\n\t=================================================\r\n";

// Spaces in the app name should exist as-is.
expect(_parseListAppsCmd(returnValue), 'to equal', [
{ appName: 'alexa-fullscreen-app', appPackage: 'com.samsung.tv.alexa-client-xapp-ut-on-tv' },
{ appName: 'ContentSharing.Provider.Ftp', appPackage: 'com.samsung.tv.coss.provider.d2d' },
{ appName: 'Xbox', appPackage: 'GHI3a0zMSx.XboxGamePass' },
{ appName: 'cloning', appPackage: 'org.tizen.cloning' },
{ appName: 'csfs', appPackage: 'com.samsung.tv.csfs' },
{ appName: 'あ', appPackage: 'pIaMf8YZyZ.service' },
{ appName: 'service-application', appPackage: 'org.tizen.was-appsync' },
{ appName: 'fuzzy-search-engine', appPackage: 'com.samsung.tv.fuzzy-search-engine' },
{ appName: 'pisa-control-service', appPackage: 'org.tizen.pisa-control-service' },
{ appName: 'SmartThings Home CCTV Service', appPackage: 'com.samsung.tv.iot-service-home-cctv_FLUX' },
{ appName: 'samsung-pass', appPackage: 'com.samsung.tizen.samsung-pass-agent' },
{ appName: 'pluginplatform', appPackage: 'com.samsung.tizen.smartthings-plugin-platform' },
{ appName: 'LibAriaFW', appPackage: 'lib-ariafw-tv' },
{ appName: 'com.samsung.tv.ondevice-voice', appPackage: 'com.samsung.tv.ondevice-voice' },
{ appName: 'PBS Video', appPackage: '70fRFUwYlD.OtterGAProd' },
{ appName: 'iacr', appPackage: 'com.samsung.tv.iacr' },
{ appName: 'Samsung Health', appPackage: 'com.samsung.tv.samsung-health' },
{ appName: '', appPackage: 'com.samsung.tv.remoteapp.local_stream' }
]);
});
});
});

0 comments on commit eb77924

Please sign in to comment.