Skip to content

Commit 9f16487

Browse files
authored
Merge branch 'tytydraco:main' into main
2 parents d4d8ff1 + 0cf9417 commit 9f16487

File tree

6 files changed

+60
-11
lines changed

6 files changed

+60
-11
lines changed

app/build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ android {
3737

3838
dependencies {
3939
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
40-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
40+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1-native-mt'
4141

42-
implementation 'androidx.core:core-ktx:1.5.0'
43-
implementation 'androidx.appcompat:appcompat:1.3.0'
42+
implementation 'androidx.core:core-ktx:1.6.0'
43+
implementation 'androidx.appcompat:appcompat:1.3.1'
4444
implementation 'androidx.preference:preference-ktx:1.1.1'
45-
implementation 'androidx.activity:activity-ktx:1.2.4'
45+
implementation 'androidx.fragment:fragment-ktx:1.3.6'
4646
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
4747
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
4848
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
4949

50-
implementation 'com.google.android.material:material:1.3.0'
50+
implementation 'com.github.javiersantos:PiracyChecker:1.2.8'
51+
52+
implementation 'com.google.android.material:material:1.4.0'
5153
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
5254
}

app/src/main/java/com/draco/ladb/viewmodels/MainActivityViewModel.kt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.draco.ladb.viewmodels
22

3+
import android.app.Activity
34
import android.app.Application
5+
import android.content.Context
46
import android.content.Intent
57
import android.content.SharedPreferences
68
import android.net.Uri
@@ -10,20 +12,31 @@ import androidx.lifecycle.AndroidViewModel
1012
import androidx.lifecycle.LiveData
1113
import androidx.lifecycle.MutableLiveData
1214
import androidx.lifecycle.viewModelScope
15+
import com.draco.ladb.BuildConfig
1316
import com.draco.ladb.R
1417
import com.draco.ladb.utils.ADB
18+
import com.github.javiersantos.piracychecker.PiracyChecker
19+
import com.github.javiersantos.piracychecker.piracyChecker
1520
import kotlinx.coroutines.Dispatchers
1621
import kotlinx.coroutines.isActive
1722
import kotlinx.coroutines.launch
1823
import java.io.File
1924

2025
class MainActivityViewModel(application: Application) : AndroidViewModel(application) {
21-
private val context = getApplication<Application>().applicationContext
22-
2326
private val _outputText = MutableLiveData<String>()
2427
val outputText: LiveData<String> = _outputText
2528

26-
val adb = ADB.getInstance(context).also {
29+
var checker: PiracyChecker? = null
30+
private val sharedPreferences = application
31+
.applicationContext
32+
.getSharedPreferences(
33+
application
34+
.applicationContext
35+
.getString(R.string.pref_file),
36+
Context.MODE_PRIVATE
37+
)
38+
39+
val adb = ADB.getInstance(getApplication<Application>().applicationContext).also {
2740
viewModelScope.launch(Dispatchers.IO) {
2841
it.initializeClient()
2942
}
@@ -33,6 +46,30 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
3346
startOutputThread()
3447
}
3548

49+
/**
50+
* Start the piracy checker if it is not setup yet (release builds only)
51+
*
52+
* @param activity Activity to use when showing the error
53+
*/
54+
fun piracyCheck(activity: Activity) {
55+
if (checker != null || BuildConfig.DEBUG)
56+
return
57+
58+
val context = getApplication<Application>().applicationContext
59+
60+
checker = activity.piracyChecker {
61+
enableGooglePlayLicensing("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRTOoEZ/IFfA/JkBFIrZqLq7N66JtJFTn/5C2QMO2EIY6hG4yZ5YTA3JrbJuuGVzQE8j29s6Lwu+19KKZcITTkZjfgl2Zku8dWQKZFt46f7mh8s1spzzc6rmSWIBPZUxN6fIIz8ar+wzyZdu3z+Iiy31dUa11Pyh82oOsWH7514AYGeIDDlvB1vSfNF/9ycEqTv5UAOgHxqZ205C1VVydJyCEwWWVJtQ+Z5zRaocI6NGaYRopyZteCEdKkBsZ69vohk4zr2SpllM5+PKb1yM7zfsiFZZanp4JWDJ3jRjEHC4s66elWG45yQi+KvWRDR25MPXhdQ9+DMfF2Ao1NTrgQIDAQAB")
62+
saveResultToSharedPreferences(
63+
sharedPreferences,
64+
context.getString(R.string.pref_key_verified)
65+
)
66+
}
67+
68+
val verified = sharedPreferences.getBoolean(context.getString(R.string.pref_key_verified), false)
69+
if (!verified)
70+
checker?.start()
71+
}
72+
3673
/**
3774
* Continuously update shell output
3875
*/
@@ -59,6 +96,8 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
5996
* Check if the user should be prompted to pair
6097
*/
6198
fun shouldWePair(sharedPreferences: SharedPreferences): Boolean {
99+
val context = getApplication<Application>().applicationContext
100+
62101
if (!sharedPreferences.getBoolean(context.getString(R.string.paired_key), false)) {
63102
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
64103
return true
@@ -71,6 +110,8 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
71110
* Return the contents of the script from the intent
72111
*/
73112
fun getScriptFromIntent(intent: Intent): String? {
113+
val context = getApplication<Application>().applicationContext
114+
74115
return when (intent.type) {
75116
"text/x-sh" -> {
76117
val uri = Uri.parse(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM).toString())

app/src/main/java/com/draco/ladb/views/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class MainActivity : AppCompatActivity() {
128128
}
129129
}
130130
}
131+
132+
viewModel.piracyCheck(this)
131133
}
132134

133135
/**

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@
7575
<string name="licenses_title">Licenses</string>
7676
<string name="licenses_summary">View the open source licenses</string>
7777
<string name="licenses_key">licenses</string>
78+
79+
<string name="pref_file" translatable="false">preferences</string>
80+
<string name="pref_key_verified" translatable="false">verified</string>
7881
</resources>

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.5.0"
3+
ext.kotlin_version = "1.5.20"
44
repositories {
55
google()
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:7.0.0-beta03'
9+
classpath 'com.android.tools.build:gradle:7.0.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.4'
1212

@@ -19,6 +19,7 @@ allprojects {
1919
repositories {
2020
google()
2121
mavenCentral()
22+
maven { url 'https://jitpack.io' }
2223
}
2324
}
2425

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Sat Mar 06 16:41:44 PST 2021
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)