Skip to content

Commit 69c3744

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Integrate livesync logic from android runtime
1 parent 529004f commit 69c3744

File tree

4 files changed

+25
-40
lines changed

4 files changed

+25
-40
lines changed

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ interface IUsbLiveSyncService {
5757

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

6263
interface IOptions extends ICommonOptions {

lib/providers/device-app-data-provider.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export class AndroidAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase
2626
}
2727

2828
public get deviceProjectRootPath(): string {
29-
return `/data/local/tmp/12590FAA-5EDD-4B12-856D-F52A0A1599F2/${this.appIdentifier}`;
29+
let options: IOptions = $injector.resolve("options");
30+
let syncFolderName = options.watch ? "sync" : "fullsync";
31+
return `/data/local/tmp/${this.appIdentifier}/${syncFolderName}`;
3032
}
3133

3234
public isLiveSyncSupported(device: Mobile.IDevice): IFuture<boolean> {

lib/services/usb-livesync-service.ts

+20-38
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,8 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
3636
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
3737
let projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
3838

39-
let canLiveSyncAction = (device: Mobile.IDevice, appIdentifier: string): IFuture<boolean> => {
40-
return (() => {
41-
if(platform.toLowerCase() === "android") {
42-
let output = (<Mobile.IAndroidDevice>device).adb.executeShellCommand(`"echo '' | run-as ${appIdentifier}"`).wait();
43-
if(output.indexOf(`run-as: Package '${appIdentifier}' is unknown`) !== -1) {
44-
this.$logger.warn(`Unable to livesync on device ${device.deviceInfo.identifier}. Consider upgrading your device OS.`);
45-
return false;
46-
}
47-
}
48-
49-
return true;
50-
}).future<boolean>()();
51-
}
52-
5339
let restartAppOnDeviceAction = (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void> => {
54-
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device);
40+
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device);
5541
return platformSpecificUsbLiveSyncService.restartApplication(deviceAppData, localToDevicePaths);
5642
}
5743

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

55+
let beforeLiveSyncAction = (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData): IFuture<void> => {
56+
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device);
57+
if(platformSpecificUsbLiveSyncService.beforeLiveSyncAction) {
58+
return platformSpecificUsbLiveSyncService.beforeLiveSyncAction(deviceAppData);
59+
}
60+
}
61+
6962
let watchGlob = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
7063

71-
this.sync(platform, this.$projectData.projectId, platformData.appDestinationDirectoryPath, projectFilesPath, this.excludedProjectDirsAndFiles, watchGlob, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeBatchLiveSyncAction, canLiveSyncAction).wait();
64+
this.sync(platform, this.$projectData.projectId, projectFilesPath, this.excludedProjectDirsAndFiles, watchGlob, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction, beforeBatchLiveSyncAction).wait();
7265
}).future<void>()();
7366
}
7467

@@ -114,31 +107,20 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
114107
let commands = [ this.liveSyncCommands.SyncFilesCommand() ];
115108
this.livesync(deviceAppData.appIdentifier, deviceAppData.deviceProjectRootPath, commands).wait();
116109
} else {
117-
this.device.adb.executeShellCommand(`chmod 0777 ${this.$mobileHelper.buildDevicePath(deviceAppData.deviceProjectRootPath, "app")}`).wait();
118-
119-
let commands: string[] = [];
120-
121-
let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
122-
_.each(localToDevicePaths, localToDevicePath => {
123-
let devicePath = this.$mobileHelper.correctDevicePath(path.join(devicePathRoot, localToDevicePath.getRelativeToProjectBasePath()));
124-
if(this.$fs.getFsStats(localToDevicePath.getLocalPath()).wait().isFile()) {
125-
commands.push(`mv "${localToDevicePath.getDevicePath()}" "${devicePath}"`);
126-
}
127-
});
128-
129-
commands.push(`rm -rf ${this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb")}`);
130-
commands.push("exit");
131-
132-
let commandsFileDevicePath = this.$mobileHelper.buildDevicePath(deviceAppData.deviceProjectRootPath, AndroidUsbLiveSyncService.LIVESYNC_COMMANDS_FILE_NAME);
133-
this.createCommandsFileOnDevice(commandsFileDevicePath, commands).wait();
134-
135-
let result = this.device.adb.executeShellCommand(`"cat ${commandsFileDevicePath} | run-as ${deviceAppData.appIdentifier}"`).wait();
136-
if(result.indexOf("Permission denied") !== -1) {
137-
this.device.adb.executeShellCommand(`${commandsFileDevicePath}`).wait();
138-
}
110+
let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
111+
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb")}`).wait();
139112
}
140113

141114
this.device.applicationManager.restartApplication(deviceAppData.appIdentifier).wait();
142115
}).future<void>()();
143116
}
117+
118+
public beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
119+
return (() => {
120+
let deviceRootPath = `/data/local/tmp/${deviceAppData.appIdentifier}`;
121+
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync")}`).wait();
122+
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "sync")}`).wait();
123+
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")}`).wait();
124+
}).future<void>()();
125+
}
144126
}

0 commit comments

Comments
 (0)