Skip to content

Commit

Permalink
feature_app_demo_boot_laces (#1)
Browse files Browse the repository at this point in the history
* add bootlaces to demo app.

* add hasOverlay function to library.
  • Loading branch information
evilthreads669966 authored Oct 5, 2020
1 parent 37d5dce commit db3886c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {
2. Add the dependency to your app's build.gradle file
```gradle
dependencies {
implementation 'com.github.evilthreads669966:jackhammer:0.1'
implementation 'com.github.evilthreads669966:jackhammer:0.2'
}
```
3. Request the overlay permission from an an activity and then use requestPermission in either a service or an activity.
Expand Down
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "com.evilthreads.jackhammer"
minSdkVersion 16
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
Expand All @@ -30,9 +30,11 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation project(":jackhammerlib")
implementation 'com.github.evilthreads669966:bootlaces:1.0'
implementation "androidx.lifecycle:lifecycle-service:2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation project(":jackhammerlib")
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyService" android:directBootAware="true"/>
</application>

</manifest>
26 changes: 7 additions & 19 deletions app/src/main/java/com/evilthreads/jackhammer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
package com.evilthreads.jackhammer

import android.Manifest
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.candroid.bootlaces.bootService
import com.evilthreads.jackhammerlib.checkOverlayPermission
import com.evilthreads.jackhammerlib.requestpermission

class MainActivity : AppCompatActivity() {

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
bruteForce()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
bruteForce()
bootService(this){
service = MyService::class
}
}

fun bruteForce(){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(checkOverlayPermission())
requestpermission(Manifest.permission.READ_CALENDAR){
Log.d("JACKJAMMER", "WE DID IT")
}
}
override fun onResume() {
super.onResume()
checkOverlayPermission()
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/evilthreads/jackhammer/MyService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.evilthreads.jackhammer

import android.Manifest
import android.os.Build
import android.util.Log
import androidx.lifecycle.lifecycleScope
import com.candroid.bootlaces.BootService
import com.evilthreads.jackhammerlib.hasOverlayPermission
import com.evilthreads.jackhammerlib.requestpermission
import kotlinx.coroutines.delay

class MyService: BootService(){
init {
lifecycleScope.launchWhenCreated {
while(!hasOverlayPermission())
delay(1000)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
requestpermission(Manifest.permission.READ_CALENDAR){
Log.d("JACKJAMMER", "EVIL THREADS")
}
else
Log.d("JACKJAMMER", "EVIL THREADS")
}
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,18 @@ fun Context.requestpermission(permission: String, payload: () -> Unit){
/*this method checks whether you have overlay settings enabled for you app and if you don't it brings up the overlay settings screen.*/
fun Activity.checkOverlayPermission(): Boolean {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
if (!Settings.canDrawOverlays(this)) {
if (!hasOverlayPermission()) {
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:${this.packageName}"))
this.startActivityForResult(intent, 666)
return false
}
}
return true
}

/*check whether overlay is enabled*/
fun Context.hasOverlayPermission(): Boolean{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
return Settings.canDrawOverlays(this)
return true
}

0 comments on commit db3886c

Please sign in to comment.