Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e602138 authored by Daniel Zheng's avatar Daniel Zheng Committed by Android (Google) Code Review
Browse files

Merge "TIMService: get Health handle" into main

parents 1d412f84 420ea802
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -33,16 +33,20 @@ import android.net.Uri;
import android.os.Binder;
import android.os.ITradeInMode;
import android.os.SystemProperties;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.service.persistentdata.PersistentDataBlockManager;
import android.util.Slog;

import com.android.server.health.HealthServiceWrapper;

import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.NoSuchElementException;

public final class TradeInModeService extends SystemService {
    private static final String TAG = "TradeInModeService";
@@ -319,6 +323,19 @@ public final class TradeInModeService extends SystemService {
        Settings.Global.putInt(cr, Settings.Global.ADB_ENABLED, enabled ? 1 : 0);
    }

    private HealthServiceWrapper getHealthService() {
        try {
            HealthServiceWrapper health = HealthServiceWrapper.create(null);
            return health;
        } catch (RemoteException ex) {
            Slog.e(TAG, "health: (RemoteException)");
            throw ex.rethrowFromSystemServer();
        } catch (NoSuchElementException ex) {
            Slog.e(TAG, "health: cannot register callback. (no supported health HAL service)");
            throw ex;
        }
    }

    private int getTradeInModeState() {
        return SystemProperties.getInt(TIM_PROP, TIM_STATE_UNSET);
    }