66 lines
2.2 KiB
Java

package com.x.gamesdk;
import android.app.*;
import android.content.Context;
import android.os.Build;
import android.os.PerformanceHintManager;
import android.os.Process;
import android.util.Log;
public class GameSdk {
private static final String LOG_TAG = "GamePerformacneSDK";
private static GameSdk instane;
private final Context context;
private PerformanceHintManager.Session performanceHintSession;
public static GameSdk getInstance() {
return instane;
}
public GameSdk(Context context) {
instane = this;
this.context = context;
Log.d(LOG_TAG, "new Game Performance sdk.SupportGameState:" + SupportGameState() + "|Build.VERSION.SDK_INT:" + Build.VERSION.SDK_INT);
try {
PerformanceHintManager performanceHintManager = context.getSystemService(PerformanceHintManager.class);
performanceHintSession = performanceHintManager.createHintSession(new int[]{Process.myTid()}, 16666666);
Log.d(LOG_TAG, "create performance Hint Session." + performanceHintSession + "|tid:" + Process.myTid());
} catch (Exception e) {
Log.d(LOG_TAG, "create performance Hint err:" + e.getMessage());
}
}
public boolean SupportGameState() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
}
public boolean SupportPerformanceHint() {
return performanceHintSession != null;
}
public void SetGameState(boolean isLoading, int gameState) {
try {
GameManager gameManager = context.getSystemService(GameManager.class);
if (SupportGameState()) {
gameManager.setGameState(new GameState(isLoading, gameState));
Log.d(LOG_TAG, "set game state.");
}
} catch (Exception ignored) {
}
}
public void SetPerfHitTargetNanos( long targetNs) {
performanceHintSession.updateTargetWorkDuration(targetNs);
}
public void SetPerfHitPreferPowerEfficiency(boolean preferPowerEfficiency) {
performanceHintSession.setPreferPowerEfficiency(preferPowerEfficiency);
}
public void ReportPerfHint(long durantionNs) {
performanceHintSession.reportActualWorkDuration(durantionNs);
}
}