Skip to content

Commit f64527d

Browse files
authored
Merge pull request #51 from Sj-Si/chore/message-log
[CHORE] Update logging for `automation_library` MessageLog changes.
2 parents 0a85f96 + 19e09be commit f64527d

File tree

12 files changed

+566
-583
lines changed

12 files changed

+566
-583
lines changed

android/app/src/main/java/com/steve1316/uma_android_automation/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import com.steve1316.automation_library.utils.ScreenStateReceiver
1818
import org.opencv.android.OpenCVLoader
1919
import java.util.Locale
2020

21-
2221
class MainActivity : ReactActivity() {
2322
companion object {
2423
const val loggerTag: String = "UAA"

android/app/src/main/java/com/steve1316/uma_android_automation/StartModule.kt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import androidx.core.net.toUri
3434
* Loaded into the React PackageList via MainApplication's instantiation of the StartPackage.
3535
*/
3636
class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), ActivityEventListener {
37-
private val tag = "[${MainActivity.loggerTag}]StartModule"
37+
private val TAG = "[${MainActivity.loggerTag}]StartModule"
3838

3939
companion object {
4040
private var reactContext: ReactApplicationContext? = null
@@ -47,7 +47,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
4747
init {
4848
StartModule.reactContext = reactContext
4949
StartModule.reactContext?.addActivityEventListener(this)
50-
Log.d(tag, "StartModule is now initialized.")
50+
Log.d(TAG, "StartModule is now initialized.")
5151
}
5252

5353
override fun getName(): String {
@@ -65,7 +65,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
6565
MediaProjectionService.getStartIntent(reactContext!!, resultCode, data!!)
6666
)
6767
sendEvent("MediaProjectionService", "Running")
68-
Log.d(tag, "MediaProjectionService is now running.")
68+
Log.d(TAG, "MediaProjectionService is now running.")
6969
}
7070
}
7171

@@ -92,7 +92,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
9292
// unregister in stopProjection().
9393
EventBus.getDefault().unregister(this)
9494
EventBus.getDefault().register(this)
95-
Log.d(tag, "Event Bus registered for StartModule")
95+
Log.d(TAG, "Event Bus registered for StartModule")
9696
val mediaProjectionManager = reactContext?.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
9797
reactContext?.startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), 100, null)
9898
}
@@ -102,7 +102,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
102102
*/
103103
private fun stopProjection() {
104104
EventBus.getDefault().unregister(this)
105-
Log.d(tag, "Event Bus unregistered for StartModule")
105+
Log.d(TAG, "Event Bus unregistered for StartModule")
106106
reactContext?.startService(MediaProjectionService.getStopIntent(reactContext!!))
107107
sendEvent("MediaProjectionService", "Not Running")
108108
}
@@ -135,7 +135,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
135135
*/
136136
private fun checkForOverlayPermission(): Boolean {
137137
if (!Settings.canDrawOverlays(this.reactApplicationContext.currentActivity)) {
138-
Log.d(tag, "Application is missing overlay permission.")
138+
Log.d(TAG, "Application is missing overlay permission.")
139139

140140
val builder = AlertDialog.Builder(this.reactApplicationContext.currentActivity)
141141
builder.setTitle(R.string.overlay_disabled)
@@ -154,7 +154,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
154154
return false
155155
}
156156

157-
Log.d(tag, "Application has permission to draw overlay.")
157+
Log.d(TAG, "Application has permission to draw overlay.")
158158
return true
159159
}
160160

@@ -171,7 +171,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
171171
val enabled = prefString.contains(reactContext?.packageName.toString() + "/" + MyAccessibilityService::class.java.name)
172172

