desc:wifi优化

main
xiaowusky 1 year ago
parent 945705b211
commit d3145d0ed2

@ -75,13 +75,13 @@ class CommonTopBar : LinearLayout {
if (!enable) {
mBinding?.wifi?.visibility = GONE
} else {
// mBinding?.wifi?.visibility = VISIBLE
mBinding?.wifi?.visibility = VISIBLE
}
}
override fun onLevel(level: Int) {
Log.i(this@CommonTopBar.javaClass.name, "wifiCallback onLevel = $level")
mBinding?.wifi?.visibility = if (level > 0) VISIBLE else GONE
// mBinding?.wifi?.visibility = if (level > 0) VISIBLE else GONE
val showLevel = (level + 1) * 20
mBinding?.wifi?.setImageLevel(showLevel)
}

@ -67,25 +67,19 @@ object LztekUtil {
return mLztek?.storageCardPath
}
private const val BYTE_GB = 1024 * 1024 * 1024
fun getCardAvailableSizeWeak(): Boolean {
val context = CommonApplication.getContext()
var hasNvme = false
var cardPath = Environment.getExternalStorageDirectory().absolutePath
context?.let {
val nvmePath = StorageUtils.getStoragePath(it, NVME_KEYWORDS)
val nvmePath = StorageUtils.getStoragePath(it, false)
if (!nvmePath.isNullOrEmpty()) {
hasNvme = true
cardPath = nvmePath
}
}
cardPath?.let {
val statfs = StatFs(it)
val blocSize = statfs.blockSizeLong
val availableSize = statfs.availableBlocksLong * blocSize
val totalSize = statfs.blockCountLong * blocSize
val gb = (availableSize / BYTE_GB).toInt()
val gb = StorageUtils.getAvailableSizeSizeInGB(it)
return if (hasNvme) gb < STORAGE_WARN_THRESHOLD_NVME else gb < STORAGE_WARN_THRESHOLD
}
return false

@ -5,6 +5,8 @@ import android.content.Context
import android.content.Context.WIFI_SERVICE
import android.content.Intent
import android.content.IntentFilter
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.net.wifi.WifiManager
import android.util.Log
@ -28,6 +30,20 @@ object WifiHelper {
callbacks.forEach {
it.onLevel(mRssi)
}
}else if (intent?.action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
val networkInfo = intent?.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO) as NetworkInfo?
networkInfo?.let {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
if (networkInfo.detailedState == NetworkInfo.DetailedState.DISCONNECTED){
mWifiState = -1
}else if (networkInfo.detailedState == NetworkInfo.DetailedState.CONNECTED){
mWifiState = WifiManager.WIFI_STATE_ENABLED
}
callbacks.forEach {
it.onEnable(mWifiState == WifiManager.WIFI_STATE_ENABLED)
}
}
}
}
Log.i(
this@WifiHelper.javaClass.name,
@ -49,6 +65,7 @@ object WifiHelper {
private fun watchWifi(context: Context) {
val filter = IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)
filter.addAction(WifiManager.RSSI_CHANGED_ACTION)
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION)
context.registerReceiver(receiver, filter)
}

