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

Commit d64c5874 authored by Jack Nudelman's avatar Jack Nudelman
Browse files

Add ThermalMitigation API to Telephony.

go/telephony-thermal-mitigation

Test: make, cts
Bug: 158872959

Change-Id: Ib4be5edf063e4c54e9238b0403f59e1621df671e
Merged-In: Ib4be5edf063e4c54e9238b0403f59e1621df671e
parent 138e2db1
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -9615,6 +9615,25 @@ package android.telephony {
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.DataSpecificRegistrationInfo> CREATOR;
  }
  public final class DataThrottlingRequest implements android.os.Parcelable {
    method public int describeContents();
    method public long getCompletionDurationMillis();
    method public int getDataThrottlingAction();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.DataThrottlingRequest> CREATOR;
    field public static final int DATA_THROTTLING_ACTION_HOLD = 3; // 0x3
    field public static final int DATA_THROTTLING_ACTION_NO_DATA_THROTTLING = 0; // 0x0
    field public static final int DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER = 2; // 0x2
    field public static final int DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER = 1; // 0x1
  }
  public static final class DataThrottlingRequest.Builder {
    ctor public DataThrottlingRequest.Builder();
    method @NonNull public android.telephony.DataThrottlingRequest build();
    method @NonNull public android.telephony.DataThrottlingRequest.Builder setCompletionDurationMillis(long);
    method @NonNull public android.telephony.DataThrottlingRequest.Builder setDataThrottlingAction(int);
  }
  public final class ImsiEncryptionInfo implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getKeyIdentifier();
@@ -10196,6 +10215,7 @@ package android.telephony {
    method @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void resetOtaEmergencyNumberDbFilePath();
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean resetRadioConfig();
    method @RequiresPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL) public void resetSettings();
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int sendThermalMitigationRequest(@NonNull android.telephony.ThermalMitigationRequest);
    method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int setAllowedCarriers(int, java.util.List<android.service.carrier.CarrierIdentifier>);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setAllowedNetworkTypes(long);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setCallForwarding(@NonNull android.telephony.CallForwardingInfo, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.Consumer<java.lang.Integer>);
@@ -10313,6 +10333,11 @@ package android.telephony {
    field public static final int SRVCC_STATE_HANDOVER_FAILED = 2; // 0x2
    field public static final int SRVCC_STATE_HANDOVER_NONE = -1; // 0xffffffff
    field public static final int SRVCC_STATE_HANDOVER_STARTED = 0; // 0x0
    field public static final int THERMAL_MITIGATION_RESULT_INVALID_STATE = 3; // 0x3
    field public static final int THERMAL_MITIGATION_RESULT_MODEM_ERROR = 1; // 0x1
    field public static final int THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE = 2; // 0x2
    field public static final int THERMAL_MITIGATION_RESULT_SUCCESS = 0; // 0x0
    field public static final int THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR = 4; // 0x4
  }
  public static interface TelephonyManager.CallForwardingInfoCallback {
@@ -10324,6 +10349,24 @@ package android.telephony {
    field public static final int RESULT_SUCCESS = 0; // 0x0
  }
  public final class ThermalMitigationRequest implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public android.telephony.DataThrottlingRequest getDataThrottlingRequest();
    method public int getThermalMitigationAction();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.ThermalMitigationRequest> CREATOR;
    field public static final int THERMAL_MITIGATION_ACTION_DATA_THROTTLING = 0; // 0x0
    field public static final int THERMAL_MITIGATION_ACTION_RADIO_OFF = 2; // 0x2
    field public static final int THERMAL_MITIGATION_ACTION_VOICE_ONLY = 1; // 0x1
  }
  public static final class ThermalMitigationRequest.Builder {
    ctor public ThermalMitigationRequest.Builder();
    method @NonNull public android.telephony.ThermalMitigationRequest build();
    method @NonNull public android.telephony.ThermalMitigationRequest.Builder setDataThrottlingRequest(@NonNull android.telephony.DataThrottlingRequest);
    method @NonNull public android.telephony.ThermalMitigationRequest.Builder setThermalMitigationAction(int);
  }
  public final class UiccAccessRule implements android.os.Parcelable {
    ctor public UiccAccessRule(byte[], @Nullable String, long);
    method public int describeContents();
+11 −0
Original line number Diff line number Diff line
@@ -634,4 +634,15 @@ public class Annotation {
            TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA,
            TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE})
    public @interface OverrideNetworkType {}

    /**
     *  Result of a thermal mitigation request.
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = { "THERMAL_MITIGATION_RESULT_" }, value = {
        TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS,
        TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR,
        TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE,
        TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR})
    public @interface ThermalMitigationResult {}
}
+19 −0
Original line number Diff line number Diff line
/*
* Copyright (C) 2020 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.telephony;

parcelable DataThrottlingRequest;
 No newline at end of file
+244 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.telephony;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

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


/**
 * Class stores information related to the type of data throttling request. Must be populated as
 * field in {@link ThermalMitigationRequest} for sending of thermal mitigation request at {@link
 * TelephonyManager#sendThermalMitigationRequest(ThermalMitigationResult)}.
 * @hide
 */
