This commit is contained in:
@@ -21,7 +21,6 @@ android {
|
||||
defaultConfig {
|
||||
applicationId = "com.kain344.firefly_go_android"
|
||||
minSdk = 24
|
||||
//noinspection OldTargetApi
|
||||
targetSdk = 35
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
BIN
app/libs/firefly-go.aar
LFS
BIN
app/libs/firefly-go.aar
LFS
Binary file not shown.
@@ -2,12 +2,20 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"
|
||||
tools:ignore="ForegroundServicesPolicy" />
|
||||
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"
|
||||
tools:ignore="RequestInstallPackagesPolicy" />
|
||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -20,6 +28,7 @@
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:theme="@style/Theme.FireflyGoAndroid"
|
||||
tools:targetApi="31">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
@@ -32,9 +41,12 @@
|
||||
|
||||
<service
|
||||
android:name=".GolangServerService"
|
||||
android:foregroundServiceType="dataSync"
|
||||
android:exported="false" />
|
||||
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:exported="false">
|
||||
<property
|
||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||
android:value="Running local Golang TCP/UDP Server" />
|
||||
</service>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"leader": 3,
|
||||
"leader": 0,
|
||||
"lineups": {
|
||||
"0": 1217,
|
||||
"1": 1307,
|
||||
"2": 1005,
|
||||
"3": 1410
|
||||
"0": 1308,
|
||||
"1": 1406,
|
||||
"2": 1218,
|
||||
"3": 1304
|
||||
},
|
||||
"position": {
|
||||
"x": -30,
|
||||
"z": -22750,
|
||||
"y": -15000,
|
||||
"rot_y": 234288
|
||||
"x": -4030,
|
||||
"z": -13006,
|
||||
"y": 0,
|
||||
"rot_y": 270000
|
||||
},
|
||||
"scene": {
|
||||
"plane_id": 10000,
|
||||
"floor_id": 10000003,
|
||||
"entry_id": 100000352
|
||||
"floor_id": 10000000,
|
||||
"entry_id": 100000104
|
||||
},
|
||||
"player_outfit": [
|
||||
1003
|
||||
@@ -48,7 +48,7 @@
|
||||
"second_lineup": []
|
||||
},
|
||||
"challenge_peak": {
|
||||
"current_mode": "Knight",
|
||||
"current_mode": "Boss",
|
||||
"group_id": 6,
|
||||
"is_in_challenge_peak": false,
|
||||
"challenge_peak_data": {
|
||||
@@ -15189,7 +15189,7 @@
|
||||
"owner_uid": 0,
|
||||
"avatar_id": 8009,
|
||||
"data": {
|
||||
"rank": 0,
|
||||
"rank": 6,
|
||||
"skills": {
|
||||
"8009001": 6,
|
||||
"8009002": 10,
|
||||
@@ -15295,43 +15295,33 @@
|
||||
}
|
||||
},
|
||||
"battle_config": {
|
||||
"battle_type": "CE",
|
||||
"blessings": [],
|
||||
"battle_type": "MOC",
|
||||
"blessings": [
|
||||
{
|
||||
"level": 1,
|
||||
"id": 3030145
|
||||
}
|
||||
],
|
||||
"custom_stats": [],
|
||||
"cycle_count": 30,
|
||||
"stage_id": 0,
|
||||
"stage_id": 30122121,
|
||||
"path_resonance_id": 0,
|
||||
"monsters": [
|
||||
[
|
||||
{
|
||||
"monster_id": 101302009,
|
||||
"monster_id": 4053010,
|
||||
"level": 95,
|
||||
"amount": 1
|
||||
},
|
||||
{
|
||||
"monster_id": 101302009,
|
||||
"level": 95,
|
||||
"amount": 1
|
||||
},
|
||||
{
|
||||
"monster_id": 101302009,
|
||||
"monster_id": 4033020,
|
||||
"level": 95,
|
||||
"amount": 1
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"monster_id": 101302009,
|
||||
"level": 95,
|
||||
"amount": 1
|
||||
},
|
||||
{
|
||||
"monster_id": 101302009,
|
||||
"level": 95,
|
||||
"amount": 1
|
||||
},
|
||||
{
|
||||
"monster_id": 101302009,
|
||||
"monster_id": 3024030,
|
||||
"level": 95,
|
||||
"amount": 1
|
||||
}
|
||||
@@ -6,6 +6,13 @@
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14358961_e055a63b3c34_b199a0234548b5",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14374543_04d971175704_ab00cb3f54bb00"
|
||||
},
|
||||
"CNBETAAndroid4.1.52": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14427120_6f7bdcd832cf_5c861411529529",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14426018_808f7828fdd4_646eb1de0d5580",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14460274_5ed5ff5977db_299d2e7b72efe8"
|
||||
},
|
||||
"CNBETAWin4.1.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14372365_fa78e03ad599_36972b4e3bb553",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14352532_e3dee8767e70_9fd758f12171f5",
|
||||
@@ -13,6 +20,13 @@
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14358961_e055a63b3c34_b199a0234548b5",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14374543_04d971175704_ab00cb3f54bb00"
|
||||
},
|
||||
"CNBETAWin4.1.52": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14427120_6f7bdcd832cf_5c861411529529",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14426018_808f7828fdd4_646eb1de0d5580",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14460274_5ed5ff5977db_299d2e7b72efe8"
|
||||
},
|
||||
"CNBETAiOS4.1.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14372365_fa78e03ad599_36972b4e3bb553",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14352532_e3dee8767e70_9fd758f12171f5",
|
||||
@@ -20,6 +34,13 @@
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14358961_e055a63b3c34_b199a0234548b5",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14374543_04d971175704_ab00cb3f54bb00"
|
||||
},
|
||||
"CNBETAiOS4.1.52": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14427120_6f7bdcd832cf_5c861411529529",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14426018_808f7828fdd4_646eb1de0d5580",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14460274_5ed5ff5977db_299d2e7b72efe8"
|
||||
},
|
||||
"OSBETAAndroid4.1.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14372365_fa78e03ad599_36972b4e3bb553",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14352532_e3dee8767e70_9fd758f12171f5",
|
||||
@@ -27,6 +48,13 @@
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14358961_e055a63b3c34_b199a0234548b5",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14374543_04d971175704_ab00cb3f54bb00"
|
||||
},
|
||||
"OSBETAAndroid4.1.52": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14427120_6f7bdcd832cf_5c861411529529",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14426018_808f7828fdd4_646eb1de0d5580",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14460274_5ed5ff5977db_299d2e7b72efe8"
|
||||
},
|
||||
"OSBETAWin4.1.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14372365_fa78e03ad599_36972b4e3bb553",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14352532_e3dee8767e70_9fd758f12171f5",
|
||||
@@ -34,11 +62,25 @@
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14358961_e055a63b3c34_b199a0234548b5",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14374543_04d971175704_ab00cb3f54bb00"
|
||||
},
|
||||
"OSBETAWin4.1.52": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14427120_6f7bdcd832cf_5c861411529529",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14426018_808f7828fdd4_646eb1de0d5580",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14460274_5ed5ff5977db_299d2e7b72efe8"
|
||||
},
|
||||
"OSBETAiOS4.1.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14372365_fa78e03ad599_36972b4e3bb553",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14352532_e3dee8767e70_9fd758f12171f5",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14394020_12e3f0c6a002_07566508dd1394",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14358961_e055a63b3c34_b199a0234548b5",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14374543_04d971175704_ab00cb3f54bb00"
|
||||
},
|
||||
"OSBETAiOS4.1.52": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"asset_bundle_url_b": "https://autopatchcn.bhsr.com/asb/BetaLive/output_14420305_7a74f0e95f84_edf69bcd963b3a",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_14427120_6f7bdcd832cf_5c861411529529",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_14426018_808f7828fdd4_646eb1de0d5580",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_14460274_5ed5ff5977db_299d2e7b72efe8"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.example.firefly_go_android
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.content.pm.ServiceInfo
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
@@ -16,6 +18,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import libandroid.Libandroid
|
||||
import androidx.core.content.edit
|
||||
|
||||
class GolangServerService : Service() {
|
||||
|
||||
@@ -33,9 +36,10 @@ class GolangServerService : Service() {
|
||||
createNotificationChannel()
|
||||
}
|
||||
|
||||
@SuppressLint("WakelockTimeout")
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (isRunning) {
|
||||
Log.d(TAG, "❗ Server is already running")
|
||||
Log.d(TAG, "Server is already running")
|
||||
return START_STICKY
|
||||
}
|
||||
isRunning = true
|
||||
@@ -64,42 +68,63 @@ class GolangServerService : Service() {
|
||||
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||
.build()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 34) {
|
||||
startForeground(
|
||||
NOTIFICATION_ID,
|
||||
notification,
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
|
||||
)
|
||||
} else if (Build.VERSION.SDK_INT >= 29) {
|
||||
startForeground(
|
||||
NOTIFICATION_ID,
|
||||
notification,
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST
|
||||
)
|
||||
} else {
|
||||
startForeground(NOTIFICATION_ID, notification)
|
||||
}
|
||||
|
||||
startForeground(NOTIFICATION_ID, notification)
|
||||
|
||||
// Khởi tạo WakeLock và WifiLock
|
||||
try {
|
||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GolangServer::WakeLock")
|
||||
wakeLock?.acquire(10*60*1000L)
|
||||
Log.d(TAG, "✅ WakeLock acquired")
|
||||
wakeLock?.acquire()
|
||||
Log.d(TAG, "WakeLock acquired")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ WakeLock failed", e)
|
||||
Log.e(TAG, "Lock failed", e)
|
||||
}
|
||||
|
||||
Thread {
|
||||
try {
|
||||
val appDataPath = intent?.getStringExtra("appDataPath")
|
||||
val sharedPrefs = getSharedPreferences("AppPrefs", MODE_PRIVATE)
|
||||
var appDataPath = intent?.getStringExtra("appDataPath")
|
||||
|
||||
if (appDataPath != null) {
|
||||
sharedPrefs.edit { putString("saved_app_data_path", appDataPath) }
|
||||
} else {
|
||||
appDataPath = sharedPrefs.getString("saved_app_data_path", null)
|
||||
}
|
||||
|
||||
if (appDataPath != null) {
|
||||
Libandroid.setPathDataLocal(appDataPath)
|
||||
Log.d(TAG, "✅ Set path data: $appDataPath")
|
||||
Log.d(TAG, "Set path data: $appDataPath")
|
||||
} else {
|
||||
isRunning = false
|
||||
Log.e(TAG, "❌ appDataPath not received in intent")
|
||||
Log.e(TAG, "appDataPath not received and not found in SharedPreferences")
|
||||
stopSelf()
|
||||
return@Thread
|
||||
}
|
||||
|
||||
Libandroid.setServerRunning(true)
|
||||
isRunning = true
|
||||
Log.d(TAG, "✅ Server started")
|
||||
Log.d(TAG, "Server started")
|
||||
} catch (e: Exception) {
|
||||
isRunning = false
|
||||
Log.e(TAG, "❌ Error starting server", e)
|
||||
Log.e(TAG, "Error starting server", e)
|
||||
stopSelf()
|
||||
}
|
||||
}.start()
|
||||
|
||||
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
@@ -107,7 +132,6 @@ class GolangServerService : Service() {
|
||||
super.onDestroy()
|
||||
Log.d(TAG, "onDestroy called")
|
||||
|
||||
// 1. Tắt server
|
||||
try {
|
||||
val result = Libandroid.setServerRunning(false)
|
||||
isRunning = false
|
||||
@@ -116,15 +140,16 @@ class GolangServerService : Service() {
|
||||
Log.e(TAG, "Error shutting down server", e)
|
||||
}
|
||||
|
||||
// Nhả các khóa tài nguyên
|
||||
try {
|
||||
wakeLock?.let {
|
||||
if (it.isHeld) {
|
||||
it.release()
|
||||
Log.d(TAG, "✅ WakeLock released")
|
||||
Log.d(TAG, "WakeLock released")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ Failed to release WakeLock", e)
|
||||
Log.e(TAG, "Failed to release Locks", e)
|
||||
}
|
||||
isRunning = false
|
||||
}
|
||||
@@ -143,7 +168,7 @@ class GolangServerService : Service() {
|
||||
|
||||
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.createNotificationChannel(channel)
|
||||
Log.d(TAG, "✅ Notification channel created")
|
||||
Log.d(TAG, "Notification channel created")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import AutoUpdaterManager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
@@ -67,6 +68,11 @@ import kotlinx.coroutines.delay
|
||||
import org.json.JSONObject
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.net.toUri
|
||||
import android.provider.Settings
|
||||
|
||||
data class AppVersion(
|
||||
val latestVersion: String,
|
||||
@@ -77,14 +83,14 @@ data class AppVersion(
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
requestBatteryExemption(this)
|
||||
requestInstallPermission(this)
|
||||
|
||||
val appDataPath = filesDir.absolutePath
|
||||
val appDataPath = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "FireflyGo").absolutePath
|
||||
val dataDir = File("$appDataPath/data")
|
||||
dataDir.mkdirs()
|
||||
if (!dataDir.exists()) dataDir.mkdirs()
|
||||
|
||||
copyRawToFile(this, dataDir, "data-in-game.json", R.raw.data_in_game_json)
|
||||
copyRawToFile(this, dataDir, "freesr-data.json", R.raw.freesr_data_json)
|
||||
copyRawToFile(this, dataDir, "version.json", R.raw.version_json)
|
||||
copyRawToFile(dataDir)
|
||||
|
||||
val jsonString = resources.openRawResource(R.raw.app_version_json).use { input ->
|
||||
input.bufferedReader().use { it.readText() }
|
||||
@@ -112,22 +118,61 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
}
|
||||
@SuppressLint("BatteryLife")
|
||||
|
||||
fun copyRawToFile(context: Context, targetDir: File, fileName: String, resId: Int, override: Boolean = false) {
|
||||
val outFile = File(targetDir, fileName)
|
||||
if (!outFile.exists() || override) {
|
||||
try {
|
||||
context.resources.openRawResource(resId).use { input ->
|
||||
fun requestBatteryExemption(context: Context) {
|
||||
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
if (!powerManager.isIgnoringBatteryOptimizations(context.packageName)) {
|
||||
val intent = Intent().apply {
|
||||
action = ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
data = "package:${context.packageName}".toUri()
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
fun requestInstallPermission(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (!context.packageManager.canRequestPackageInstalls()) {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).apply {
|
||||
data = "package:${context.packageName}".toUri()
|
||||
}
|
||||
context.startActivity(intent)
|
||||
Toast.makeText(context, "Please allow installing unknown apps to update", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
fun copyRawToFile(targetDir: File, override: Boolean = false): Boolean {
|
||||
val files = listOf(
|
||||
"assets/data-in-game.json" to "data-in-game.json",
|
||||
"assets/freesr-data.json" to "freesr-data.json",
|
||||
"assets/version.json" to "version.json"
|
||||
)
|
||||
|
||||
return try {
|
||||
if (!targetDir.exists()) targetDir.mkdirs()
|
||||
|
||||
for ((assetPath, name) in files) {
|
||||
val outFile = File(targetDir, name)
|
||||
|
||||
if (outFile.exists() && !override) continue
|
||||
|
||||
val inputStream =
|
||||
MainActivity::class.java.classLoader
|
||||
?.getResourceAsStream(assetPath)
|
||||
?: return false
|
||||
|
||||
inputStream.use { input ->
|
||||
FileOutputStream(outFile).use { output ->
|
||||
input.copyTo(output)
|
||||
output.fd.sync()
|
||||
}
|
||||
}
|
||||
Log.i("FileCopy", "${if (override) "✅ Overridden" else "✅ Copied"} $fileName to ${outFile.absolutePath}")
|
||||
} catch (e: Exception) {
|
||||
Log.e("FileCopy", "❌ Failed to copy $fileName: ${e.message}")
|
||||
}
|
||||
} else {
|
||||
Log.i("FileCopy", "ℹ️ $fileName already exists at ${outFile.absolutePath}")
|
||||
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,18 +181,18 @@ fun removeFile(targetDir: File, fileName: String): Boolean {
|
||||
return if (file.exists()) {
|
||||
try {
|
||||
if (file.delete()) {
|
||||
Log.i("FileRemove", "🗑️ Removed $fileName from ${file.absolutePath}")
|
||||
Log.i("FileRemove", "Removed $fileName from ${file.absolutePath}")
|
||||
true
|
||||
} else {
|
||||
Log.e("FileRemove", "❌ Failed to remove $fileName from ${file.absolutePath}")
|
||||
Log.e("FileRemove", "Failed to remove $fileName from ${file.absolutePath}")
|
||||
false
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("FileRemove", "❌ Error removing $fileName: ${e.message}")
|
||||
Log.e("FileRemove", "Error removing $fileName: ${e.message}")
|
||||
false
|
||||
}
|
||||
} else {
|
||||
Log.i("FileRemove", "ℹ️ $fileName does not exist in ${targetDir.absolutePath}")
|
||||
Log.i("FileRemove", "$fileName does not exist in ${targetDir.absolutePath}")
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -239,7 +284,7 @@ fun ServerControlScreen(appDataPath: String, dataDir: File, appVersion: AppVersi
|
||||
if (!isRunning) {
|
||||
val intent = Intent(context, GolangServerService::class.java)
|
||||
intent.putExtra("appDataPath", appDataPath)
|
||||
context.startService(intent)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
} else {
|
||||
context.stopService(Intent(context, GolangServerService::class.java))
|
||||
}
|
||||
@@ -382,9 +427,7 @@ fun ServerControlScreen(appDataPath: String, dataDir: File, appVersion: AppVersi
|
||||
onClick = {
|
||||
showResetDialog = false
|
||||
try {
|
||||
copyRawToFile(context, dataDir, "data-in-game.json", R.raw.data_in_game_json, true)
|
||||
copyRawToFile(context, dataDir, "freesr-data.json", R.raw.freesr_data_json, true)
|
||||
copyRawToFile(context, dataDir, "version.json", R.raw.version_json, true)
|
||||
copyRawToFile(dataDir, true)
|
||||
Toast.makeText(context, "Data has been reset successfully", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(context, "Reset failed: ${e.message}", Toast.LENGTH_SHORT).show()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"latest_version": "4.1.1-01",
|
||||
"changelog": "UPDATE: 4.1.51",
|
||||
"apk_url": "https://git.kain.io.vn/Firefly-Shelter/FireflyGo_Android/releases/download/4.1.1-01/firefly_go_android.apk"
|
||||
"latest_version": "4.1.2-01",
|
||||
"changelog": "UPDATE: 4.1.52",
|
||||
"apk_url": "https://git.kain.io.vn/Firefly-Shelter/FireflyGo_Android/releases/download/4.1.2-01/firefly_go_android.apk"
|
||||
}
|
||||
Reference in New Issue
Block a user