Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standalone: Log output to logcat #62

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Andrew Gunnerson
* SPDX-FileCopyrightText: 2023-2024 Andrew Gunnerson
* SPDX-License-Identifier: GPL-3.0-only
* Based on BCR code.
*/
Expand All @@ -8,7 +8,9 @@

package com.chiller3.custota.standalone

import android.util.Log
import com.chiller3.custota.BuildConfig
import java.lang.invoke.MethodHandles
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.ExperimentalPathApi
Expand All @@ -18,15 +20,17 @@ import kotlin.io.path.readBytes
import kotlin.io.path.walk
import kotlin.system.exitProcess

private val TAG = MethodHandles.lookup().lookupClass().simpleName

private val PACKAGE_CACHE_DIR = Paths.get("/data/system/package_cache")

private var dryRun = false

private fun delete(path: Path) {
if (dryRun) {
println("Would have deleted: $path")
Log.i(TAG, "Would have deleted: $path")
} else {
println("Deleting: $path")
Log.i(TAG, "Deleting: $path")
path.deleteIfExists()
}
}
Expand Down Expand Up @@ -74,7 +78,7 @@ private fun clearPackageManagerCache(appId: String): Boolean {
delete(path)
}
} catch (e: Exception) {
e.printStackTrace()
Log.w(TAG, "Failed to delete $path", e)
ret = false
}
}
Expand All @@ -94,8 +98,7 @@ fun main(args: Array<String>) {
try {
mainInternal()
} catch (e: Exception) {
System.err.println("Failed to clear caches")
e.printStackTrace()
Log.e(TAG, "Failed to clear caches", e)
exitProcess(1)
}
}