Merge branches 'beta' and 'master' of ssh://192.168.5.234:1022/Unisoc_Alldocube/CubeAoleyunSN into beta

This commit is contained in:
2022-04-20 09:22:48 +08:00
3 changed files with 58 additions and 21 deletions

View File

@@ -28,6 +28,8 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
@@ -230,6 +232,56 @@ public class JGYUtils {
}
}
/**
* 忽略电池优化
*/
private void ignoreBatteryOptimization(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
// 判断当前APP是否有加入电池优化的白名单如果没有弹出加入电池优化的白名单的设置对话框。
if (!hasIgnored) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
}
public static boolean getScreenStatus(Context context) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//true为打开false为关闭
return powerManager.isScreenOn();
}
/**
* 点亮屏幕
*
* @param timeout The timeout after which to release the wake lock, in milliseconds.
*/
@Nullable
public static PowerManager.WakeLock acquireWakeLock(@NonNull Context context, long timeout) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm == null)
return null;
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.FULL_WAKE_LOCK |
PowerManager.ON_AFTER_RELEASE,
context.getClass().getName());
wakeLock.acquire(timeout);
return wakeLock;
}
public static void release(@Nullable PowerManager.WakeLock wakeLock) {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}
}
/**
* 应用自启升级和网络权限管理
*
@@ -1491,24 +1543,6 @@ public class JGYUtils {
}
}
/**
* 忽略电池优化
*/
private void ignoreBatteryOptimization(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName());
// 判断当前APP是否有加入电池优化的白名单如果没有弹出加入电池优化的白名单的设置对话框。
if (!hasIgnored) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
}
public void killPackage(String pkg) {
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);