1
1
package com.draco.ladb.viewmodels
2
2
3
+ import android.app.Activity
3
4
import android.app.Application
5
+ import android.content.Context
4
6
import android.content.Intent
5
7
import android.content.SharedPreferences
6
8
import android.net.Uri
@@ -10,20 +12,31 @@ import androidx.lifecycle.AndroidViewModel
10
12
import androidx.lifecycle.LiveData
11
13
import androidx.lifecycle.MutableLiveData
12
14
import androidx.lifecycle.viewModelScope
15
+ import com.draco.ladb.BuildConfig
13
16
import com.draco.ladb.R
14
17
import com.draco.ladb.utils.ADB
18
+ import com.github.javiersantos.piracychecker.PiracyChecker
19
+ import com.github.javiersantos.piracychecker.piracyChecker
15
20
import kotlinx.coroutines.Dispatchers
16
21
import kotlinx.coroutines.isActive
17
22
import kotlinx.coroutines.launch
18
23
import java.io.File
19
24
20
25
class MainActivityViewModel (application : Application ) : AndroidViewModel(application) {
21
- private val context = getApplication<Application >().applicationContext
22
-
23
26
private val _outputText = MutableLiveData <String >()
24
27
val outputText: LiveData <String > = _outputText
25
28
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 {
27
40
viewModelScope.launch(Dispatchers .IO ) {
28
41
it.initializeClient()
29
42
}
@@ -33,6 +46,30 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
33
46
startOutputThread()
34
47
}
35
48
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
+
36
73
/* *
37
74
* Continuously update shell output
38
75
*/
@@ -59,6 +96,8 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
59
96
* Check if the user should be prompted to pair
60
97
*/
61
98
fun shouldWePair (sharedPreferences : SharedPreferences ): Boolean {
99
+ val context = getApplication<Application >().applicationContext
100
+
62
101
if (! sharedPreferences.getBoolean(context.getString(R .string.paired_key), false )) {
63
102
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R )
64
103
return true
@@ -71,6 +110,8 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
71
110
* Return the contents of the script from the intent
72
111
*/
73
112
fun getScriptFromIntent (intent : Intent ): String? {
113
+ val context = getApplication<Application >().applicationContext
114
+
74
115
return when (intent.type) {
75
116
" text/x-sh" -> {
76
117
val uri = Uri .parse(intent.getParcelableExtra<Parcelable >(Intent .EXTRA_STREAM ).toString())
0 commit comments