package com.xm.test.myfilemaster.util

import android.bluetooth.BluetoothAdapter
import android.content.ContentResolver
import android.content.Context
import android.location.LocationManager
import android.net.wifi.WifiManager
import android.provider.Settings


object SystemServerState {

    fun isGPSEnabled(context: Context): Boolean {
        val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ?: false
    }

    fun isBluetoothEnabled(): Boolean {
        val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
        return bluetoothAdapter?.isEnabled ?: false
    }

    fun isHotspotEnabled(context: Context): Boolean {
        val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
        return wifiManager.isWifiEnabled ?: false
    }

    fun isAutoBrightnessEnabled(contentResolver: ContentResolver?): Boolean {
        try {
            val mode: Int =
                Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE)
            return mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
        } catch (e: Settings.SettingNotFoundException) {
            e.printStackTrace()
        }
        return false
    }
}