Skip to content
This repository was archived by the owner on Oct 2, 2026. It is now read-only.

Commit 70e6e4e

Browse files
authored
fix: require API 27 for extended lock management (#906)
* fix: require API 27 for extended lock management * fix: preserve failed locksettings probe behavior * refactor: detect lock management support by API level
1 parent 15b19f4 commit 70e6e4e

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎lib/tools/lockmgmt.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ const HIDE_KEYBOARD_WAIT_TIME = 100;
1919
*/
2020
export async function isLockManagementSupported(this: ADB): Promise<boolean> {
2121
if (typeof this._isLockManagementSupported !== 'boolean') {
22-
const passFlag = '__PASS__';
23-
let output = '';
24-
try {
25-
output = await this.shell([`locksettings help && echo ${passFlag}`]);
26-
} catch {}
27-
this._isLockManagementSupported = output.includes(passFlag);
22+
this._isLockManagementSupported = (await this.getApiLevel()) >= 27;
2823
log.debug(`Extended lock settings management is ${this._isLockManagementSupported ? '' : 'not '}supported`);
2924
}
3025
return this._isLockManagementSupported as boolean;

‎test/unit/lockmgmt.spec.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ describe('lock management', function () {
2020
sandbox.restore();
2121
});
2222

23+
describe('isLockManagementSupported', function () {
24+
for (const apiLevel of [26, 27, 36]) {
25+
it(`checks and caches support using only the API level (API ${apiLevel})`, async function () {
26+
const adb = new ADB();
27+
const getApiLevel = sandbox.stub(adb, 'getApiLevel').resolves(apiLevel);
28+
const shell = sandbox.stub(adb, 'shell');
29+
assert.strictEqual(await adb.isLockManagementSupported(), apiLevel >= 27);
30+
assert.strictEqual(await adb.isLockManagementSupported(), apiLevel >= 27);
31+
sinon.assert.calledOnce(getApiLevel);
32+
sinon.assert.notCalled(shell);
33+
});
34+
}
35+
36+
it('does not cache a failed API lookup', async function () {
37+
const adb = new ADB();
38+
const getApiLevel = sandbox.stub(adb, 'getApiLevel');
39+
getApiLevel.onFirstCall().rejects(new Error('device unavailable'));
40+
getApiLevel.onSecondCall().resolves(27);
41+
await assert.rejects(adb.isLockManagementSupported(), /device unavailable/);
42+
assert.strictEqual(await adb.isLockManagementSupported(), true);
43+
sinon.assert.calledTwice(getApiLevel);
44+
});
45+
});
46+
2347
describe('credential arguments', {skip: process.platform === 'win32'}, function () {
2448
const credentials = ['1234', "pass'word", 'two words', 'a"b', '$APPIUM_QUOTE_TEST', 'a;b', 'a\nb', '*'];
2549

0 commit comments

Comments
 (0)