@@ -28,6 +28,7 @@ import com.google.gson.reflect.TypeToken
28
28
import com.legendsayantan.adbtools.adapters.DebloatAdapter
29
29
import com.legendsayantan.adbtools.adapters.SimpleAdapter
30
30
import com.legendsayantan.adbtools.data.AppData
31
+ import com.legendsayantan.adbtools.lib.Logger.Companion.log
31
32
import com.legendsayantan.adbtools.lib.ShizukuRunner
32
33
import com.legendsayantan.adbtools.lib.Utils.Companion.extractUrls
33
34
import com.legendsayantan.adbtools.lib.Utils.Companion.getAllInstalledApps
@@ -78,6 +79,9 @@ class DebloatActivity : AppCompatActivity() {
78
79
ShizukuRunner .command(" pm grant $packageName android.permission.QUERY_ALL_PACKAGES" ,
79
80
object : ShizukuRunner .CommandResultListener {
80
81
override fun onCommandResult (output : String , done : Boolean ) {}
82
+ override fun onCommandError (error : String ) {
83
+ applicationContext.log(error)
84
+ }
81
85
})
82
86
val setListListener = {
83
87
list.setOnItemClickListener { _, _, position, _ ->
@@ -96,44 +100,66 @@ class DebloatActivity : AppCompatActivity() {
96
100
startActivity(Intent (Intent .ACTION_VIEW , Uri .parse(listOfLinks[linkPosition])))
97
101
}
98
102
val disableBtn = MaterialButton (this )
99
- ShizukuRunner .command(" pm list packages -d" ,object : ShizukuRunner .CommandResultListener {
100
- override fun onCommandResult (output : String , done : Boolean ) {
101
- if (done){
102
- val isDisabled = output.contains(id)
103
- disableBtn.text = if (isDisabled) getString(R .string.confirm_to_enable) else getString(R .string.confirm_to_disable)
104
- disableBtn.setOnClickListener {
105
- // disable app
106
- ShizukuRunner .command(" cmd package ${if (isDisabled)" enable" else " disable" } -k --user 0 $id " ,
107
- object : ShizukuRunner .CommandResultListener {
108
- override fun onCommandResult (output : String , done : Boolean ) {
109
- if (done) {
110
- runOnUiThread {
111
- if (output.contains(" Success" , true )) {
112
- list.adapter =
113
- DebloatAdapter (this @DebloatActivity, apps)
114
- Toast .makeText(
115
- applicationContext,
116
- " Success for ${app.name} " ,
117
- Toast .LENGTH_LONG
118
- ).show()
119
- } else {
120
- Toast .makeText(
121
- applicationContext,
122
- " Failed,\n $output " ,
123
- Toast .LENGTH_LONG
124
- ).show()
103
+ ShizukuRunner .command(" pm list packages -d" ,
104
+ object : ShizukuRunner .CommandResultListener {
105
+ override fun onCommandResult (output : String , done : Boolean ) {
106
+ if (done) {
107
+ val isDisabled = output.contains(id)
108
+ disableBtn.text =
109
+ if (isDisabled) getString(R .string.confirm_to_enable) else getString(
110
+ R .string.confirm_to_disable
111
+ )
112
+ disableBtn.setOnClickListener {
113
+ // disable app
114
+ ShizukuRunner .command(" cmd package ${if (isDisabled) " enable" else " disable" } -k --user 0 $id " ,
115
+ object : ShizukuRunner .CommandResultListener {
116
+ override fun onCommandResult (
117
+ output : String ,
118
+ done : Boolean
119
+ ) {
120
+ if (done) {
121
+ runOnUiThread {
122
+ if (output.contains(" Success" , true )) {
123
+ list.adapter =
124
+ DebloatAdapter (
125
+ this @DebloatActivity,
126
+ apps
127
+ )
128
+ Toast .makeText(
129
+ applicationContext,
130
+ " Success for ${app.name} " ,
131
+ Toast .LENGTH_LONG
132
+ ).show()
133
+ } else {
134
+ Toast .makeText(
135
+ applicationContext,
136
+ " Failed,\n $output " ,
137
+ Toast .LENGTH_LONG
138
+ ).show()
139
+ applicationContext.log(output)
140
+ }
141
+ dialog?.dismiss()
125
142
}
126
- dialog?.dismiss()
127
143
}
128
144
}
129
- }
130
- })
145
+
146
+ override fun onCommandError (error : String ) {
147
+ applicationContext.log(error)
148
+ }
149
+ })
150
+ }
131
151
}
132
152
}
133
- }
134
- })
135
- disableBtn.layoutParams = LinearLayout .LayoutParams (LinearLayout .LayoutParams .WRAP_CONTENT , LinearLayout .LayoutParams .WRAP_CONTENT ).apply {
136
- setMargins(0 ,0 ,25 ,0 )
153
+
154
+ override fun onCommandError (error : String ) {
155
+ applicationContext.log(error)
156
+ }
157
+ })
158
+ disableBtn.layoutParams = LinearLayout .LayoutParams (
159
+ LinearLayout .LayoutParams .WRAP_CONTENT ,
160
+ LinearLayout .LayoutParams .WRAP_CONTENT
161
+ ).apply {
162
+ setMargins(0 , 0 , 25 , 0 )
137
163
}
138
164
val uninstallBtn = MaterialButton (this )
139
165
uninstallBtn.text = getString(R .string.confirm_to_uninstall)
@@ -161,11 +187,16 @@ class DebloatActivity : AppCompatActivity() {
161
187
" Failed to uninstall ${app.name} ,\n $output " ,
162
188
Toast .LENGTH_LONG
163
189
).show()
190
+ applicationContext.log(output)
164
191
}
165
192
dialog?.dismiss()
166
193
}
167
194
}
168
195
}
196
+
197
+ override fun onCommandError (error : String ) {
198
+ applicationContext.log(error)
199
+ }
169
200
})
170
201
}
171
202
val btnContainer = LinearLayout (this )
@@ -270,6 +301,8 @@ class DebloatActivity : AppCompatActivity() {
270
301
}
271
302
}
272
303
} catch (e: Exception ) {
304
+ applicationContext.log(e.stackTraceToString(), true )
305
+
273
306
if (database.isNullOrBlank()) {
274
307
onFailure()
275
308
} else {
@@ -339,14 +372,14 @@ class DebloatActivity : AppCompatActivity() {
339
372
.show()
340
373
}
341
374
342
- fun restoreMode () {
375
+ private fun restoreMode () {
343
376
val activityContext = this
344
377
ShizukuRunner .command(" cmd package list packages -u" ,
345
378
object : ShizukuRunner .CommandResultListener {
346
379
override fun onCommandResult (output : String , done : Boolean ) {
347
380
if (done) {
348
381
val allApps = output.replace(" package:" , " " ).split(" \n " )
349
- loadApps { installed ->
382
+ loadApps( { installed ->
350
383
val uninstalled = allApps.filter { ! installed.contains(it) }
351
384
runOnUiThread {
352
385
val appsView = RecyclerView (activityContext)
@@ -379,18 +412,32 @@ class DebloatActivity : AppCompatActivity() {
379
412
}
380
413
}
381
414
}
415
+ override fun onCommandError (error : String ) {
416
+ applicationContext.log(error)
417
+ }
382
418
})
383
419
dialog.dismiss()
384
420
}
385
421
}
386
422
387
- }
423
+ }, {
424
+ runOnUiThread {
425
+ Toast .makeText(
426
+ activityContext,
427
+ " Error loading apps : $it " ,
428
+ Toast .LENGTH_LONG
429
+ ).show()
430
+ }
431
+ })
388
432
}
389
433
}
434
+ override fun onCommandError (error : String ) {
435
+ applicationContext.log(error)
436
+ }
390
437
})
391
438
}
392
439
393
- companion object {
440
+ companion object {
394
441
const val FILENAME_DATABASE : String = " debloat-list.json"
395
442
}
396
443
}
0 commit comments