Skip to content

Commit

Permalink
Speed up livesync on android device
Browse files Browse the repository at this point in the history
Related:  #921
  • Loading branch information
Fatme Havaluova authored and rosen-vladimirov committed Feb 4, 2016
1 parent f2ed563 commit 8d9c319
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IPlatformService {
runPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
preparePlatform(platform: string): IFuture<boolean>;
buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
installOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
deployOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/livesync-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class LiveSyncProvider implements ILiveSyncProvider {

public buildForDevice(device: Mobile.IDevice): IFuture<string> {
return (() => {
this.$platformService.buildPlatform(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
this.$platformService.buildForDeploy(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform);
if (device.isEmulator) {
return this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait().packageName;
Expand Down
10 changes: 9 additions & 1 deletion lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as constants from "../constants";
import * as semver from "semver";
import * as projectServiceBaseLib from "./platform-project-service-base";
import * as androidDebugBridgePath from "../common/mobile/android/android-debug-bridge";
import {AndroidDeviceHashService} from "../common/mobile/android/android-device-hash-service";

export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
private static VALUES_DIRNAME = "values";
Expand All @@ -29,7 +30,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
private $sysInfo: ISysInfo,
private $mobileHelper: Mobile.IMobileHelper,
private $injector: IInjector,
private $pluginVariablesService: IPluginVariablesService) {
private $pluginVariablesService: IPluginVariablesService,
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory) {
super($fs, $projectData, $projectDataService);
this._androidProjectPropertiesManagers = Object.create(null);
}
Expand Down Expand Up @@ -330,6 +332,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync"),
this.$mobileHelper.buildDevicePath(deviceRootPath, "sync"),
this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")]).wait();

let projectFilesManager = this.$injector.resolve("projectFilesManager"); // We need to resolve projectFilesManager here due to cyclic dependency
let deviceAppData = this.$deviceAppDataFactory.create(this.$projectData.projectId, this.platformData.normalizedPlatformName, null);
let localToDevicePaths = projectFilesManager.createLocalToDevicePaths(deviceAppData, path.join(this.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
let deviceHashService = this.$injector.resolve(AndroidDeviceHashService, { adb: adb, appIdentifier: this.$projectData.projectId });
deviceHashService.uploadHashFileToDevice(localToDevicePaths).wait();
}).future<void>()();
}

Expand Down
12 changes: 11 additions & 1 deletion lib/services/livesync/android-livesync-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
///<reference path="../../.d.ts"/>
"use strict";

import {AndroidDebugBridge} from "../../common/mobile/android/android-debug-bridge";
import {AndroidDeviceHashService} from "../../common/mobile/android/android-device-hash-service";
import Future = require("fibers/future");
import * as helpers from "../../common/helpers";
import liveSyncServiceBaseLib = require("./livesync-service-base");
Expand All @@ -13,7 +15,9 @@ class AndroidLiveSyncService extends liveSyncServiceBaseLib.LiveSyncServiceBase<
constructor(_device: Mobile.IDevice,
private $fs: IFileSystem,
private $mobileHelper: Mobile.IMobileHelper,
private $options: IOptions) {
private $options: IOptions,
private $injector: IInjector,
private $projectData: IProjectData) {
super(_device);
}

Expand Down Expand Up @@ -56,6 +60,12 @@ class AndroidLiveSyncService extends liveSyncServiceBaseLib.LiveSyncServiceBase<
}).future<void>()();
}

public afterInstallApplicationAction(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
let adb = this.$injector.resolve(AndroidDebugBridge, { identifier: deviceAppData.device.deviceInfo.identifier });
let deviceHashService = this.$injector.resolve(AndroidDeviceHashService, { adb: adb, appIdentifier: this.$projectData.projectId });
return deviceHashService.uploadHashFileToDevice(localToDevicePaths);
}

private getDeviceRootPath(appIdentifier: string): string {
return `/data/local/tmp/${appIdentifier}`;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class PlatformService implements IPlatformService {
}).future<void>()();
}

public buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<string> {
public buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
return (() => {
platform = platform.toLowerCase();
if (!this.preparePlatform(platform).wait()) {
Expand All @@ -321,7 +321,7 @@ export class PlatformService implements IPlatformService {
let platformData = this.$platformsData.getPlatformData(platform);
platformData.platformProjectService.buildForDeploy(platformData.projectRoot, buildConfig).wait();
this.$logger.out("Project successfully built");
}).future<string>()();
}).future<void>()();
}

public copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): IFuture<void> {
Expand Down

0 comments on commit 8d9c319

Please sign in to comment.