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

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

Merge changes Ic25a611f,Ib1b0dce8 into main

* changes:
  HealthServiceWrapper.java formatting + comments
  TIM formatting
parents 668ea456 a314b4e3
Loading
Loading
Loading
Loading
+13 −16
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;


public final class TradeInModeService extends SystemService {
    private static final String TAG = "TradeInModeService";

@@ -339,8 +338,7 @@ public final class TradeInModeService extends SystemService {

    private boolean isFrpActive() {
        try {
            PersistentDataBlockManager pdb =
                    mContext.getSystemService(PersistentDataBlockManager.class);
            PersistentDataBlockManager pdb = mContext.getSystemService(PersistentDataBlockManager.class);
            if (pdb == null) {
                return false;
            }
@@ -351,9 +349,9 @@ public final class TradeInModeService extends SystemService {
        }
    }

    // This returns true if the device has progressed far enough into Setup Wizard that it no
    // longer makes sense to enable trade-in mode. As a last stop, we check the SUW completion
    // bits.
    // This returns true if the device has progressed far enough into Setup Wizard
    // that it no longer makes sense to enable trade-in mode. As a last stop, we
    // check the SUW completion bits.
    private boolean isDeviceSetup() {
        final ContentResolver cr = mContext.getContentResolver();
        try {
@@ -395,7 +393,6 @@ public final class TradeInModeService extends SystemService {
        cr.registerContentObserver(deviceProvisioned, false, observer);
    }


    private void watchForNetworkChange() {
        mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
        NetworkRequest networkRequest = new NetworkRequest.Builder()
+43 −24
Original line number Diff line number Diff line
@@ -28,15 +28,21 @@ import com.android.internal.annotations.VisibleForTesting;
import java.util.NoSuchElementException;

/**
 * HealthServiceWrapper wraps the internal IHealth service and refreshes the service when necessary.
 * This is essentially a wrapper over IHealth that is useful for BatteryService.
 * HealthServiceWrapper wraps the internal IHealth service and refreshes the
 * service when necessary.
 *
 * <p>The implementation may be backed by a HIDL or AIDL HAL.
 * This is essentially a wrapper over IHealth that is useful for BatteryService,
 * and TradeInModeService.
 *
 * <p>On new registration of IHealth service, the internal service is refreshed. On death of an
 * existing IHealth service, the internal service is NOT cleared to avoid race condition between
 * death notification and new service notification. Hence, a caller must check for transaction
 * errors when calling into the service.
 * <p>
 * The implementation may be backed by a HIDL or AIDL HAL.
 *
 * <p>
 * On new registration of IHealth service, the internal service is refreshed. On
 * death of an existing IHealth service, the internal service is NOT cleared to
 * avoid race condition between death notification and new service notification.
 * Hence, a caller must check for transaction errors when calling into the
 * service.
 *
 * @hide Should only be used internally.
 */
@@ -46,7 +52,8 @@ public abstract class HealthServiceWrapper {
    abstract HandlerThread getHandlerThread();

    /**
     * Calls into get*() functions in the health HAL. This reads into the kernel interfaces
     * Calls into get*() functions in the health HAL. This reads into the kernel
     * interfaces
     * directly.
     *
     * @see IBatteryPropertiesRegistrar#getProperty
@@ -61,11 +68,14 @@ public abstract class HealthServiceWrapper {
    public abstract void scheduleUpdate() throws RemoteException;

    /**
     * Calls into getHealthInfo() in the health HAL. This returns a cached value in the health HAL
     * Calls into getHealthInfo() in the health HAL. This returns a cached value in
     * the health HAL
     * implementation.
     *
     * @return health info. {@code null} if no health HAL service. {@code null} if any
     *     service-specific error when calling {@code getHealthInfo}, e.g. it is unsupported.
     * @return health info. {@code null} if no health HAL service. {@code null} if
     *         any
     *         service-specific error when calling {@code getHealthInfo}, e.g. it is
     *         unsupported.
     * @throws RemoteException for any transaction-level errors
     */
    public abstract android.hardware.health.HealthInfo getHealthInfo() throws RemoteException;
@@ -89,7 +99,8 @@ public abstract class HealthServiceWrapper {
     * Create a new HealthServiceWrapper instance.
     *
     * @param healthInfoCallback the callback to call when health info changes
     * @return the new HealthServiceWrapper instance, which may be backed by HIDL or AIDL service.
     * @return the new HealthServiceWrapper instance, which may be backed by HIDL or
     *         AIDL service.
     * @throws RemoteException        transaction errors
     * @throws NoSuchElementException no HIDL or AIDL service is available
     */
@@ -97,23 +108,31 @@ public abstract class HealthServiceWrapper {
            throws RemoteException, NoSuchElementException {
        return create(
                healthInfoCallback == null ? null : new HealthRegCallbackAidl(healthInfoCallback),
                new HealthServiceWrapperAidl.ServiceManagerStub() {},
                new HealthServiceWrapperAidl.ServiceManagerStub() {
                },
                healthInfoCallback == null ? null : new HealthHalCallbackHidl(healthInfoCallback),
                new HealthServiceWrapperHidl.IServiceManagerSupplier() {},
                new HealthServiceWrapperHidl.IHealthSupplier() {});
                new HealthServiceWrapperHidl.IServiceManagerSupplier() {
                },
                new HealthServiceWrapperHidl.IHealthSupplier() {
                });
    }

    /**
     * Create a new HealthServiceWrapper instance for testing.
     *
     * @param aidlRegCallback callback for AIDL service registration, or {@code null} if the client
     *     does not care about AIDL service registration notifications
     * @param aidlRegCallback            callback for AIDL service registration, or
     *                                   {@code null} if the client
     *                                   does not care about AIDL service
     *                                   registration notifications
     * @param aidlServiceManager         Stub for AIDL ServiceManager
     * @param hidlRegCallback callback for HIDL service registration, or {@code null} if the client
     *     does not care about HIDL service registration notifications
     * @param hidlRegCallback            callback for HIDL service registration, or
     *                                   {@code null} if the client
     *                                   does not care about HIDL service
     *                                   registration notifications
     * @param hidlServiceManagerSupplier supplier of HIDL service manager
     * @param hidlHealthSupplier         supplier of HIDL health HAL
     * @return the new HealthServiceWrapper instance, which may be backed by HIDL or AIDL service.
     * @return the new HealthServiceWrapper instance, which may be backed by HIDL or
     *         AIDL service.
     */
    @VisibleForTesting
    static @NonNull HealthServiceWrapper create(