@ -1,13 +1,12 @@
package com.common.commonlib.utils
import android.content.Context
import android.os.StatFs
import android.os.storage.StorageManager
import android.os.storage.StorageVolume
import java.lang.reflect.InvocationTargetException
val USB_KEYWORDS = arrayOf("USB", "U 盘")
@JvmField
val NVME_KEYWORDS = arrayOf("新加卷")
object StorageUtils {
@ -17,7 +16,7 @@ object StorageUtils {
* @param keyword SD = "内部存储"; EXT = "SD卡"; USB = "U盘"
* @return
*/
fun getStoragePath(mContext: Context, keywords: Array<String> = USB_KEYWORDS): String? {
fun getStoragePath(mContext: Context, isUsb: Boolean = true): String? {
var targetpath: String? = ""
val mStorageManager = mContext
.getSystemService(Context.STORAGE_SERVICE) as StorageManager
@ -34,8 +33,16 @@ object StorageUtils {
val storageVolumeElement: StorageVolume = result[i]
val userLabel = getUserLabel.invoke(storageVolumeElement) as String
val path = getPath.invoke(storageVolumeElement) as String
if (keywords.contains(userLabel))
targetpath = path
if (isUsb) {
if (USB_KEYWORDS.contains(userLabel)) {
targetpath = path
}
} else {
// 大于400GB的也当硬盘看待
if (NVME_KEYWORDS.contains(userLabel) || getSizeInGB(path) > 400) {
targetpath = path
}
}
}
} catch (e: ClassNotFoundException) {
e.printStackTrace()
@ -48,4 +55,21 @@ object StorageUtils {
}
return targetpath
}
private const val BYTE_GB = 1024 * 1024 * 1024f
private fun getSizeInGB(path: String): Int {
val statfs = StatFs(path)
val blocSize = statfs.blockSizeLong
val totalSize = statfs.blockCountLong * blocSize
val gb = (totalSize / BYTE_GB).toInt()
return gb;
}
fun getAvailableSizeSizeInGB(path: String): Float {
val statfs = StatFs(path)
val blocSize = statfs.blockSizeLong
val availableSize = statfs.availableBlocksLong * blocSize
val gb = (availableSize / BYTE_GB)
return gb
}
}

@ -42,10 +42,12 @@ public class AndroidMuxer {
try {
long timeMillis = System.currentTimeMillis();
File output = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO, timeMillis, DEFAULT_RECORD_DURATION);
mCurrentPath = output.getAbsolutePath();
LogUtils.v(String.format("startRecording: %s", output));
mMuxer = new MediaMuxer(mCurrentPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mStarted = false;
if (output != null) {
mCurrentPath = output.getAbsolutePath();
LogUtils.v(String.format("startRecording: %s", output));
mMuxer = new MediaMuxer(mCurrentPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mStarted = false;
}
} catch (IOException e) {
e.printStackTrace();
}
@ -123,6 +125,7 @@ public class AndroidMuxer {
if (mStartRecordTime > 0 && mStartRecordTime < System.currentTimeMillis() && !TextUtils.isEmpty(mCurrentPath)) {
insertToDB(mStartRecordTime, mCurrentPath);
}
mMuxer = null;
}
}
}

@ -1,7 +1,5 @@
package com.yinuo.library.vlc.encoder;
import static com.common.commonlib.utils.StorageUtilsKt.NVME_KEYWORDS;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
@ -14,6 +12,7 @@ import android.view.Surface;
import androidx.annotation.Nullable;
import com.common.commonlib.CommonApplication;
import com.common.commonlib.utils.LogUtils;
import com.common.commonlib.utils.StorageUtils;
import java.io.File;
@ -189,8 +188,7 @@ public class CameraHelper {
* Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory
* is persistent and available to other applications like gallery.
*
* @param type Media type. Can be video or image.
* @param defaultRecordDuration
* @param type Media type. Can be video or image.
* @return A file object pointing to the newly created file.
*/
public static File getOutputMediaFile(int type, long time, long duration) {
@ -199,6 +197,11 @@ public class CameraHelper {
File mediaStorageDir = getMediaStorageDir();
if (mediaStorageDir == null) return null;
Float availableSizeSizeInGB = StorageUtils.INSTANCE.getAvailableSizeSizeInGB(mediaStorageDir.getAbsolutePath());
if (availableSizeSizeInGB < 1f) {
LogUtils.e("存储空间即将耗尽");
return null;
}
// Create a media file name
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);
String timeStamp = format.format(time);
@ -221,7 +224,7 @@ public class CameraHelper {
private static File getMediaStorageDir() {
Context context = CommonApplication.Companion.getContext();
if (context != null) {
String nvmePath = StorageUtils.INSTANCE.getStoragePath(context, NVME_KEYWORDS);
String nvmePath = StorageUtils.INSTANCE.getStoragePath(context, false);
if (!TextUtils.isEmpty(nvmePath)) {
File mediaStorageDir = new File(nvmePath + File.separator + "video");
if (!mediaStorageDir.exists() && !mediaStorageDir.mkdirs()) {

Loading…
Cancel
Save