SystemUtils类处理

This commit is contained in:
zu
2023-11-29 03:39:01 +08:00
parent 10f0c71ad7
commit 93f3a6d87f
6 changed files with 20 additions and 77 deletions

View File

@@ -1,58 +0,0 @@
/**
*
*/
package com.chwl.core.utils;
import android.content.Context;
import android.os.Build;
import android.os.Looper;
import com.chwl.library.utils.config.BasicConfig;
import com.chwl.library.utils.log.MLog;
import java.lang.reflect.Method;
/**
* @author daixiang
*
*/
public final class SystemUtils {
public static final String TAG = "SystemUtils";
public static boolean isMainThread() {
return Looper.getMainLooper() == Looper.myLooper();
}
/**
* MediaSessionLegacyHelper is a static singleton that is lazily instantiated and keeps a
* reference to the context it's given the first time MediaSessionLegacyHelper.getHelper()
* is called.
* This leak was introduced in android-5.0.1_r1 and fixed in Android 5.1.0_r1 by calling
* context.getApplicationContext().
* Fix: https://github.com/android/platform_frameworks_base/commit/9b5257c9c99c4cb541d8e8e78fb04f008b1a9091
*
* Hack: to fix this, you could call MediaSessionLegacyHelper.getHelper() early in
* Application.onCreate() and pass it the application context.
* https://github.com/square/leakcanary/blob/master/leakcanary-android/src/main/java/com/squareup/leakcanary/AndroidExcludedRefs.java
*/
public static void fixMediaSessionLegacyHelper() {
try {
if (Build.VERSION.SDK_INT != 21) {
MLog.info(TAG, "fixMediaSessionLegacyHelper api:" + Build.VERSION.SDK_INT);
return;
}
Class cls = Class.forName("android.media.session.MediaSessionLegacyHelper");
if (cls == null) {
return;
}
Method method = cls.getMethod("getHelper", Context.class);
method.invoke(null, BasicConfig.INSTANCE.getAppContext());
MLog.info(TAG, "fixMediaSessionLegacyHelper done!");
} catch (Throwable throwable) {
MLog.error(TAG, "fixMediaSessionLegacyHelper error! " + throwable);
}
}
}