@SystemApi
public final class DataThrottlingRequest implements Parcelable {
    /**
     * Clear all existing data throttling, enable data, and attempt to enable radio for thermal
     * mitigation all within the requested completion window. Note that attempting to enable radio
     * will not guarantee that radio will actually be enabled.
     *
     * @hide
     */
    @SystemApi
    public static final int DATA_THROTTLING_ACTION_NO_DATA_THROTTLING = 0;

    /**
     * Enact secondary carrier data throttling within specified completion window. This also
     * attempts to enables radio if currently disabled for thermal mitigation, enables data, and
     * removes any existing data throttling on primary carrier. Note that attempting to enable radio
     * will not guarantee that radio will actually be enabled.
     *
     * @hide
     */
    @SystemApi
    public static final int DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER = 1;

    /**
     * Enact primary carrier data throttling within specified completion window. This also attempts
     * to enable radio if currently disabled for thermal mitigation and disables data on secondary
     * carrier if currently enabled. Note that attempting to enable radio will not guarantee that
     * radio will actually be enabled.
     *
     * @hide
     */
    @SystemApi
    public static final int DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER = 2;

    /**
     * Immediately hold on to the current level of data throttling indicating that the current level
     * of data throttling has alleviated the thermal concerns which caused the original data
     * throttling request. A thermal module should remain actively monitoring the temperature levels
     * and request an appropriate thermal mitigation action. {@link
     * #THERMAL_MITIGATION_RESULT_INVALID_PARAMETERS} will be returned if completion window is not
     * 0.
     *
     * @hide
     */
    @SystemApi
    public static final int DATA_THROTTLING_ACTION_HOLD = 3;

    /**
     * Type of data throttling action to carry out.
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = { "DATA_THROTTLING_ACTION_" }, value = {
        DATA_THROTTLING_ACTION_NO_DATA_THROTTLING,
        DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER,
        DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER,
        DATA_THROTTLING_ACTION_HOLD})
    public @interface DataThrottlingAction {}

    /**
     * Represents the data throttling action that will be requested. See {@link
     * DATA_THROTTLING_ACTION_NO_DATA_THROTTLING}, {@link
     * #DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER}, {@link
     * #DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER}, and {@link
     * #DATA_THROTTLING_ACTION_HOLD} for more details.
     **/
    private @DataThrottlingAction int mDataThrottlingAction;
    /**
     * Represents the time over which modem should gradually execute the data thorttling request.
     */
    private long mCompletionDurationMillis;

    private DataThrottlingRequest(@NonNull int dataThrottlingAction,
            long completionDurationMillis) {
        mDataThrottlingAction = dataThrottlingAction;
        mCompletionDurationMillis = completionDurationMillis;
    }

    private DataThrottlingRequest(Parcel in) {
        mDataThrottlingAction = in.readInt();
        mCompletionDurationMillis = in.readLong();
    }

