Git Product home page Git Product logo

hugorosario / transmission-android Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 17.09 MB

Transmission daemon ported to Android.

License: Other

CMake 0.46% Makefile 13.49% Shell 5.72% C 52.72% M4 1.57% Batchfile 0.11% D 0.18% Perl 11.91% DTrace 0.01% Roff 4.45% C++ 2.21% HTML 0.24% Visual Basic 0.04% Awk 0.01% DIGITAL Command Language 0.58% Python 2.36% Perl 6 0.02% sed 0.01% Objective-C 2.92% Assembly 1.00%
bittorrent-client transmission-daemon android

transmission-android's Introduction

ABOUT

  Transmission is a fast, easy, and free BitTorrent client.
  Visit https://transmissionbt.com/ for more information.
  
  This repository is an Android port of the transmission daemon version 2.94.
  Modifications have been made to the source code of transmission and dependency 
  libraries in order to make this compile without errors.
  
  It provides a nice interactive build script and supports cross compiling to ARM and X86 android.

BUILDING
  
  Download and extract the latest Android NDK from https://developer.android.com/ndk/downloads/
  I already had revision 17c and it worked fine.
  
  Clone this repository.
  
  $ git clone https://github.com/hugorosario/transmission-android.git
  
  Edit the "build.sh" script inside the "builder" folder and set your NDK_ROOT directory to where you extracted it.
  For example, export NDK_ROOT=/home/dev/android-ndk
  
  Run the interactive build script.
  $ ./build.sh
  
  Select architecture (ARM or X86) to build the toolchain. 
  Select "Build all (dependencies + transmission)".
  
  If everything went good, you should have a transmission-daemon binary in your toolchain sysroot/usr/bin folder.

RUNNING
  
  Since this is a binary executable and not an APK, it needs to be launched from JAVA code.
  This means you need to build and APK to start/stop the daemon.
  
  In order to execute the daemon, you have to copy it to the app private space and make it executable.
  This is required because Android does not allow launching executables located on the SD card. 
  Here is some code that extracts the binary from the RAW folder into getFilesDir() location 
  and makes it executable:
  
  static boolean initialize(Context context) {
      try {
          initialized = false;
          String appFileDirectory = context.getFilesDir().getParent();
          binary = new File(appFileDirectory + "/transmissiond");
          extractResource(context, R.raw.transmission_x86, binary);
          if (binary.exists())
              initialized = binary.setExecutable(true);
      } catch (Exception e) {
          e.printStackTrace();
      }
      return initialized;
  }

  static void extractResource(Context context, int id, File dest){
      try {
          InputStream ins = context.getResources().openRawResource(id);
          final byte[] buffer = new byte[ins.available()];
          ins.read(buffer);
          ins.close();
          if (dest.exists())
              dest.delete();
          FileOutputStream fos = new FileOutputStream(dest);
          fos.write(buffer);
          fos.close();
      }catch (Exception e){
          e.printStackTrace();
      }
  }
  
  Here is some code that might help launching the daemon (many parameters are missing from this sample code):
  
  public static void startDaemon(final TransmissionListener listener){
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                if (isInitialized()){
                    process = new ProcessBuilder().command(binary.getAbsolutePath(),"-f").redirectErrorStream(true).start();
                    listener.onStatusUpdated(false, "transmission-daemon started!");
                    Thread readThread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                                while (!Thread.currentThread().isInterrupted()) {
                                    if (bufferedReader.ready()) {
                                        String line = bufferedReader.readLine();
                                        listener.onLog(line);
                                    }
                                }
                                bufferedReader.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    readThread.start();
                    Thread errorThread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                                while (!Thread.currentThread().isInterrupted()) {
                                    if (bufferedReader.ready()) {
                                        String line = bufferedReader.readLine();
                                        listener.onError(line);
                                    }
                                }
                                bufferedReader.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    errorThread.start();
                    process.waitFor();
                    readThread.interrupt();
                    errorThread.interrupt();
                    process = null;
                    listener.onStatusUpdated(false, "transmission-daemon stopped!");
                }
            } catch (Exception e) {
                e.printStackTrace();
                listener.onStatusUpdated(false, "FATAL ERROR : " + e.getMessage());
            }
        }
    }).start();
}

  
  
TODO
  I will soon add a sample APK that starts/stops the daemon and has a nice helper class for transmission settings.

transmission-android's People

Contributors

hugorosario avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.