@@ -34,16 +34,18 @@ async function pullAndroidDBFiles(packageName, deviceId, remotePath, localPath =
34
34
35
35
// Use run-as to copy the database file to the local machine
36
36
await new Promise < void > ( ( resolve , reject ) => {
37
- // Use exec-out to avoid text encoding issues with binary data
38
- const adminCmd = location ?. admin ? `run-as ${ packageName } ` : ''
39
- const cmd = `adb -s ${ deviceId } exec-out ${ adminCmd } cat ${ remotePath } > ${ localPath } `
40
- exec ( cmd , ( error , _stdout , stderr ) => {
37
+ let callCmd = `adb -s ${ deviceId } exec-out run-as ${ packageName } cat ${ remotePath } > ${ localPath } `
38
+
39
+ if ( location . admin === false ) {
40
+ // If not admin, we need to pull the file instead
41
+ callCmd = `adb -s ${ deviceId } pull ${ remotePath } ${ localPath } `
42
+ }
43
+
44
+ log . info ( `Running command pull: ${ callCmd } ` )
45
+ exec ( callCmd , ( error , _stdout , _stderr ) => {
41
46
if ( error ) {
42
47
reject ( error )
43
48
}
44
- else if ( stderr && ! stderr . includes ( 'pulled' ) ) {
45
- reject ( new Error ( stderr ) )
46
- }
47
49
else {
48
50
resolve ( )
49
51
}
@@ -203,6 +205,8 @@ export function setupIpcADB() {
203
205
const adminCmd = options . admin ? `run-as ${ packageName } ` : ''
204
206
const cmd = `adb -s ${ deviceId } shell ${ adminCmd } find ${ location } ${ packageName } / -name "*.db" -o -name "*.sqlite" -o -name "*.sqlite3" 2>/dev/null`
205
207
208
+ log . info ( `Running command: ${ cmd } ` )
209
+
206
210
const filesOutput = await new Promise < string > ( ( resolve , _reject ) => {
207
211
exec ( cmd , ( _error , stdout , _stderr ) => {
208
212
// We don't reject here because some errors are expected
@@ -214,21 +218,24 @@ export function setupIpcADB() {
214
218
// Process found files
215
219
const filePaths = filesOutput . split ( '\n' ) . filter ( line => line . trim ( ) . length > 0 )
216
220
217
- await Promise . all ( filePaths . map ( async ( filePath ) => {
218
- const filename = path . basename ( filePath )
219
-
220
- const pulledFileData = await pullAndroidDBFiles ( packageName , deviceId , filePath , '' , location )
221
-
222
- databaseFiles . push ( {
223
- path : pulledFileData . path || filePath ,
224
- packageName,
225
- filename,
226
- location,
227
- remotePath : filePath ,
228
- deviceType : 'android' ,
229
- } )
230
- } ) ,
221
+ const pulledFiles = await Promise . all (
222
+ filePaths . map ( async ( filePath ) => {
223
+ const filename = path . basename ( filePath )
224
+
225
+ const pulledFileData = await pullAndroidDBFiles ( packageName , deviceId , filePath , '' , location )
226
+
227
+ return {
228
+ path : pulledFileData . path || filePath ,
229
+ packageName,
230
+ filename,
231
+ location,
232
+ remotePath : filePath ,
233
+ deviceType : 'android' ,
234
+ } as DatabaseFile
235
+ } ) ,
231
236
)
237
+
238
+ databaseFiles . push ( ...pulledFiles )
232
239
}
233
240
catch ( err ) {
234
241
// Silently fail for individual locations - we'll still try others
@@ -251,6 +258,21 @@ export function setupIpcADB() {
251
258
const filename = path . basename ( localPath )
252
259
const tmpPath = `/data/local/tmp/${ filename } `
253
260
261
+ if ( remotePath . includes ( 'sdcard' ) || remotePath . includes ( 'external' ) ) {
262
+ await new Promise < void > ( ( resolve , reject ) => {
263
+ exec ( `adb -s ${ deviceId } push ${ localPath } ${ remotePath } ` , ( error , _stdout , _stderr ) => {
264
+ if ( error ) {
265
+ reject ( error )
266
+ }
267
+ else {
268
+ resolve ( )
269
+ }
270
+ } )
271
+ } )
272
+
273
+ return
274
+ }
275
+
254
276
// Push the file to device tmp directory
255
277
await new Promise < void > ( ( resolve , reject ) => {
256
278
exec ( `adb -s ${ deviceId } push "${ localPath } " ${ tmpPath } ` , ( error , _stdout , stderr ) => {
0 commit comments