Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate livesync logic from android runtime #736

Merged
merged 1 commit into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/common
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface IUsbLiveSyncService {

interface IPlatformSpecificUsbLiveSyncService {
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
}

interface IOptions extends ICommonOptions {
Expand Down
4 changes: 3 additions & 1 deletion lib/providers/device-app-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down
58 changes: 20 additions & 38 deletions lib/services/usb-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> => {
return (() => {
if(platform.toLowerCase() === "android") {
let output = (<Mobile.IAndroidDevice>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<boolean>()();
}

let restartAppOnDeviceAction = (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void> => {
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device);
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device);
return platformSpecificUsbLiveSyncService.restartApplication(deviceAppData, localToDevicePaths);
}

Expand All @@ -66,9 +52,16 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
}).future<string>()();
}

let beforeLiveSyncAction = (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData): IFuture<void> => {
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<void>()();
}

Expand Down Expand Up @@ -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<void>()();
}

public beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
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<void>()();
}
}