173173
if (enabled) {
174-
Log.d(tag, "This application's Accessibility Service is currently turned on.")
174+
Log.d(TAG, "This application's Accessibility Service is currently turned on.")
175175
return true
176176
}
177177
}
@@ -219,48 +219,48 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
219219
fun onStartEvent(event: StartEvent) {
220220
if (event.message == "Entry Point ON") {
221221
// Initialize SQLite settings with detailed debugging.
222-
Log.d(tag, "Starting SQLite settings initialization...")
222+
Log.d(TAG, "Starting SQLite settings initialization...")
223223

224224
// Check if the database file exists before attempting to initialize.
225225
val dbFile = java.io.File(context.filesDir, "SQLite/settings.db")
226-
Log.d(tag, "Database file path: ${dbFile.absolutePath}")
227-
Log.d(tag, "Database file exists: ${dbFile.exists()}")
228-
Log.d(tag, "Database file can read: ${dbFile.canRead()}")
229-
Log.d(tag, "Database file size: ${if (dbFile.exists()) dbFile.length() else "N/A"} bytes")
226+
Log.d(TAG, "Database file path: ${dbFile.absolutePath}")
227+
Log.d(TAG, "Database file exists: ${dbFile.exists()}")
228+
Log.d(TAG, "Database file can read: ${dbFile.canRead()}")
229+
Log.d(TAG, "Database file size: ${if (dbFile.exists()) dbFile.length() else "N/A"} bytes")
230230

231231
// List the contents of the files directory to see what's actually there.
232232
val filesDir = context.filesDir
233-
Log.d(tag, "Files directory: ${filesDir.absolutePath}")
233+
Log.d(TAG, "Files directory: ${filesDir.absolutePath}")
234234
val files = filesDir.listFiles()
235235
if (files != null) {
236-
Log.d(tag, "Files in files directory:")
236+
Log.d(TAG, "Files in files directory:")
237237
for (file in files) {
238-
Log.d(tag, " - ${file.name} (${if (file.isDirectory) "dir" else "file"})")
238+
Log.d(TAG, " - ${file.name} (${if (file.isDirectory) "dir" else "file"})")
239239
}
240240
}
241241

242242
// Check if SQLite subdirectory exists.
243243
val sqliteDir = java.io.File(context.filesDir, "SQLite")
244-
Log.d(tag, "SQLite directory exists: ${sqliteDir.exists()}")
244+
Log.d(TAG, "SQLite directory exists: ${sqliteDir.exists()}")
245245
if (sqliteDir.exists()) {
246246
val sqliteFiles = sqliteDir.listFiles()
247247
if (sqliteFiles != null) {
248-
Log.d(tag, "Files in SQLite directory:")
248+
Log.d(TAG, "Files in SQLite directory:")
249249
for (file in sqliteFiles) {
250-
Log.d(tag, " - ${file.name} (${file.length()} bytes)")
250+
Log.d(TAG, " - ${file.name} (${file.length()} bytes)")
251251
}
252252
}
253253
}
254254

255255
// Check if database is available before attempting to initialize.
256256
val settingsManager = SQLiteSettingsManager(context)
257-
Log.d(tag, "Database is available: ${settingsManager.isDatabaseAvailable()}")
257+
Log.d(TAG, "Database is available: ${settingsManager.isDatabaseAvailable()}")
258258

259259
SettingsHelper.initialize(context)
260260
if (SettingsHelper.isAvailable()) {
261-
Log.d(tag, "SQLite settings initialized successfully.")
261+
Log.d(TAG, "SQLite settings initialized successfully.")
262262
} else {
263-
Log.w(tag, "Failed to initialize SQLite settings, continuing with defaults.")
263+
Log.w(TAG, "Failed to initialize SQLite settings, continuing with defaults.")
264264
}
265265

266266
val entryPoint = Game(context)
@@ -285,7 +285,7 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
285285
params.putInt("id", messageId++)
286286
if (emitter == null) {
287287
// Register the event emitter to send messages to JS.
288-
Log.d(tag, "Event emitter not found to be able to send messages to the frontend. Registering now.")
288+
Log.d(TAG, "Event emitter not found to be able to send messages to the frontend. Registering now.")
289289
emitter = reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
290290
}
291291

@@ -309,11 +309,11 @@ class StartModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
309309
*/
310310
@Subscribe
311311
fun onSubscriberExceptionEvent(event: SubscriberExceptionEvent) {
312-
Log.e(tag, "Received exception event to send: ${event.throwable}")
313-
MessageLog.printToLog(event.throwable.toString(), MainActivity.loggerTag, isWarning = false, isError = true, skipPrintTime = false)
312+
Log.e(TAG, "Received exception event to send: ${event.throwable}")
313+
MessageLog.e(MainActivity.loggerTag, event.throwable.toString())
314314
for (line in event.throwable.stackTrace) {
315-
MessageLog.printToLog("\t${line}", MainActivity.loggerTag, isWarning = false, isError = true, skipPrintTime = true)
315+
MessageLog.e(MainActivity.loggerTag, "\t${line}", skipPrintTime = true)
316316
}
317-
MessageLog.printToLog("", MainActivity.loggerTag, isWarning = false, isError = false, skipPrintTime = true)
317+
MessageLog.d(MainActivity.loggerTag, "", skipPrintTime = true)
318318
}
319319
}

android/app/src/main/java/com/steve1316/uma_android_automation/bot/Campaign.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package com.steve1316.uma_android_automation.bot
22

33
import com.steve1316.uma_android_automation.MainActivity
44
import com.steve1316.uma_android_automation.utils.SettingsHelper
5+
import com.steve1316.automation_library.utils.MessageLog
56

67
/**
78
* Base campaign class that contains all shared logic for campaign automation.
89
* Campaign-specific logic should be implemented in subclasses by overriding the appropriate methods.
910
* By default, URA Finale is handled by this base class.
1011
*/
1112
open class Campaign(val game: Game) {
12-
protected val tag: String = "[${MainActivity.Companion.loggerTag}]Normal"
13+
protected open val TAG: String = "[${MainActivity.Companion.loggerTag}]Normal"
1314

1415
val mustRestBeforeSummer: Boolean = SettingsHelper.getBooleanSetting("training", "mustRestBeforeSummer")
1516

@@ -52,19 +53,19 @@ open class Campaign(val game: Game) {
5253

5354
// If the required skill points has been reached, stop the bot.
5455
if (game.enableSkillPointCheck && game.imageUtils.determineSkillPoints() >= game.skillPointsRequired) {
55-
game.printToLog("\n[END] Bot has acquired the set amount of skill points. Exiting now...", tag = tag)
56+
MessageLog.i(TAG, "\n[END] Bot has acquired the set amount of skill points. Exiting now...")
5657
game.notificationMessage = "Bot has acquired the set amount of skill points."
5758
break
5859
}
5960

6061
// If force racing is enabled, skip all other activities and go straight to racing
6162
if (game.racing.enableForceRacing) {
62-
game.printToLog("[INFO] Force racing enabled - skipping all other activities and going straight to racing.", tag = tag)
63+
MessageLog.i(TAG, "Force racing enabled - skipping all other activities and going straight to racing.")
6364
needToRace = true
6465
} else {
6566
// Check if we need to rest before Summer Training (June Early/Late in Classic/Senior Year).
6667
if (mustRestBeforeSummer && (game.currentDate.year == 2 || game.currentDate.year == 3) && game.currentDate.month == 6 && game.currentDate.phase == "Late") {
67-
game.printToLog("[INFO] Forcing rest during June ${game.currentDate.phase} in Year ${game.currentDate.year} in preparation for Summer Training.", tag = tag)
68+
MessageLog.i(TAG, "Forcing rest during June ${game.currentDate.phase} in Year ${game.currentDate.year} in preparation for Summer Training.")
6869
game.recoverEnergy()
6970
game.racing.skipRacing = false
7071
} else if (game.checkInjury() && !game.checkFinals()) {
@@ -74,21 +75,21 @@ open class Campaign(val game: Game) {
7475
} else if (game.recoverMood() && !game.checkFinals()) {
7576
game.racing.skipRacing = false
7677
} else if (game.currentDate.turnNumber >= 16 && !game.racing.checkEligibilityToStartExtraRacingProcess()) {
77-
game.printToLog("[INFO] Training due to it not being an extra race day.", tag = tag)
78+
MessageLog.i(TAG, "[INFO] Training due to it not being an extra race day.")
7879
game.training.handleTraining()
7980
game.racing.skipRacing = false
8081
} else {
81-
game.printToLog("[INFO] Bot has no injuries, mood is sufficient and extra races can be run today. Setting the needToRace flag to true.", tag = tag)
82+
MessageLog.i(TAG, "[INFO] Bot has no injuries, mood is sufficient and extra races can be run today. Setting the needToRace flag to true.")
8283
needToRace = true
8384
}
8485
}
8586
}
8687

8788
if (game.racing.encounteredRacingPopup || needToRace) {
88-
game.printToLog("[INFO] All checks are cleared for racing.", tag = tag)
89+
MessageLog.i(TAG, "[INFO] All checks are cleared for racing.")
8990
if (!handleRaceEvents()) {
9091
if (game.racing.detectedMandatoryRaceCheck) {
91-
game.printToLog("\n[END] Stopping bot due to detection of Mandatory Race.", tag = tag)
92+
MessageLog.i(TAG, "\n[END] Stopping bot due to detection of Mandatory Race.")
9293
game.notificationMessage = "Stopping bot due to detection of Mandatory Race."
9394
break
9495
}
@@ -108,7 +109,7 @@ open class Campaign(val game: Game) {
108109
} else if (game.checkMandatoryRacePrepScreen()) {
109110
// If the bot is at the Main screen with the button to select a race visible, that means the bot needs to handle a mandatory race.
110111
if (!handleRaceEvents() && game.racing.detectedMandatoryRaceCheck) {
111-
game.printToLog("\n[END] Stopping bot due to detection of Mandatory Race.", tag = tag)
112+
MessageLog.i(TAG, "\n[END] Stopping bot due to detection of Mandatory Race.")
112113
game.notificationMessage = "Stopping bot due to detection of Mandatory Race."
113114
break
114115
}
@@ -118,15 +119,15 @@ open class Campaign(val game: Game) {
118119
game.racing.skipRacing = false
119120
} else if (game.checkEndScreen()) {
120121
// Stop when the bot has reached the screen where it details the overall result of the run.
121-
game.printToLog("\n[END] Bot has reached the end of the run. Exiting now...", tag = tag)
122+
MessageLog.i(TAG, "\n[END] Bot has reached the end of the run. Exiting now...")
122123
game.notificationMessage = "Bot has reached the end of the run"
123124
break
124125
} else if (checkCampaignSpecificConditions()) {
125-
game.printToLog("[INFO] Campaign-specific checks complete.", tag = tag)
126+
MessageLog.i(TAG, "Campaign-specific checks complete.")
126127
game.racing.skipRacing = false
127128
continue
128129
} else {
129-
game.printToLog("[INFO] Did not detect the bot being at the following screens: Main, Training Event, Inheritance, Mandatory Race Preparation, Racing and Career End.", tag = tag)
130+
MessageLog.i(TAG, "Did not detect the bot being at the following screens: Main, Training Event, Inheritance, Mandatory Race Preparation, Racing and Career End.")
130131
}
131132

132133
// Various miscellaneous checks

0 commit comments

Comments
 (0)