    /**
     * Implement the Parcelable interface
     */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mDataThrottlingAction);
        dest.writeLong(mCompletionDurationMillis);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public String toString() {
        return "[DataThrottlingRequest "
            + ", DataThrottlingAction=" + mDataThrottlingAction
            + ", completionDurationMillis=" + mCompletionDurationMillis
            + "]";
    }

    /**
    * @return the dataThrottlingAction.
    */
    public @DataThrottlingAction int getDataThrottlingAction() {
        return mDataThrottlingAction;
    }

    /**
     * @return the completionDurationMillis which represents the time over which modem should
     * gradually execute the data thorttling request.
     */
    public long getCompletionDurationMillis() {
        return mCompletionDurationMillis;
    }

    public static final @NonNull Parcelable.Creator<DataThrottlingRequest> CREATOR =
            new Parcelable.Creator<DataThrottlingRequest>() {

        @Override
        public DataThrottlingRequest createFromParcel(Parcel in) {
            return new DataThrottlingRequest(in);
        }

        @Override
        public DataThrottlingRequest[] newArray(int size) {
            return new DataThrottlingRequest[size];
        }
    };

    /**
     * Provides a convenient way to set the fields of a {@link DataThrottlingRequest} when creating
     * a new instance.
     *
     * <p>The example below shows how you might create a new {@code DataThrottlingRequest}:
     *
     * <pre><code>
     *
     * DataThrottlingRequest dp = new DataThrottlingRequest.Builder()
     *     .setDataThrottlingAction(
     *          DataThrottlingRequest.DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER)
     *     .setCompletionDurationMillis(10000L)
     *     .build();
     * </code></pre>
     *
     * @hide
     */
    @SystemApi
    public static final class Builder {
        private @DataThrottlingAction int mDataThrottlingAction;
        private long mCompletionDurationMillis;

        /**
         * Default constructor for Builder.
         */
        public Builder() {}

        /**
         * Set the data throttling action.
         *
         * @param dataThrottlingAction data throttling action.
         *
         * @return The same instance of the builder.
         */
        public @NonNull Builder setDataThrottlingAction(
                @DataThrottlingAction int dataThrottlingAction) {
            mDataThrottlingAction = dataThrottlingAction;
            return this;
        }

        /**
         * Set the completion duration.
         *
         * @param completionDurationMillis completion duration in millis which represents the time
         *      over which modem should gradually execute the data thorttling request. This can
         *      never be a negative number and must be 0 for {@link #DATA_THROTTLING_ACTION_HOLD}.
         *      Otherwise, an IllegalArgumentException will be thrown.
         *
         * @return The same instance of the builder.
         */
        public @NonNull Builder setCompletionDurationMillis(long completionDurationMillis) {
            mCompletionDurationMillis = completionDurationMillis;
            return this;
        }

        /**
         * Build the DataThrottlingRequest.
         *
         * @return the DataThrottlingRequest object.
         */
        public @NonNull DataThrottlingRequest build() {
            if (mCompletionDurationMillis < 0) {
                throw new IllegalArgumentException("completionDurationMillis cannot be a negative "
                        + "number");
            }

            if (mDataThrottlingAction == DataThrottlingRequest.DATA_THROTTLING_ACTION_HOLD
                    && mCompletionDurationMillis != 0) {
                throw new IllegalArgumentException("completionDurationMillis must be 0 for "
                    + "DataThrottlingRequest.DATA_THROTTLING_ACTION_HOLD");
            }

            return new DataThrottlingRequest(mDataThrottlingAction, mCompletionDurationMillis);
        }
    }

}
+103 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import android.telephony.Annotation.CarrierPrivilegeStatus;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SimActivationState;
import android.telephony.Annotation.ThermalMitigationResult;
import android.telephony.Annotation.UiccAppType;
import android.telephony.CallForwardingInfo.CallForwardingReason;
import android.telephony.VisualVoicemailService.VisualVoicemailTask;
@@ -14043,4 +14044,106 @@ public class TelephonyManager {
        return Collections.emptyList();
    }
    /**
     * Indicates that the thermal mitigation request was completed successfully.
     *
     * @hide
     */
    @SystemApi
    public static final int THERMAL_MITIGATION_RESULT_SUCCESS = 0;
    /**
     * Indicates that the thermal mitigation request was not completed because of a modem error.
     *
     * @hide
     */
    @SystemApi
    public static final int THERMAL_MITIGATION_RESULT_MODEM_ERROR = 1;
    /**
     * Indicates that the thermal mitigation request was not completed because the modem is not
     * available.
     *
     * @hide
     */
    @SystemApi
    public static final int THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE = 2;
    /**
     * Indicates that the thermal mitigation request could not power off the radio due to the device
     * either being in an active voice call, device pending an emergency call, or any other state
     * that would dissallow powering off of radio.
     *
     * @hide
     */
    @SystemApi
    public static final int THERMAL_MITIGATION_RESULT_INVALID_STATE = 3;
    /**
     * Indicates that the thermal mitigation request resulted an unknown error.
     *
     * @hide
     */
    @SystemApi
    public static final int THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR = 4;
    /**
     * Thermal mitigation request to control functionalities at modem. Thermal mitigation is done
     * per-subscription. Caller must be sure to bind the TelephonyManager instance to subId by
     * calling {@link #createForSubscriptionId(int)} if they want thermal mitigation on a specific
     * subscription Id. Otherwise, TelephonyManager will use the default subscription.
     *
     * Calling this does not guarantee that the thermal mitigation action requested was done to
     * completion. A thermal module should actively monitor the temperature levels and request an
     * appropriate thermal mitigation action. Every action is assumed to be done 'on top of' the
     * previous action, where the order of actions from least thermal mitigation to most is as
     * follows:
     * <ol>
     *   <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_DATA_THROTTLING}</li>
     *   <ol>
     *      <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_NO_DATA_THROTTLING}</li>
     *      <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER}</li>
     *      <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER}</li>
     *   </ol>
     *   <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY}</li>
     *   <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF}</li>
     * </ol>
     *
     * So, for example, requesting {@link
     * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER} will ensure that the
     * data on secondary carrier has been disabled before throttling on primary carrier. {@link
     * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY} will ensure that data on both
     * primary and secondary have been disabled. {@link
     * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF} will ensure that voice is
     * disabled and that data on both primary and secondary carriers are disabled before turning
     * radio off. {@link DataThrottlingRequest#DATA_THROTTLING_ACTION_HOLD} is not part of the order
     * and can be used at any time during data throttling to hold onto the current level of data
     * throttling.
     *
     * @param thermalMitigationRequest Thermal mitigation request. See {@link
     * ThermalMitigationRequest} for details.
     *
     * @throws IllegalStateException if the Telephony process is not currently available.
     * @throws IllegalArgumentException if the thermalMitigationRequest had invalid parameters.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    @ThermalMitigationResult
    public int sendThermalMitigationRequest(
            @NonNull ThermalMitigationRequest thermalMitigationRequest) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return telephony.sendThermalMitigationRequest(getSubId(), thermalMitigationRequest);
            }
            throw new IllegalStateException("telephony service is null.");
        } catch (RemoteException ex) {
            Log.e(TAG, "Telephony#thermalMitigationRequest RemoteException", ex);
            ex.rethrowFromSystemServer();
        }
        return THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
    }
}
Loading