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

Commit b84c3cbe authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add signal type to GnssCapabilities (frameworks/base)"

parents 7d1e1c1e d4dea7da
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -19490,6 +19490,7 @@ package android.location {
  public final class GnssCapabilities implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public java.util.List<android.location.GnssSignalType> getGnssSignalTypes();
    method public boolean hasAntennaInfo();
    method public boolean hasGeofencing();
    method @Deprecated public boolean hasGnssAntennaInfo();
@@ -19523,6 +19524,7 @@ package android.location {
    ctor public GnssCapabilities.Builder();
    ctor public GnssCapabilities.Builder(@NonNull android.location.GnssCapabilities);
    method @NonNull public android.location.GnssCapabilities build();
    method @NonNull public android.location.GnssCapabilities.Builder setGnssSignalTypes(@NonNull java.util.List<android.location.GnssSignalType>);
    method @NonNull public android.location.GnssCapabilities.Builder setHasAntennaInfo(boolean);
    method @NonNull public android.location.GnssCapabilities.Builder setHasGeofencing(boolean);
    method @NonNull public android.location.GnssCapabilities.Builder setHasLowPowerMode(boolean);
@@ -19735,6 +19737,16 @@ package android.location {
    field @Deprecated public static final int STATUS_READY = 1; // 0x1
  }
  public final class GnssSignalType implements android.os.Parcelable {
    method @NonNull public static android.location.GnssSignalType create(int, @FloatRange(from=0.0f, fromInclusive=false) double, @NonNull String);
    method public int describeContents();
    method @FloatRange(from=0.0f, fromInclusive=false) public double getCarrierFrequencyHz();
    method @NonNull public String getCodeType();
    method public int getConstellationType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.location.GnssSignalType> CREATOR;
  }
  public final class GnssStatus implements android.os.Parcelable {
    method public int describeContents();
    method @FloatRange(from=0, to=360) public float getAzimuthDegrees(@IntRange(from=0) int);
+41 −8
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

@@ -123,20 +125,23 @@ public final class GnssCapabilities implements Parcelable {
     * @hide
     */
    public static GnssCapabilities empty() {
        return new GnssCapabilities(0, 0, 0);
        return new GnssCapabilities(0, 0, 0, new ArrayList<>());
    }

    private final @TopHalCapabilityFlags int mTopFlags;
    private final @SubHalMeasurementCorrectionsCapabilityFlags int mMeasurementCorrectionsFlags;
    private final @SubHalPowerCapabilityFlags int mPowerFlags;
    private final @NonNull List<GnssSignalType> mGnssSignalTypes;

    private GnssCapabilities(
            @TopHalCapabilityFlags int topFlags,
            @SubHalMeasurementCorrectionsCapabilityFlags int measurementCorrectionsFlags,
            @SubHalPowerCapabilityFlags int powerFlags) {
            @SubHalPowerCapabilityFlags int powerFlags,
            @NonNull List<GnssSignalType> gnssSignalTypes) {
        mTopFlags = topFlags;
        mMeasurementCorrectionsFlags = measurementCorrectionsFlags;
        mPowerFlags = powerFlags;
        mGnssSignalTypes = gnssSignalTypes;
    }

    /**
@@ -148,7 +153,8 @@ public final class GnssCapabilities implements Parcelable {
        if (mTopFlags == flags) {
            return this;
        } else {
            return new GnssCapabilities(flags, mMeasurementCorrectionsFlags, mPowerFlags);
            return new GnssCapabilities(flags, mMeasurementCorrectionsFlags, mPowerFlags,
                    new ArrayList<>(mGnssSignalTypes));
        }
    }

@@ -163,7 +169,8 @@ public final class GnssCapabilities implements Parcelable {
        if (mMeasurementCorrectionsFlags == flags) {
            return this;
        } else {
            return new GnssCapabilities(mTopFlags, flags, mPowerFlags);
            return new GnssCapabilities(mTopFlags, flags, mPowerFlags,
                    new ArrayList<>(mGnssSignalTypes));
        }
    }

@@ -177,7 +184,8 @@ public final class GnssCapabilities implements Parcelable {
        if (mPowerFlags == flags) {
            return this;
        } else {
            return new GnssCapabilities(mTopFlags, mMeasurementCorrectionsFlags, flags);
            return new GnssCapabilities(mTopFlags, mMeasurementCorrectionsFlags, flags,
                    new ArrayList<>(mGnssSignalTypes));
        }
    }

@@ -424,6 +432,14 @@ public final class GnssCapabilities implements Parcelable {
        return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_OTHER_MODES) != 0;
    }

    /**
     * Returns the list of {@link GnssSignalType}s that the GNSS chipset supports.
     */
    @NonNull
    public List<GnssSignalType> getGnssSignalTypes() {
        return mGnssSignalTypes;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
@@ -441,14 +457,15 @@ public final class GnssCapabilities implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mTopFlags, mMeasurementCorrectionsFlags, mPowerFlags);
        return Objects.hash(mTopFlags, mMeasurementCorrectionsFlags, mPowerFlags, mGnssSignalTypes);
    }

    public static final @NonNull Creator<GnssCapabilities> CREATOR =
            new Creator<GnssCapabilities>() {
                @Override
                public GnssCapabilities createFromParcel(Parcel in) {
                    return new GnssCapabilities(in.readInt(), in.readInt(), in.readInt());
                    return new GnssCapabilities(in.readInt(), in.readInt(), in.readInt(),
                            in.createTypedArrayList(GnssSignalType.CREATOR));
                }

                @Override
@@ -467,6 +484,7 @@ public final class GnssCapabilities implements Parcelable {
        parcel.writeInt(mTopFlags);
        parcel.writeInt(mMeasurementCorrectionsFlags);
        parcel.writeInt(mPowerFlags);
        parcel.writeTypedList(mGnssSignalTypes);
    }

    @Override
@@ -545,6 +563,9 @@ public final class GnssCapabilities implements Parcelable {
        if (hasPowerOtherModes()) {
            builder.append("OTHER_MODES_POWER ");
        }
        if (!mGnssSignalTypes.isEmpty()) {
            builder.append("signalTypes=").append(mGnssSignalTypes).append(" ");
        }
        if (builder.length() > 1) {
            builder.setLength(builder.length() - 1);
        } else {
@@ -562,17 +583,20 @@ public final class GnssCapabilities implements Parcelable {
        private @TopHalCapabilityFlags int mTopFlags;
        private @SubHalMeasurementCorrectionsCapabilityFlags int mMeasurementCorrectionsFlags;
        private @SubHalPowerCapabilityFlags int mPowerFlags;
        private @NonNull List<GnssSignalType> mGnssSignalTypes;

        public Builder() {
            mTopFlags = 0;
            mMeasurementCorrectionsFlags = 0;
            mPowerFlags = 0;
            mGnssSignalTypes = new ArrayList<>();
        }

        public Builder(@NonNull GnssCapabilities capabilities) {
            mTopFlags = capabilities.mTopFlags;
            mMeasurementCorrectionsFlags = capabilities.mMeasurementCorrectionsFlags;
            mPowerFlags = capabilities.mPowerFlags;
            mGnssSignalTypes = capabilities.mGnssSignalTypes;
        }

        /**
@@ -778,11 +802,20 @@ public final class GnssCapabilities implements Parcelable {
            return this;
        }

        /**
         * Sets a list of {@link GnssSignalType}.
         */
        public @NonNull Builder setGnssSignalTypes(@NonNull List<GnssSignalType> gnssSignalTypes) {
            mGnssSignalTypes = gnssSignalTypes;
            return this;
        }

        /**
         * Builds a new GnssCapabilities.
         */
        public @NonNull GnssCapabilities build() {
            return new GnssCapabilities(mTopFlags, mMeasurementCorrectionsFlags, mPowerFlags);
            return new GnssCapabilities(mTopFlags, mMeasurementCorrectionsFlags, mPowerFlags,
                    new ArrayList<>(mGnssSignalTypes));
        }

        private static int setFlag(int value, int flag, boolean set) {
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022, 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.location;

parcelable GnssSignalType;
+152 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.location;

import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.Preconditions;

import java.util.Objects;

/**
 * This class represents a GNSS signal type.
 */
public final class GnssSignalType implements Parcelable {

    /**
     * Creates a {@link GnssSignalType} with a full list of parameters.
     *
     * @param constellationType the constellation type as defined in
     * {@link GnssStatus.ConstellationType}
     * @param carrierFrequencyHz the carrier frequency in Hz
     * @param codeType the code type as defined in {@link GnssMeasurement#getCodeType()}
     */
    @NonNull
    public static GnssSignalType create(@GnssStatus.ConstellationType int constellationType,
            @FloatRange(from = 0.0f, fromInclusive = false) double carrierFrequencyHz,
            @NonNull String codeType) {
        Preconditions.checkArgument(carrierFrequencyHz > 0,
                "carrierFrequencyHz must be greater than 0.");
        Objects.requireNonNull(codeType);
        return new GnssSignalType(constellationType, carrierFrequencyHz, codeType);
    }

    @GnssStatus.ConstellationType
    private final int mConstellationType;
    @FloatRange(from = 0.0f, fromInclusive = false)
    private final double mCarrierFrequencyHz;
    @NonNull
    private final String mCodeType;

    /**
     * Creates a {@link GnssSignalType} with a full list of parameters.
     */
    private GnssSignalType(@GnssStatus.ConstellationType int constellationType,
            double carrierFrequencyHz, @NonNull String codeType) {
        this.mConstellationType = constellationType;
        this.mCarrierFrequencyHz = carrierFrequencyHz;
        this.mCodeType = codeType;
    }

    /** Returns the {@link GnssStatus.ConstellationType}. */
    @GnssStatus.ConstellationType
    public int getConstellationType() {
        return mConstellationType;
    }

    /** Returns the carrier frequency in Hz. */
    @FloatRange(from = 0.0f, fromInclusive = false)
    public double getCarrierFrequencyHz() {
        return mCarrierFrequencyHz;
    }

    /**
     * Return the code type.
     *
     * @see GnssMeasurement#getCodeType()
     */
    @NonNull
    public String getCodeType() {
        return mCodeType;
    }

    @NonNull
    public static final Parcelable.Creator<GnssSignalType> CREATOR =
            new Parcelable.Creator<GnssSignalType>() {
                @Override
                @NonNull
                public GnssSignalType createFromParcel(@NonNull Parcel parcel) {
                    return new GnssSignalType(parcel.readInt(), parcel.readDouble(),
                            parcel.readString());
                }

                @Override
                public GnssSignalType[] newArray(int i) {
                    return new GnssSignalType[i];
                }
            };

    @Override
    public void writeToParcel(@NonNull Parcel parcel, int flags) {
        parcel.writeInt(mConstellationType);
        parcel.writeDouble(mCarrierFrequencyHz);
        parcel.writeString(mCodeType);
    }

    @NonNull
    @Override
    public String toString() {
        StringBuilder s = new StringBuilder();
        s.append("GnssSignalType[");
        s.append(" Constellation=").append(mConstellationType);
        s.append(", CarrierFrequencyHz=").append(mCarrierFrequencyHz);
        s.append(", CodeType=").append(mCodeType);
        s.append(']');
        return s.toString();
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (obj instanceof GnssSignalType) {
            GnssSignalType other = (GnssSignalType) obj;
            return mConstellationType == other.mConstellationType
                    && Double.compare(mCarrierFrequencyHz, other.mCarrierFrequencyHz) == 0
                    && mCodeType.equals(other.mCodeType);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mConstellationType, mCarrierFrequencyHz, mCodeType);
    }

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