-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bfe1198
Showing
39 changed files
with
994 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
/.idea/deploymentTargetDropDown.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Usb Clipboard Type | ||
|
||
## Description | ||
|
||
Emulate a USB keyboard to paste text from the clipboard from your phone to your computer. | ||
|
||
## Requirements | ||
- Rooted Android device | ||
- [USB Gadget Tool](https://github.com/tejado/android-usb-gadget) switched into hid keyboard mode | ||
- On android 10+ you also need clipboard access for background apps enabled via [Riru-ClipboardWhitelist](https://github.com/Kr328/Riru-ClipboardWhitelist) or [xposed-clipboard-whitelist](https://github.com/GamerGirlandCo/xposed-clipboard-whitelist) | ||
|
||
## Usage | ||
Just copy some text to the clipboard and click the Quick Settings tile to paste it on your computer while connected via USB. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'io.github.cloudburst.cliptype' | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
applicationId "io.github.cloudburst.cliptype" | ||
minSdk 24 | ||
targetSdk 34 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
|
||
dependencies { | ||
implementation 'androidx.core:core-ktx:1.12.0' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.10.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
|
||
def libsuVersion = '5.2.1' | ||
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}" | ||
implementation "com.github.topjohnwu.libsu:service:${libsuVersion}" | ||
implementation "com.github.topjohnwu.libsu:nio:${libsuVersion}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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.READ_CLIPBOARD_IN_BACKGROUND" | ||
tools:ignore="ProtectedPermissions" /> | ||
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" | ||
tools:ignore="ProtectedPermissions" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.AppCompat.Light" | ||
tools:targetApi="31"> | ||
<service | ||
android:name=".UsbQSService" | ||
android:enabled="true" | ||
android:exported="true" | ||
android:icon="@drawable/ic_baseline_usb_24" | ||
android:label="@string/usb_qs_label" | ||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> | ||
<intent-filter> | ||
<action android:name="android.service.quicksettings.action.QS_TILE" /> | ||
</intent-filter> | ||
</service> | ||
</application> | ||
|
||
</manifest> |
6 changes: 6 additions & 0 deletions
6
app/src/main/aidl/io/github/cloudburst/cliptype/IUsbRootService.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.github.cloudburst.cliptype; | ||
|
||
interface IUsbRootService { | ||
boolean hidCapable(); | ||
void typeUsb(String text); | ||
} |
112 changes: 112 additions & 0 deletions
112
app/src/main/java/io/github/cloudburst/cliptype/UsbKbdMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package io.github.cloudburst.cliptype | ||
|
||
class UsbKbdMap { | ||
private val kbdVal = mapOf( | ||
null to byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'a' to byteArrayOf(0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'b' to byteArrayOf(0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'c' to byteArrayOf(0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'd' to byteArrayOf(0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'e' to byteArrayOf(0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'f' to byteArrayOf(0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'g' to byteArrayOf(0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'h' to byteArrayOf(0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'i' to byteArrayOf(0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'j' to byteArrayOf(0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'k' to byteArrayOf(0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'l' to byteArrayOf(0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'm' to byteArrayOf(0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'n' to byteArrayOf(0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'o' to byteArrayOf(0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'p' to byteArrayOf(0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'q' to byteArrayOf(0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'r' to byteArrayOf(0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
's' to byteArrayOf(0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
't' to byteArrayOf(0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'u' to byteArrayOf(0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'v' to byteArrayOf(0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'w' to byteArrayOf(0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'x' to byteArrayOf(0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'y' to byteArrayOf(0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'z' to byteArrayOf(0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
|
||
'A' to byteArrayOf(0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'B' to byteArrayOf(0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'C' to byteArrayOf(0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'D' to byteArrayOf(0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'E' to byteArrayOf(0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'F' to byteArrayOf(0x02, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'G' to byteArrayOf(0x02, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'H' to byteArrayOf(0x02, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'I' to byteArrayOf(0x02, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'J' to byteArrayOf(0x02, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'K' to byteArrayOf(0x02, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'L' to byteArrayOf(0x02, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'M' to byteArrayOf(0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'N' to byteArrayOf(0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'O' to byteArrayOf(0x02, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'P' to byteArrayOf(0x02, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'Q' to byteArrayOf(0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'R' to byteArrayOf(0x02, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'S' to byteArrayOf(0x02, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'T' to byteArrayOf(0x02, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'U' to byteArrayOf(0x02, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'V' to byteArrayOf(0x02, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'W' to byteArrayOf(0x02, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'X' to byteArrayOf(0x02, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'Y' to byteArrayOf(0x02, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'Z' to byteArrayOf(0x02, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
|
||
'1' to byteArrayOf(0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'2' to byteArrayOf(0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'3' to byteArrayOf(0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'4' to byteArrayOf(0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'5' to byteArrayOf(0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'6' to byteArrayOf(0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'7' to byteArrayOf(0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'8' to byteArrayOf(0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'9' to byteArrayOf(0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'0' to byteArrayOf(0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
|
||
'!' to byteArrayOf(0x02, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'@' to byteArrayOf(0x02, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'#' to byteArrayOf(0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'$' to byteArrayOf(0x02, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'%' to byteArrayOf(0x02, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'^' to byteArrayOf(0x02, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'&' to byteArrayOf(0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'*' to byteArrayOf(0x02, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'(' to byteArrayOf(0x02, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
')' to byteArrayOf(0x02, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
|
||
' ' to byteArrayOf(0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
|
||
'-' to byteArrayOf(0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'=' to byteArrayOf(0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'[' to byteArrayOf(0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
']' to byteArrayOf(0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'\\' to byteArrayOf(0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
';' to byteArrayOf(0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'"' to byteArrayOf(0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'`' to byteArrayOf(0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
',' to byteArrayOf(0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'.' to byteArrayOf(0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'/' to byteArrayOf(0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
|
||
'_' to byteArrayOf(0x02, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'+' to byteArrayOf(0x02, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'{' to byteArrayOf(0x02, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'}' to byteArrayOf(0x02, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'|' to byteArrayOf(0x02, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
':' to byteArrayOf(0x02, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'\'' to byteArrayOf(0x02, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'~' to byteArrayOf(0x02, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'<' to byteArrayOf(0x02, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'>' to byteArrayOf(0x02, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
'?' to byteArrayOf(0x02, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00), | ||
) | ||
|
||
fun getScancode(key: Char?): ByteArray = | ||
kbdVal[key] ?: kbdVal[null]!! | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/io/github/cloudburst/cliptype/UsbQSService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.github.cloudburst.cliptype | ||
|
||
import android.content.ClipboardManager | ||
import android.content.Intent | ||
import android.os.Build.VERSION | ||
import android.service.quicksettings.TileService | ||
import com.topjohnwu.superuser.ipc.RootService | ||
|
||
class UsbQSService : TileService() { | ||
|
||
private var connection: UsbRootService.Connection? = null | ||
|
||
override fun onClick() { | ||
super.onClick() | ||
|
||
updateDesc(getString(R.string.usb_qs_desc_default)) | ||
|
||
val clipboard = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager | ||
val content = clipboard.primaryClip?.getItemAt(0)?.text ?: return | ||
|
||
val intent = Intent(this, UsbRootService::class.java) | ||
intent.putExtra("text", content) | ||
|
||
createConnection() | ||
|
||
for (i in 1..5) { | ||
if (connection?.binder == null) { | ||
Thread.sleep(100) | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
if (connection?.binder?.hidCapable() == false) { | ||
updateDesc(getString(R.string.usb_qs_desc_hid_unavailable)) | ||
} else { | ||
updateDesc(getString(R.string.usb_qs_desc_default)) | ||
connection?.binder?.typeUsb(content.toString()) | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
connection?.let { | ||
RootService.unbind(it) | ||
connection = null | ||
} | ||
} | ||
|
||
private fun createConnection() { | ||
if (connection != null) return | ||
connection = UsbRootService.Connection() | ||
val intent = Intent(this, UsbRootService::class.java) | ||
RootService.bind(intent, connection!!) | ||
} | ||
|
||
private fun updateDesc(desc: String) { | ||
qsTile.contentDescription = desc | ||
if (VERSION.SDK_INT >= 29) | ||
qsTile.subtitle = desc | ||
qsTile.updateTile() | ||
} | ||
} |
Oops, something went wrong.