diff --git a/lib/common b/lib/common index b88415ac1c..665ade98dd 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit b88415ac1c04d356687ea900424477adfcefaa46 +Subproject commit 665ade98dda49b04232db6ba17288156ff393088 diff --git a/lib/declarations.ts b/lib/declarations.ts index 98fd4c5ab0..b5756a38dc 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -57,6 +57,7 @@ interface IUsbLiveSyncService { interface IPlatformSpecificUsbLiveSyncService { restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture; + beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture; } interface IOptions extends ICommonOptions { diff --git a/lib/providers/device-app-data-provider.ts b/lib/providers/device-app-data-provider.ts index 22979f9669..5774e1fe9a 100644 --- a/lib/providers/device-app-data-provider.ts +++ b/lib/providers/device-app-data-provider.ts @@ -26,7 +26,9 @@ export class AndroidAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase } public get deviceProjectRootPath(): string { - return `/data/local/tmp/12590FAA-5EDD-4B12-856D-F52A0A1599F2/${this.appIdentifier}`; + let options: IOptions = $injector.resolve("options"); + let syncFolderName = options.watch ? "sync" : "fullsync"; + return `/data/local/tmp/${this.appIdentifier}/${syncFolderName}`; } public isLiveSyncSupported(device: Mobile.IDevice): IFuture { diff --git a/lib/services/usb-livesync-service.ts b/lib/services/usb-livesync-service.ts index 3217caef80..930ad3ce4e 100644 --- a/lib/services/usb-livesync-service.ts +++ b/lib/services/usb-livesync-service.ts @@ -36,22 +36,8 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer let platformData = this.$platformsData.getPlatformData(platform.toLowerCase()); let projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); - let canLiveSyncAction = (device: Mobile.IDevice, appIdentifier: string): IFuture => { - return (() => { - if(platform.toLowerCase() === "android") { - let output = (device).adb.executeShellCommand(`"echo '' | run-as ${appIdentifier}"`).wait(); - if(output.indexOf(`run-as: Package '${appIdentifier}' is unknown`) !== -1) { - this.$logger.warn(`Unable to livesync on device ${device.deviceInfo.identifier}. Consider upgrading your device OS.`); - return false; - } - } - - return true; - }).future()(); - } - let restartAppOnDeviceAction = (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture => { - let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device); + let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device); return platformSpecificUsbLiveSyncService.restartApplication(deviceAppData, localToDevicePaths); } @@ -66,9 +52,16 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer }).future()(); } + let beforeLiveSyncAction = (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData): IFuture => { + let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device); + if(platformSpecificUsbLiveSyncService.beforeLiveSyncAction) { + return platformSpecificUsbLiveSyncService.beforeLiveSyncAction(deviceAppData); + } + } + let watchGlob = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME); - this.sync(platform, this.$projectData.projectId, platformData.appDestinationDirectoryPath, projectFilesPath, this.excludedProjectDirsAndFiles, watchGlob, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeBatchLiveSyncAction, canLiveSyncAction).wait(); + this.sync(platform, this.$projectData.projectId, projectFilesPath, this.excludedProjectDirsAndFiles, watchGlob, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction, beforeBatchLiveSyncAction).wait(); }).future()(); } @@ -114,31 +107,20 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android let commands = [ this.liveSyncCommands.SyncFilesCommand() ]; this.livesync(deviceAppData.appIdentifier, deviceAppData.deviceProjectRootPath, commands).wait(); } else { - this.device.adb.executeShellCommand(`chmod 0777 ${this.$mobileHelper.buildDevicePath(deviceAppData.deviceProjectRootPath, "app")}`).wait(); - - let commands: string[] = []; - - let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`; - _.each(localToDevicePaths, localToDevicePath => { - let devicePath = this.$mobileHelper.correctDevicePath(path.join(devicePathRoot, localToDevicePath.getRelativeToProjectBasePath())); - if(this.$fs.getFsStats(localToDevicePath.getLocalPath()).wait().isFile()) { - commands.push(`mv "${localToDevicePath.getDevicePath()}" "${devicePath}"`); - } - }); - - commands.push(`rm -rf ${this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb")}`); - commands.push("exit"); - - let commandsFileDevicePath = this.$mobileHelper.buildDevicePath(deviceAppData.deviceProjectRootPath, AndroidUsbLiveSyncService.LIVESYNC_COMMANDS_FILE_NAME); - this.createCommandsFileOnDevice(commandsFileDevicePath, commands).wait(); - - let result = this.device.adb.executeShellCommand(`"cat ${commandsFileDevicePath} | run-as ${deviceAppData.appIdentifier}"`).wait(); - if(result.indexOf("Permission denied") !== -1) { - this.device.adb.executeShellCommand(`${commandsFileDevicePath}`).wait(); - } + let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`; + this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb")}`).wait(); } this.device.applicationManager.restartApplication(deviceAppData.appIdentifier).wait(); }).future()(); } + + public beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): IFuture { + return (() => { + let deviceRootPath = `/data/local/tmp/${deviceAppData.appIdentifier}`; + this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync")}`).wait(); + this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "sync")}`).wait(); + this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")}`).wait(); + }).future()(); + } }