Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weixiansen574 committed Mar 26, 2024
1 parent 99626ac commit 4ea0de2
Show file tree
Hide file tree
Showing 168 changed files with 6,236 additions and 1 deletion.
15 changes: 15 additions & 0 deletions HybridFileXfer-Android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions HybridFileXfer-Android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions HybridFileXfer-Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
plugins {
id 'com.android.application'
}

android {
namespace 'top.weixiansen574.hybridfilexfer'
compileSdk 34

defaultConfig {
applicationId "top.weixiansen574.hybridfilexfer"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding true
buildConfig = true
aidl = true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "dev.rikka.shizuku:api:13.1.5"
}
Binary file added HybridFileXfer-Android/app/debug/app-debug.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions HybridFileXfer-Android/app/debug/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "top.weixiansen574.hybridfilexfer",
"variantName": "debug",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0_1711385041641",
"outputFile": "app-debug.apk"
}
],
"elementType": "File"
}
21 changes: 21 additions & 0 deletions HybridFileXfer-Android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package top.weixiansen574.hybridfilexfer;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("top.weixiansen574.hybirdfilexfer", appContext.getPackageName());
}
}
45 changes: 45 additions & 0 deletions HybridFileXfer-Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/logo"
android:label="@string/app_name"

android:supportsRtl="true"
android:theme="@style/Theme.HybridFileXfer"
tools:targetApi="31">
<activity
android:name=".TransferActivity"
android:theme="@style/Theme.HybridFileXfer.NoActionBar"
android:exported="false" />

<service
android:name=".TransferServices"
android:process=":TransferService"
android:enabled="true"/>

<activity
android:name=".MainActivity"
android:theme="@style/Theme.HybridFileXfer"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ITransferService.aidl
package top.weixiansen574.hybridfilexfer;

// Declare any non-default types here with import statements

interface ITransferService {
void destroy() = 16777114; // Destroy method defined by Shizuku server

void exit() = 1; // Exit method defined by user

top.weixiansen574.hybridfilexfer.droidcore.Error startServer() = 2;
void stopServer() = 3;
void waitingForDied() = 4;
void stopGetNextEvent() = 5;

void transferToPc(in List<String> files,String localDir,String remoteDir) = 101;
void transferToMe(in List<String> files, String remoteDir, String localDir) = 102;
List<top.weixiansen574.hybridfilexfer.droidcore.ParcelableRemoteFile> listClientFiles(String path) = 100;
top.weixiansen574.hybridfilexfer.droidcore.ParcelableFileTransferEvent getNextFileTransferEvent() = 110;
top.weixiansen574.hybridfilexfer.droidcore.ParcelableTransferredBytesInfo getTransferredBytesInfo() = 111;

List<top.weixiansen574.hybridfilexfer.droidcore.ParcelableRemoteFile> listLocalFiles(String path) = 200;
top.weixiansen574.hybridfilexfer.droidcore.ParcelableRemoteFile getParentFile(String path) = 201;




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ParcelableFileTransferEvent.aidl
package top.weixiansen574.hybridfilexfer.droidcore;
// Declare any non-default types here with import statements

parcelable Error;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ParcelableFileTransferEvent.aidl
package top.weixiansen574.hybridfilexfer.droidcore;
// Declare any non-default types here with import statements

parcelable ParcelableFileTransferEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// ParcelableRemoteFile.aidl
package top.weixiansen574.hybridfilexfer.droidcore;

// Declare any non-default types here with import statements

parcelable ParcelableRemoteFile;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ParcelableFileTransferEvent.aidl
package top.weixiansen574.hybridfilexfer.droidcore;
// Declare any non-default types here with import statements

parcelable ParcelableTransferredBytesInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package top.weixiansen574.async;

public abstract class BackstageTask<T extends EventHandler> implements Runnable{
private final T handle;
public BackstageTask(T handle){
this.handle = handle;
}

@Override
public void run(){
try {
onStart(handle);
} catch (Throwable e) {
handle.sendError(e);
}
}
public void execute(){TaskManger.execute(this);}
protected abstract void onStart(T eventHandler) throws Throwable;
protected void sleep(long time){
try {
Thread.sleep(time);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package top.weixiansen574.async;

import android.os.Handler;
import android.os.Looper;

import androidx.annotation.NonNull;

public abstract class EventHandler extends Handler {
public EventHandler() {
super();
}

public EventHandler(@NonNull Looper looper) {
super(looper);
}

public void sendEventMessage(EventMessage message) {
post(() -> handleEvent(message));
}

public void sendEventMessage(int what,Object... objects){
post(() -> handleEvent(new EventMessage(what,objects)));
}

public void sendEmptyEventMessage(int what){
post(() -> handleEvent(new EventMessage(what)));
}

public void sendError(Throwable th) {
post(() -> handleError(th));
}

protected abstract void handleEvent(EventMessage message);

protected abstract void handleError(Throwable th);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package top.weixiansen574.async;

public class EventMessage {
private final int what;
private final Object[] objects;
public EventMessage(Object[] objects,int what){
this.what = what;
this.objects = objects;
}
public EventMessage(int what,Object... objects){
this.what = what;
this.objects = objects;
}

public EventMessage(int what){
this.what = what;
this.objects = new Object[0];
}

public <T> T getObject(int index,Class<T> clazz){
return clazz.cast(objects[index]);
}

public int getWhat() {
return what;
}

public Object[] getObjects(){
return objects;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package top.weixiansen574.async;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TaskManger {
private static volatile Handler mainThreadHandler;
private static Handler getUiThreadHandler() {
if (mainThreadHandler == null) {
synchronized (TaskManger.class) {
if (mainThreadHandler == null) {
mainThreadHandler = new Handler(Looper.getMainLooper());
}
}
}
return mainThreadHandler;
}



public static void postOnUiThread(Runnable runnable) {
getUiThreadHandler().post(runnable);
}
private static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
public static void start(Runnable runnable){
executorService.execute(runnable);
}
public static void execute(BackstageTask<?> backstageTask){
start(backstageTask);
}
}
Loading

0 comments on commit 4ea0de2

Please sign in to comment.