Search in sources :

Example 1 with InstantRunClient

use of com.android.tools.fd.client.InstantRunClient in project android by JetBrains.

the class HotSwapTask method perform.

@Override
public boolean perform(@NotNull final IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
    InstantRunManager manager = InstantRunManager.get(myProject);
    UpdateMode updateMode = null;
    try {
        InstantRunClient instantRunClient = InstantRunManager.getInstantRunClient(myInstantRunContext);
        if (instantRunClient == null) {
            return terminateLaunch(launchStatus, "Unable to connect to application. Press Run or Debug to rebuild and install the app.");
        }
        updateMode = manager.pushArtifacts(device, myInstantRunContext, myRestartActivity ? UpdateMode.WARM_SWAP : UpdateMode.HOT_SWAP);
        printer.stdout("Hot swapped changes, activity " + (updateMode == UpdateMode.HOT_SWAP ? "not restarted" : "restarted"));
    } catch (InstantRunPushFailedException | IOException e) {
        return terminateLaunch(launchStatus, "Error installing hot swap patches: " + e);
    }
    InstantRunStatsService.get(myProject).notifyDeployType(DeployType.HOTSWAP, myInstantRunContext, device);
    return true;
}
Also used : InstantRunClient(com.android.tools.fd.client.InstantRunClient) UpdateMode(com.android.tools.fd.client.UpdateMode) InstantRunPushFailedException(com.android.tools.fd.client.InstantRunPushFailedException) IOException(java.io.IOException)

Example 2 with InstantRunClient

use of com.android.tools.fd.client.InstantRunClient in project android by JetBrains.

the class RestartActivityAction method showToast.

private static void showToast(@NotNull IDevice device, @NotNull InstantRunContext context, @NotNull final String message) {
    try {
        InstantRunClient instantRunClient = InstantRunManager.getInstantRunClient(context);
        if (instantRunClient == null) {
            InstantRunManager.LOG.warn("Cannot connect to app, not showing toast");
            return;
        }
        instantRunClient.showToast(device, message);
    } catch (Throwable e) {
        InstantRunManager.LOG.warn(e);
    }
}
Also used : InstantRunClient(com.android.tools.fd.client.InstantRunClient)

Example 3 with InstantRunClient

use of com.android.tools.fd.client.InstantRunClient in project android by JetBrains.

the class InstantRunManager method pushArtifacts.

/**
   * Pushes the artifacts obtained from the {@link InstantRunContext} to the given device.
   * If the app is running, the artifacts are sent directly to the server running as part of the app.
   * Otherwise, we save it to a file on the device.
   */
public UpdateMode pushArtifacts(@NotNull IDevice device, @NotNull InstantRunContext context, @NotNull UpdateMode updateMode) throws InstantRunPushFailedException, IOException {
    InstantRunClient client = getInstantRunClient(context);
    assert client != null;
    InstantRunBuildInfo instantRunBuildInfo = context.getInstantRunBuildInfo();
    assert instantRunBuildInfo != null;
    updateMode = client.pushPatches(device, instantRunBuildInfo, updateMode, InstantRunSettings.isRestartActivity(), InstantRunSettings.isShowToastEnabled());
    if ((updateMode == UpdateMode.HOT_SWAP || updateMode == UpdateMode.WARM_SWAP)) {
        refreshDebugger(context.getApplicationId());
    }
    return updateMode;
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo) InstantRunClient(com.android.tools.fd.client.InstantRunClient)

Aggregations

InstantRunClient (com.android.tools.fd.client.InstantRunClient)3 InstantRunBuildInfo (com.android.tools.fd.client.InstantRunBuildInfo)1 InstantRunPushFailedException (com.android.tools.fd.client.InstantRunPushFailedException)1 UpdateMode (com.android.tools.fd.client.UpdateMode)1 IOException (java.io.IOException)1