Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky committed Jul 3, 2022
0 parents commit 9042c9d
Show file tree
Hide file tree
Showing 61 changed files with 1,962 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .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
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Privacy Policy

The app has nothing to store, but settings.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# USBKill

USB connection trigger.

[comment]: <> ([<img )

[comment]: <> ( src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png")

[comment]: <> ( alt="Get it on F-Droid")

[comment]: <> ( height="80">]&#40;https://f-droid.org/packages/me.lucky.usbkill/&#41;)

[comment]: <> ([<img )

[comment]: <> ( src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png" )

[comment]: <> ( alt="Get it on Google Play" )

[comment]: <> ( height="80">]&#40;https://play.google.com/store/apps/details?id=me.lucky.usbkill&#41;)

<img
src="https://raw.githubusercontent.com/x13a/USBKill/main/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png"
width="30%"
height="30%">

Tiny app to listen for USB connection events **while the device is locked**.
When found, it will send a broadcast message.

## Wasted

* action: `me.lucky.wasted.action.TRIGGER`
* receiver: `me.lucky.wasted/.TriggerReceiver`
* authentication code: the code from Wasted

Do not forget to activate the `Broadcast` trigger in Wasted.

## Permissions

* FOREGROUND_SERVICE - receive usb state events
* RECEIVE_BOOT_COMPLETED - persist service across reboots

## License
[![GNU GPLv3 Image](https://www.gnu.org/graphics/gplv3-127x51.png)](https://www.gnu.org/licenses/gpl-3.0.en.html)

This application is Free Software: You can use, study share and improve it at your will.
Specifically you can redistribute and/or modify it under the terms of the
[GNU General Public License v3](https://www.gnu.org/licenses/gpl.html) as published by the Free
Software Foundation.
12 changes: 12 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Security Policy

## Supported Versions

| Version | Supported |
| ------- | ------------------ |
| 1.0.x | :white_check_mark: |
| < 1.0 | :x: |

## Reporting a Vulnerability

Contact: [email protected]
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/release
50 changes: 50 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 32

defaultConfig {
applicationId "me.lucky.usbkill"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0.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'
}

buildFeatures {
viewBinding true
}
lint {
disable 'MissingTranslation'
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation 'androidx.security:security-crypto:1.0.0'
}
21 changes: 21 additions & 0 deletions 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,24 @@
package me.lucky.usbkill

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

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

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("me.lucky.usbkill", appContext.packageName)
}
}
62 changes: 62 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="me.lucky.usbkill">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
<uses-feature android:name="android.hardware.usb.accessory" android:required="false" />

<application
android:allowBackup="false"
android:fullBackupContent="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".Application"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.USBKill"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".ForegroundService"
android:exported="false">
</service>

<receiver
android:name=".UsbReceiver"
android:enabled="false"
android:exported="true">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</receiver>

<receiver
android:name=".RestartReceiver"
android:enabled="false"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>

</application>
</manifest>
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/src/main/java/me/lucky/usbkill/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.lucky.usbkill

import android.app.Application
import com.google.android.material.color.DynamicColors

class Application : Application() {
override fun onCreate() {
super.onCreate()
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
71 changes: 71 additions & 0 deletions app/src/main/java/me/lucky/usbkill/ForegroundService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package me.lucky.usbkill

import android.app.KeyguardManager
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.IBinder
import androidx.core.app.NotificationCompat

class ForegroundService : Service() {
companion object {
private const val NOTIFICATION_ID = 1001
private const val ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE"
}

private val usbStateReceiver = UsbStateReceiver()

override fun onCreate() {
super.onCreate()
init()
}

override fun onDestroy() {
super.onDestroy()
deinit()
}

private fun init() {
registerReceiver(usbStateReceiver, IntentFilter(ACTION_USB_STATE))
}

private fun deinit() {
unregisterReceiver(usbStateReceiver)
}

override fun onBind(intent: Intent?): IBinder? {
return null
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
startForeground(
NOTIFICATION_ID,
NotificationCompat.Builder(this, NotificationManager.CHANNEL_DEFAULT_ID)
.setContentTitle(getString(R.string.service_notification_title))
.setSmallIcon(android.R.drawable.ic_delete)
.setPriority(NotificationCompat.PRIORITY_LOW)
.build()
)
return START_STICKY
}

private class UsbStateReceiver : BroadcastReceiver() {
companion object {
private const val KEY_1 = "connected"
private const val KEY_2 = "host_connected"
}

override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action != ACTION_USB_STATE) return
val prefs = Preferences(context ?: return)
if (!prefs.isEnabled ||
!context.getSystemService(KeyguardManager::class.java).isDeviceLocked) return
val extras = intent.extras ?: return
if (!extras.getBoolean(KEY_1) && !extras.getBoolean(KEY_2)) return
Utils(context).sendBroadcast(prefs)
}
}
}
Loading

0 comments on commit 9042c9d

Please sign in to comment.