Search in sources :

Example 1 with CommandExecutor

use of com.taobao.android.builder.tools.command.CommandExecutor in project atlas by alibaba.

the class AwoInstaller method notifyApppatching.

/**
     * todo how know which app will be debugged?
     * just support taobao.apk now
     */
private static void notifyApppatching(AndroidBuilder androidBuilder, String patchPkg, Logger logger) {
    CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
    executor.setLogger(logger);
    executor.setCaptureStdOut(true);
    executor.setCaptureStdErr(true);
    //        List<String> killCmd = Arrays.asList("shell", "am", "force-stop", packageNameForPatch);
    //        List<String> startCmd = Arrays.asList("shell", "am", "start", packageNameForPatch + "/" + launcherActivityForPatch);
    List<String> patchCmd = Arrays.asList("shell", "am", "broadcast", "-a", "com.taobao.atlas.intent.PATCH_APP", "-e", "pkg", patchPkg);
    try {
        executor.executeCommand(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), patchCmd, false);
    } catch (Exception e) {
        throw new RuntimeException("error while restarting app,you can also restart by yourself", e);
    }
}
Also used : CommandExecutor(com.taobao.android.builder.tools.command.CommandExecutor) ExecutionException(com.taobao.android.builder.tools.command.ExecutionException)

Example 2 with CommandExecutor

use of com.taobao.android.builder.tools.command.CommandExecutor in project atlas by alibaba.

the class AwoInstaller method installPatchIfDeviceConnected.

/**
     * no device or too many device make install fail
     *
     * @param patch
     * @return
     */
private static boolean installPatchIfDeviceConnected(AndroidBuilder androidBuilder, File patch, String patchPkg, Logger logger) {
    final AndroidDebugBridge androidDebugBridge = initAndroidDebugBridge(androidBuilder);
    if (!androidDebugBridge.isConnected()) {
        throw new RuntimeException("Android Debug Bridge is not connected.");
    }
    waitForInitialDeviceList(androidDebugBridge, logger);
    List<IDevice> devices = Arrays.asList(androidDebugBridge.getDevices());
    String PATCH_INSTALL_DIRECTORY = String.format("%s%s%s", PATCH_INSTALL_DIRECTORY_PREFIX, patchPkg, PATCH_INSTALL_DIRECTORY_SUFFIX);
    if (devices.size() == 0) {
        throw new RuntimeException(String.format("%s%s%s%s%s", "no device connected,please check whether the connection is successful or copy ", patch, " in build/outputs/awbs/libxxx.so ", PATCH_INSTALL_DIRECTORY, " and restart you app"));
    }
    if (devices.size() > 1) {
        throw new RuntimeException("too much devices be connected,please disconnect the others and try again");
    }
    CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
    executor.setLogger(logger);
    executor.setCaptureStdOut(true);
    executor.setCaptureStdErr(true);
    List<String> cmd = Arrays.asList("push", patch.getAbsolutePath(), PATCH_INSTALL_DIRECTORY + patch.getName());
    try {
        executor.executeCommand(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), cmd, false);
        return true;
    } catch (ExecutionException e) {
        throw new RuntimeException("Error while trying to push patch to device ", e);
    } finally {
        String errout = executor.getStandardError();
        if ((errout != null) && (errout.trim().length() > 0)) {
            logger.error(errout);
        }
    }
}
Also used : CommandExecutor(com.taobao.android.builder.tools.command.CommandExecutor) IDevice(com.android.ddmlib.IDevice) ExecutionException(com.taobao.android.builder.tools.command.ExecutionException) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Aggregations

CommandExecutor (com.taobao.android.builder.tools.command.CommandExecutor)2 ExecutionException (com.taobao.android.builder.tools.command.ExecutionException)2 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1 IDevice (com.android.ddmlib.IDevice)1