Skip to content

Commit

Permalink
clean up function that gets the selinux categories of my app
Browse files Browse the repository at this point in the history
By this I mean that I replaced the auto-generated Java->Kotlin conversion
code with proper Kotlin functions.

I also removed the TODO, because if ':' is not found, it'll return -1.
-1 + 1 = 0. foo.substring(0) is just foo. so line 87 would catch that
  • Loading branch information
Arian04 committed Aug 13, 2024
1 parent fcd4c31 commit b23b0db
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ class CharacterDeviceManager private constructor(private val application: Applic
// Get selinux context for app
val commandResult = Shell.cmd("stat -c %C $appDataDirPath").exec()

// Get the part of the context that I need (categories) by grabbing everything after the last ':'
val contextFromCommand = java.lang.String.join("\n", commandResult.out)
val contextFromCommand = commandResult.out.joinToString(separator = "\n").trim()
var categories = contextFromCommand

// TODO: handle the case that stdout doesn't include any ':' (idk why that would even happen tho)
// Get the part of the context that I need (categories) by grabbing everything after the last ':'
categories = categories.substring(categories.lastIndexOf(':') + 1)
categories = categories.trim { it <= ' ' } // trim whitespace

Timber.d("context (before,after): (%s,%s)", contextFromCommand, categories)

// If it hasn't changed, then the previous piece of code failed to get the substring
Expand Down

0 comments on commit b23b0db

Please sign in to comment.