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

Commit e74bcd1c authored by Xiang Wang's avatar Xiang Wang
Browse files

Add SDK support for CPU/GPU headroom APIs

Bug: 346604998
Flag: android.os.cpu_gpu_headrooms
Test: atest HeadroomTest PerformanceHintNativeTestCases \
            HintManagerServiceTest PowerHalWrapperAidlTest
Change-Id: Ie5423b0c83bcf1d241bdd140197cec125eed8496
API-Coverage-Bug: 378780498
parent b3773d73
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -33301,6 +33301,14 @@ package android.os {
    method public final android.os.CountDownTimer start();
  }
  @FlaggedApi("android.os.cpu_gpu_headrooms") public final class CpuHeadroomParams {
    ctor public CpuHeadroomParams();
    method public int getCalculationType();
    method public void setCalculationType(int);
    field public static final int CPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1; // 0x1
    field public static final int CPU_HEADROOM_CALCULATION_TYPE_MIN = 0; // 0x0
  }
  public final class CpuUsageInfo implements android.os.Parcelable {
    method public int describeContents();
    method public long getActive();
@@ -33548,6 +33556,14 @@ package android.os {
    method public void onProgress(long);
  }
  @FlaggedApi("android.os.cpu_gpu_headrooms") public final class GpuHeadroomParams {
    ctor public GpuHeadroomParams();
    method public int getCalculationType();
    method public void setCalculationType(int);
    field public static final int GPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1; // 0x1
    field public static final int GPU_HEADROOM_CALCULATION_TYPE_MIN = 0; // 0x0
  }
  public class Handler {
    ctor @Deprecated public Handler();
    ctor @Deprecated public Handler(@Nullable android.os.Handler.Callback);
@@ -34798,6 +34814,10 @@ package android.os.health {
  }
  public class SystemHealthManager {
    method @FlaggedApi("android.os.cpu_gpu_headrooms") @FloatRange(from=0.0f, to=100.0f) public float getCpuHeadroom(@Nullable android.os.CpuHeadroomParams);
    method @FlaggedApi("android.os.cpu_gpu_headrooms") public long getCpuHeadroomMinIntervalMillis();
    method @FlaggedApi("android.os.cpu_gpu_headrooms") @FloatRange(from=0.0f, to=100.0f) public float getGpuHeadroom(@Nullable android.os.GpuHeadroomParams);
    method @FlaggedApi("android.os.cpu_gpu_headrooms") public long getGpuHeadroomMinIntervalMillis();
    method @FlaggedApi("com.android.server.power.optimization.power_monitor_api") public void getPowerMonitorReadings(@NonNull java.util.List<android.os.PowerMonitor>, @Nullable java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.os.PowerMonitorReadings,java.lang.RuntimeException>);
    method @FlaggedApi("com.android.server.power.optimization.power_monitor_api") public void getSupportedPowerMonitors(@Nullable java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.util.List<android.os.PowerMonitor>>);
    method public android.os.health.HealthStats takeMyUidSnapshot();
+2 −0
Original line number Diff line number Diff line
@@ -232,6 +232,8 @@ aidl_interface {
        "android.hardware.power-aidl",
    ],
    srcs: [
        "android/os/CpuHeadroomParamsInternal.aidl",
        "android/os/GpuHeadroomParamsInternal.aidl",
        "android/os/IHintManager.aidl",
        "android/os/IHintSession.aidl",
    ],
+4 −1
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ import android.os.IBatteryPropertiesRegistrar;
import android.os.IBinder;
import android.os.IDumpstate;
import android.os.IHardwarePropertiesManager;
import android.os.IHintManager;
import android.os.IPowerManager;
import android.os.IPowerStatsService;
import android.os.IRecoverySystem;
@@ -1195,8 +1196,10 @@ public final class SystemServiceRegistry {
            public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                IBinder batteryStats = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME);
                IBinder powerStats = ServiceManager.getService(Context.POWER_STATS_SERVICE);
                IBinder perfHint = ServiceManager.getService(Context.PERFORMANCE_HINT_SERVICE);
                return new SystemHealthManager(IBatteryStats.Stub.asInterface(batteryStats),
                        IPowerStatsService.Stub.asInterface(powerStats));
                        IPowerStatsService.Stub.asInterface(powerStats),
                        IHintManager.Stub.asInterface(perfHint));
            }});

        registerService(Context.CONTEXTHUB_SERVICE, ContextHubManager.class,
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.os.health.SystemHealthManager;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Headroom request params used by {@link SystemHealthManager#getCpuHeadroom(CpuHeadroomParams)}.
 */
@FlaggedApi(Flags.FLAG_CPU_GPU_HEADROOMS)
public final class CpuHeadroomParams {
    final CpuHeadroomParamsInternal mInternal;

    public CpuHeadroomParams() {
        mInternal = new CpuHeadroomParamsInternal();
    }

    /** @hide */
    @IntDef(flag = false, prefix = {"CPU_HEADROOM_CALCULATION_TYPE_"}, value = {
            CPU_HEADROOM_CALCULATION_TYPE_MIN, // 0
            CPU_HEADROOM_CALCULATION_TYPE_AVERAGE, // 1
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface CpuHeadroomCalculationType {
    }

    /**
     * Calculates the headroom based on minimum value over a device-defined window.
     */
    public static final int CPU_HEADROOM_CALCULATION_TYPE_MIN = 0;

    /**
     * Calculates the headroom based on average value over a device-defined window.
     */
    public static final int CPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1;

    /**
     * Sets the headroom calculation type.
     * <p>
     *
     * @throws IllegalArgumentException if the type is invalid.
     */
    public void setCalculationType(@CpuHeadroomCalculationType int calculationType) {
        switch (calculationType) {
            case CPU_HEADROOM_CALCULATION_TYPE_MIN:
            case CPU_HEADROOM_CALCULATION_TYPE_AVERAGE:
                mInternal.calculationType = (byte) calculationType;
                return;
        }
        throw new IllegalArgumentException("Invalid calculation type: " + calculationType);
    }

    /**
     * Gets the headroom calculation type.
     * Default to {@link #CPU_HEADROOM_CALCULATION_TYPE_MIN} if not set.
     */
    public @CpuHeadroomCalculationType int getCalculationType() {
        @CpuHeadroomCalculationType int validatedType = switch ((int) mInternal.calculationType) {
            case CPU_HEADROOM_CALCULATION_TYPE_MIN, CPU_HEADROOM_CALCULATION_TYPE_AVERAGE ->
                    mInternal.calculationType;
            default -> CPU_HEADROOM_CALCULATION_TYPE_MIN;
        };
        return validatedType;
    }

    /**
     * @hide
     */
    public CpuHeadroomParamsInternal getInternal() {
        return mInternal;
    }
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

import android.hardware.power.CpuHeadroomParams;

/**
 * Changes should be synced with match function of HintManagerService#CpuHeadroomCacheItem.
 * {@hide}
 */
@JavaDerive(equals = true, toString = true)
parcelable CpuHeadroomParamsInternal {
    boolean usesDeviceHeadroom = false;
    CpuHeadroomParams.CalculationType calculationType = CpuHeadroomParams.CalculationType.MIN;
    CpuHeadroomParams.SelectionType selectionType = CpuHeadroomParams.SelectionType.ALL;
}
Loading