Skip to content

Commit

Permalink
change the behavior depending on api level
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Jan 8, 2024
1 parent 75308aa commit 45b3bf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/tools/settings-client-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ const commands = {};

/**
* If the io.appium.settings package has running foreground service.
* It returns the io.appium.settings's process existence for api level 25 and lower
* since it does not have the foreground service.
*
* @this {import('../adb.js').ADB}
* @returns {Promise<boolean>} Return true if the device has running settings app foreground service.
*/
commands.hasRunningSettingsAppForegroundService = async function hasRunningSettingsAppForegroundService () {
if (await this.getApiLevel() < 26) {
return await this.processExists(SETTINGS_HELPER_ID);
}

// The foreground service is available since api level 26,
// thus this method works only for api level 26+.
try {
const output = await this.getActivityService(SETTINGS_HELPER_ID);
return (output.includes(FORE_GROUND_APP_KEYWORD));
Expand Down
16 changes: 14 additions & 2 deletions test/unit/adb-commands-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,9 @@ describe('adb commands', withMocks({adb, logcat, teen_process, net}, function (m
* ConnectionRecord{fbf1188 u0 CR FGS !PRCP io.appium.settings/.NLService:@339692b}
binding=AppBindRecord{c78a275 io.appium.settings/.NLService:system}
conn=android.app.LoadedApk$ServiceDispatcher$InnerConnection@339692b flags=0x5000101`;
mocks.adb.expects('shell').once().returns(getActivityServiceOutput);
mocks.adb.expects('getApiLevel').once().returns(26);
mocks.adb.expects('processExists').never();
mocks.adb.expects('getActivityService').once().returns(getActivityServiceOutput);
await adb.hasRunningSettingsAppForegroundService().should.eventually.true;
});
it('should return false if the output does not include isForeground=true', async function () {
Expand Down Expand Up @@ -1343,8 +1345,18 @@ describe('adb commands', withMocks({adb, logcat, teen_process, net}, function (m
* ConnectionRecord{8f3e709 u0 CR FGS !PRCP io.appium.settings/.NLService:@d481010}
binding=AppBindRecord{24ce493 io.appium.settings/.NLService:system}
conn=android.app.LoadedApk$ServiceDispatcher$InnerConnection@d481010 flags=0x5000101`;
mocks.adb.expects('shell').once().returns(getActivityServiceOutput);

mocks.adb.expects('getApiLevel').once().returns(26);
mocks.adb.expects('processExists').never();
mocks.adb.expects('getActivityService').once().returns(getActivityServiceOutput);
await adb.hasRunningSettingsAppForegroundService().should.eventually.false;
});
it('should rely on processExists for api level 25 and lower', async function () {
mocks.adb.expects('getApiLevel').once().returns(25);
mocks.adb.expects('processExists').once().returns(1000);
mocks.adb.expects('getActivityService').never();
await adb.hasRunningSettingsAppForegroundService().should.eventually.eql(1000);
});

});
}));

0 comments on commit 45b3bf1

Please sign in to comment.