Skip to content

Commit 923b780

Browse files
authored
Merge pull request #14 from bakad3v/dev1
code comments update
2 parents 5552a00 + 6bff761 commit 923b780

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

features/triggerReceivers/src/main/java/com/sonozaki/triggerreceivers/services/TriggerReceiverService.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class TriggerReceiverService : AccessibilityService() {
154154
keyguardManager = getSystemService(KeyguardManager::class.java)
155155
}
156156

157+
/**
158+
* Listen for power button clicks
159+
* @return callback for stopping listening to power button clicks
160+
*/
157161
private fun listenForButtonClicksRoot(superUser: SuperUser): () -> Unit {
158162
return superUser.getPowerButtonClicks {
159163
if (!it) return@getPowerButtonClicks
@@ -171,7 +175,9 @@ class TriggerReceiverService : AccessibilityService() {
171175
}
172176
}
173177

174-
178+
/**
179+
* resets the counter of incorrect password attempts and prevents rebooting if user unlocked
180+
*/
175181
private fun listenScreenUnlocked() {
176182
val screenUnlockedFilter = IntentFilter(Intent.ACTION_USER_PRESENT)
177183
val screenUnlockedReceiver = object : BroadcastReceiver() {
@@ -211,12 +217,19 @@ class TriggerReceiverService : AccessibilityService() {
211217
}
212218
}
213219

220+
/**
221+
* Disable multiuser UI on device boot if needed
222+
*/
214223
private suspend fun protectMultiuserUI() {
215224
if (getDeviceProtectionSettings().multiuserUIProtection == MultiuserUIProtection.ON_REBOOT) {
216225
disableMultiuserUI()
217226
}
218227
}
219228

229+
/**
230+
* When screen turns on|off, app can enqueue rebooting (to move device to BFU), hide multiuser UI
231+
* or use screen state changes as proxy for power button clicks (deprecated)
232+
*/
220233
private suspend fun handleScreenStateChanged(action: String) {
221234
val deprecatedButton = getButtonSettingsUseCase().triggerOnButton == PowerButtonTriggerOptions.DEPRECATED_WAY
222235
if (deprecatedButton && buttonClicksUseCase(ButtonClicked.POWER_BUTTON)) {
@@ -355,6 +368,9 @@ class TriggerReceiverService : AccessibilityService() {
355368
}
356369
}
357370

371+
/**
372+
* Trigger when password entered by user changes
373+
*/
358374
private fun updatePassword(text: String) {
359375
val ignoreChars = text.count { it == IGNORE_CHAR }
360376
if (ignoreChars == 0 && text.length != 1) {
@@ -396,6 +412,9 @@ class TriggerReceiverService : AccessibilityService() {
396412
return text.compareTo(baseContext.getString(rId), true) == 0
397413
}
398414

415+
/**
416+
* Check if user entered wrong password without admin privileges. May not work on some devices
417+
*/
399418
private fun watchWrongPassword(text: String) {
400419
coroutineScope.launch(dispatcher) {
401420
if (checkBruteforceDetectionMethod()
@@ -409,6 +428,9 @@ class TriggerReceiverService : AccessibilityService() {
409428
}
410429
}
411430

431+
/**
432+
* Trigger on volume buttons clicks
433+
*/
412434
override fun onKeyEvent(event: KeyEvent?): Boolean {
413435
if (event?.action == ACTION_DOWN) {
414436
val buttonClicked = if (event.keyCode == KEYCODE_VOLUME_UP) {

superuser/src/main/java/com/sonozaki/superuser/root/Root.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Root @Inject constructor(
3939
if (isShellChecked) {
4040
return
4141
}
42+
//su may become inaccessible if persist.sys.safemode == 1 even when booting to safe mode is prohibited
4243
try {
4344
Runtime.getRuntime().exec("su")
4445
} catch (e: IOException) {

superuser/src/main/java/com/sonozaki/superuser/superuser/SuperUser.kt

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.topjohnwu.superuser.Shell
44
import okio.BufferedSource
55

66
/**
7-
* Superuser interface. There are three types of superusers: device admin, device owner (provided by Dhizuku) and root. Root user is the most privileged one, and device admin is the least privileged.
7+
* Superuser interface. There are three types of superusers: device admin, Dshizuku (chooses between Shizuku and Dhizuku) and root. Root user is the most privileged one, and device admin is the least privileged.
88
*/
99
interface SuperUser {
1010
/**
@@ -18,7 +18,7 @@ interface SuperUser {
1818
/**
1919
* Get list of all user profiles.
2020
*
21-
* Requirements: device owner or root. Device owner requires Android 9 and above to get profiles and can't retrieve profiles names.
21+
* Requirements: shizuku, dhizuku or root. Dhizuku requires Android 9 and above to get profiles and can't retrieve profiles names.
2222
* @return list of profiles
2323
*/
2424
@Throws(SuperUserException::class)
@@ -27,7 +27,7 @@ interface SuperUser {
2727
/**
2828
* Remove specified user profile.
2929
*
30-
* Requirements: device owner or root.
30+
* Requirements: dhizuku or root.
3131
* @param id id of profile to remove
3232
*/
3333
@Throws(SuperUserException::class)
@@ -36,7 +36,7 @@ interface SuperUser {
3636
/**
3737
* Uninstall app with specified packageName. App leave numerous traces in android system even after uninstallation, it's recommended to clear app's data instead of deletion.
3838
*
39-
* Requirements: device owner or root. **Android can show notification if app was deleted using Dhizuku, making work of application obvious to adversary.**
39+
* Requirements: root or shizuku.
4040
* @param packageName name of package to uninstall
4141
*/
4242
@Throws(SuperUserException::class)
@@ -45,7 +45,7 @@ interface SuperUser {
4545
/**
4646
* Hide app with specified packageName.
4747
*
48-
* Requirements: device owner or root. The function can work with bugs if hiding apps is done using Dhizuku.
48+
* Requirements: dhizuku or root. The function can work with bugs if hiding apps is done using Dhizuku.
4949
* @param packageName name of package to hide.
5050
*/
5151
@Throws(SuperUserException::class)
@@ -54,7 +54,7 @@ interface SuperUser {
5454
/**
5555
* Clear data of app with specified packageName.
5656
*
57-
* Requirements: device owner or root. Device owner requires Android 9 or higher.
57+
* Requirements: dhizuku or root. Dhizuku requires Android 9 or higher.
5858
* @param packageName name of package to clear.
5959
*/
6060
@Throws(SuperUserException::class)
@@ -63,7 +63,7 @@ interface SuperUser {
6363
/**
6464
* Run [TRIM](https://en.wikipedia.org/wiki/Trim_(computing)) command to mark unused blocks for clearing. Use it to reduce the likelihood of deleted data recovery.
6565
*
66-
* Requirements: root.
66+
* Requirements: root or shizuku.
6767
*/
6868
@Throws(SuperUserException::class)
6969
suspend fun runTrim()
@@ -85,6 +85,11 @@ interface SuperUser {
8585
@Throws(SuperUserException::class)
8686
suspend fun stopLogd()
8787

88+
/**
89+
* Call callback when power button clicked
90+
* @return callback to stop listening to power button
91+
* Requires: root
92+
*/
8893
fun getPowerButtonClicks(callback: (Boolean) -> Unit): () -> Unit
8994

9095
/**
@@ -124,11 +129,11 @@ interface SuperUser {
124129
suspend fun getUserLimit(): Int?
125130

126131
/**
127-
* Enable or disable safe boot. For unknown reason there may be problems with enabling safe boot if it was disabled.
132+
* Enable or disable safe boot.
128133
*
129-
* Adversary may use safe boot to circumvent device protection offered by the app. However, disabling safe boot may raise suspicions. Try to make Android Antiforensics Tools a system app instead.
134+
* Adversary may use safe boot to circumvent device protection offered by the app.
130135
*
131-
* Requirements: device owner or root.
136+
* Requirements: dhizuku or shizuku or root.
132137
* @param status enable or disable safe boot.
133138
*/
134139
@Throws(SuperUserException::class)
@@ -137,7 +142,7 @@ interface SuperUser {
137142
/**
138143
* Get status of safe boot.
139144
*
140-
* Requirements: device owner or root.
145+
* Requirements: dhizuku or shizuku or root.
141146
* @return is safe boot enabled or disabled.
142147
*/
143148
@Throws(SuperUserException::class)
@@ -146,7 +151,7 @@ interface SuperUser {
146151
/**
147152
* Enable or disable UI for switching between users. May be helpful if this UI is disabled or, in contrast, can't be disabled in android settings. It's recommended to disable UI for switching between users every time you don't need it, because adversary may use it to get list of your profiles from lockscreen.
148153
*
149-
* Requirements: root, Android 10+.
154+
* Requirements: root or shizuku, Android 10+.
150155
* @param status enable or disable user switcher UI.
151156
*/
152157
@Throws(SuperUserException::class)
@@ -155,7 +160,7 @@ interface SuperUser {
155160
/**
156161
* Get status of UI for switching between users
157162
*
158-
* Requirements: root, Android 10+.
163+
* Requirements: root or shizuku, Android 10+.
159164
* @return is UI for switching between users enabled or disabled.
160165
*/
161166
@Throws(SuperUserException::class)
@@ -164,7 +169,7 @@ interface SuperUser {
164169
/**
165170
* Enable or disable switching between users and corresponding UI. May be helpful if this UI is disabled or, in contrast, can't be disabled in android settings. It's recommended to disable UI for switching between users every time you don't need it, because adversary may use it to get list of your profiles from lockscreen.
166171
*
167-
* Requirements: root, Android 9+.
172+
* Requirements: root or dhizuku, Android 9+.
168173
* @param status allow or prohibit switching between users.
169174
*/
170175
@Throws(SuperUserException::class)
@@ -173,42 +178,72 @@ interface SuperUser {
173178
/**
174179
* Get status of switching between users
175180
*
176-
* Requirements: root, Android 9+.
181+
* Requirements: root or dhizuku, Android 9+.
177182
* @return is switching between users enabled or disabled.
178183
*/
179184
@Throws(SuperUserException::class)
180185
suspend fun getSwitchUserRestriction(): Boolean
181186

182187
/**
183188
* Reboot device
189+
* Requirements: root or shizuku or dhizuku
184190
*/
185191
@Throws(SuperUserException::class)
186192
suspend fun reboot()
187193

188194
/**
189195
* Logout specified user. Moves user to SHUTDOWN state, evicts encryption keys. Can't be called for primary user.
196+
* Requirements: root or shizuku or dhizuku with Android 9 or higher
190197
*/
191198
@Throws(SuperUserException::class)
192199
suspend fun stopProfile(userId: Int, isCurrent: Boolean): Boolean
193200

201+
/**
202+
* Install application with testOnly flag.
203+
* Requirements: root
204+
*/
194205
@Throws(SuperUserException::class)
195206
suspend fun installTestOnlyApp(length: Long, data: BufferedSource): Boolean
196207

208+
/**
209+
* Disables or enables logs
210+
* Requirements: root or shizuku
211+
*/
197212
@Throws(SuperUserException::class)
198213
suspend fun changeLogsStatus(enable: Boolean)
199214

215+
/**
216+
* Disables or enables developer options
217+
* Requirements: root or shizuku
218+
*/
200219
@Throws(SuperUserException::class)
201220
suspend fun changeDeveloperSettingsStatus(unlock: Boolean)
202221

222+
/**
223+
* Check if logs are enabled
224+
* Requirements: root or shizuku
225+
*/
203226
@Throws(SuperUserException::class)
204227
suspend fun getLogsStatus(): Boolean
205228

229+
/**
230+
* Check if developer options are enabled
231+
* Requirements: root or shizuku
232+
*/
206233
@Throws(SuperUserException::class)
207234
suspend fun getDeveloperSettingsStatus(): Boolean
208235

236+
/**
237+
* Log in specified user profile
238+
* Requirements: root or shizuku or dhizuku
239+
*/
209240
@Throws(SuperUserException::class)
210241
suspend fun openProfile(userId: Int)
211242

243+
/**
244+
* Remove notification for specified package name with specified id
245+
* Requirements: root
246+
*/
212247
@Throws(SuperUserException::class)
213248
suspend fun removeNotification(packageName: String, id: Int)
214249
}

0 commit comments

Comments
 (0)