Skip to content

Commit f448aca

Browse files
committed
fix: Cannot find Firefox package on device with work profile
1 parent 716339d commit f448aca

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

src/util/adb.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,31 @@ export default class ADBUtils {
8686
return devices.map((dev) => dev.id);
8787
}
8888

89+
async getCurrentUser(deviceId) {
90+
log.debug(`Retreiving current user on ${deviceId}`);
91+
92+
const currentUser = await this.runShellCommand(deviceId, [
93+
'am',
94+
'get-current-user',
95+
]);
96+
97+
const userId = parseInt(currentUser.trim());
98+
if (isNaN(userId)) {
99+
throw new WebExtError(`Unable to retreive current user on ${deviceId}`);
100+
}
101+
return userId;
102+
}
103+
89104
async discoverInstalledFirefoxAPKs(deviceId, firefoxApk) {
90-
log.debug(`Listing installed Firefox APKs on ${deviceId}`);
105+
const userId = await this.getCurrentUser(deviceId);
91106

107+
log.debug(`Listing installed Firefox APKs on ${deviceId}`);
92108
const pmList = await this.runShellCommand(deviceId, [
93109
'pm',
94110
'list',
95111
'packages',
112+
'--user',
113+
`${userId}`,
96114
]);
97115

98116
return pmList

tests/unit/test-util/test.adb.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,28 @@ describe('utils/adb', () => {
223223
testFn: (adbUtils) => adbUtils.discoverInstalledFirefoxAPKs('device1'),
224224
});
225225

226+
sinon.assert.calledOnce(adb.fakeADBDevice.shell);
227+
});
228+
229+
it('retrieves current user', async () => {
230+
const adb = getFakeADBKit({
231+
adbkitUtil: {
232+
readAll: sinon.spy(() => {
233+
return Promise.resolve(Buffer.from('0\n'));
234+
}),
235+
},
236+
});
237+
238+
const adbUtils = new ADBUtils({ adb });
239+
const promise = adbUtils.getCurrentUser();
240+
226241
sinon.assert.calledOnce(adb.fakeADBDevice.shell);
227242
sinon.assert.calledWith(adb.fakeADBDevice.shell, [
228-
'pm',
229-
'list',
230-
'packages',
243+
'am',
244+
'get-current-user',
231245
]);
246+
const result = await assert.isFulfilled(promise);
247+
assert.equal(result, 0);
232248
});
233249

234250
it('resolves the array of the installed firefox APKs', async () => {
@@ -242,11 +258,25 @@ describe('utils/adb', () => {
242258
}),
243259
},
244260
});
261+
262+
const stubGetCurrentUser = sinon.stub(
263+
ADBUtils.prototype,
264+
'getCurrentUser',
265+
);
266+
stubGetCurrentUser.resolves(0);
267+
245268
const adbUtils = new ADBUtils({ adb });
246269

247270
const promise = adbUtils.discoverInstalledFirefoxAPKs('device1');
248271
const packages = await assert.isFulfilled(promise);
249272
sinon.assert.calledOnce(adb.fakeADBDevice.shell);
273+
sinon.assert.calledWith(adb.fakeADBDevice.shell, [
274+
'pm',
275+
'list',
276+
'packages',
277+
'--user',
278+
'0',
279+
]);
250280
sinon.assert.calledOnce(adb.util.readAll);
251281
assert.deepEqual(packages, ['org.mozilla.fennec', 'org.mozilla.firefox']);
252282
});

0 commit comments

Comments
 (0)