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

Commit 2119ade6 authored by John Wang's avatar John Wang Committed by Android (Google) Code Review
Browse files

Merge "Enhance Cell Location Api."

parents 818e7e9c 963db55d
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.CellInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Slog;
@@ -107,6 +108,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {

    private int mOtaspMode = ServiceStateTracker.OTASP_UNKNOWN;

    private CellInfo mCellInfo = null;

    static final int PHONE_STATE_PERMISSION_MASK =
                PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
                PhoneStateListener.LISTEN_CALL_STATE |
@@ -236,6 +239,13 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
                            remove(r.binder);
                        }
                    }
                    if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
                        try {
                            r.callback.onCellInfoChanged(new CellInfo(mCellInfo));
                        } catch (RemoteException ex) {
                            remove(r.binder);
                        }
                    }
                }
            }
        } else {
@@ -325,6 +335,26 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
        broadcastSignalStrengthChanged(signalStrength);
    }

    public void notifyCellInfo(CellInfo cellInfo) {
        if (!checkNotifyPermission("notifyCellInfo()")) {
            return;
        }

        synchronized (mRecords) {
            mCellInfo = cellInfo;
            for (Record r : mRecords) {
                if ((r.events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
                    try {
                        r.callback.onCellInfoChanged(new CellInfo(cellInfo));
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
            handleRemoveListLocked();
        }
    }

    public void notifyMessageWaitingChanged(boolean mwi) {
        if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
            return;
@@ -530,6 +560,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
            pw.println("  mDataConnectionLinkProperties=" + mDataConnectionLinkProperties);
            pw.println("  mDataConnectionLinkCapabilities=" + mDataConnectionLinkCapabilities);
            pw.println("  mCellLocation=" + mCellLocation);
            pw.println("  mCellInfo=" + mCellInfo);
            pw.println("registrations: count=" + recordCount);
            for (Record r : mRecords) {
                pw.println("  " + r.pkgForDebug + " 0x" + Integer.toHexString(r.events));
@@ -655,6 +686,12 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {

        }

        if ((events & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.ACCESS_COARSE_LOCATION, null);

        }

        if ((events & PHONE_STATE_PERMISSION_MASK) != 0) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.READ_PHONE_STATE, null);
+164 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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.os.Parcel;
import android.os.Parcelable;

/**
 * CellIdentity is to represent a unique CDMA cell
 *
 * @hide pending API review
 */
public final class CdmaCellIdentity extends CellIdentity implements Parcelable {
    // Network Id 0..65535
    private final int mNetworkId;
    // CDMA System Id 0..32767
    private final int mSystemId;
    // Base Station Id 0..65535
    private final int mBasestationId;
    /**
     * Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
     * It is represented in units of 0.25 seconds and ranges from -2592000
     * to 2592000, both values inclusive (corresponding to a range of -180
     * to +180 degrees).
     */
    private final int mLongitude;
    /**
     * Latitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
     * It is represented in units of 0.25 seconds and ranges from -1296000
     * to 1296000, both values inclusive (corresponding to a range of -90
     * to +90 degrees).
     */
    private final int mLatitude;

    /**
     * public constructor
     * @param nid Network Id 0..65535
     * @param sid CDMA System Id 0..32767
     * @param bid Base Station Id 0..65535
     * @param lon Longitude is a decimal number ranges from -2592000
     *        to 2592000
     * @param lat Latitude is a decimal number ranges from -1296000
     *        to 1296000
     * @param attr is comma separated “key=value” attribute pairs.
     */
    public CdmaCellIdentity (int nid, int sid,
            int bid, int lon, int lat, String attr) {
        super(CELLID_TYPE_CDMA, attr);
        mNetworkId = nid;
        mSystemId = sid;
        mBasestationId = bid;
        mLongitude = lon;
        mLatitude = lat;
    }

    private CdmaCellIdentity(Parcel in) {
        super(in);
        mNetworkId = in.readInt();
        mSystemId = in.readInt();
        mBasestationId = in.readInt();
        mLongitude = in.readInt();
        mLatitude = in.readInt();
    }

    CdmaCellIdentity(CdmaCellIdentity cid) {
        super(cid);
        mNetworkId = cid.mNetworkId;
        mSystemId = cid.mSystemId;
        mBasestationId = cid.mBasestationId;
        mLongitude = cid.mLongitude;
        mLatitude = cid.mLatitude;
    }

    /**
     * @return Network Id 0..65535
     */
    public int getNetworkId() {
        return mNetworkId;
    }

    /**
     * @return System Id 0..32767
     */
    public int getSystemId() {
        return mSystemId;
    }

    /**
     * @return Base Station Id 0..65535
     */
    public int getBasestationId() {
        return mBasestationId;
    }

    /**
     * @return Base station longitude, which is a decimal number as
     * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
     * of 0.25 seconds and ranges from -2592000 to 2592000, both
     * values inclusive (corresponding to a range of -180
     * to +180 degrees).
     */
    public int getLongitude() {
        return mLongitude;
    }

    /**
     * @return Base station
     */
    /**
     * @return Base station latitude, which is a decimal number as
     * specified in 3GPP2 C.S0005-A v6.0. It is represented in units
     * of 0.25 seconds and ranges from -1296000 to 1296000, both
     * values inclusive (corresponding to a range of -90
     * to +90 degrees).
     */
    public int getLatitude() {
        return mLatitude;
    }

    /** Implement the Parcelable interface {@hide} */
    @Override
    public int describeContents() {
        return 0;
    }

    /** Implement the Parcelable interface {@hide} */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeInt(mNetworkId);
        dest.writeInt(mSystemId);
        dest.writeInt(mBasestationId);
        dest.writeInt(mLongitude);
        dest.writeInt(mLatitude);
    }

    /** Implement the Parcelable interface {@hide} */
    public static final Creator<CdmaCellIdentity> CREATOR =
            new Creator<CdmaCellIdentity>() {
        @Override
        public CdmaCellIdentity createFromParcel(Parcel in) {
            return new CdmaCellIdentity(in);
        }

        @Override
        public CdmaCellIdentity[] newArray(int size) {
            return new CdmaCellIdentity[size];
        }
    };
}
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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.os.Parcel;
import android.os.Parcelable;

/**
 * CellIdentity is to represent ONE unique cell in the world
 * it contains all levels of info to identity country, carrier, etc.
 *
 * @hide pending API review
 */
public abstract class CellIdentity implements Parcelable {

    // Cell is a GSM Cell {@link GsmCellIdentity}
    public static final int CELLID_TYPE_GSM = 1;
    // Cell is a CMDA Cell {@link CdmaCellIdentity}
    public static final int CELLID_TYPE_CDMA = 2;
    // Cell is a LTE Cell {@link LteCellIdentity}
    public static final int CELLID_TYPE_LTE = 3;

    private int mCellIdType;
    private String mCellIdAttributes;

    protected CellIdentity(int type, String attr) {
        this.mCellIdType = type;
        this.mCellIdAttributes = new String(attr);
    }

    protected CellIdentity(Parcel in) {
        this.mCellIdType = in.readInt();
        this.mCellIdAttributes = new String(in.readString());
    }

    protected CellIdentity(CellIdentity cid) {
        this.mCellIdType = cid.mCellIdType;
        this.mCellIdAttributes = new String(cid.mCellIdAttributes);
    }

    /**
     * @return Cell Identity type as one of CELLID_TYPE_XXXX
     */
    public int getCellIdType() {
        return mCellIdType;
    }


    /**
     * @return Cell identity attribute pairs
     * Comma separated “key=value” pairs.
     *   key := must must an single alpha-numeric word
     *   value := “quoted value string”
     *
     * Current list of keys and values:
     *   type = fixed | mobile
     */
    public String getCellIdAttributes() {
        return mCellIdAttributes;
    }


    /** Implement the Parcelable interface {@hide} */
    @Override
    public int describeContents() {
        return 0;
    }

    /** Implement the Parcelable interface {@hide} */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mCellIdType);
        dest.writeString(mCellIdAttributes);
    }
}
+20 −0
Original line number Diff line number Diff line
/*
**
** Copyright 2007, 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 CellInfo;
 No newline at end of file
+218 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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.os.Parcel;
import android.os.Parcelable;

/**
 * Represent one snapshot observation of one cell info
 * which contains the time of observation.
 *
 * @hide Pending API review
 */
public final class CellInfo implements Parcelable {
    // Type to distinguish where time stamp gets recorded.
    public static final int CELL_INFO_TIMESTAMP_TYPE_UNKNOWN = 0;
    public static final int CELL_INFO_TIMESTAMP_TYPE_ANTENNA = 1;
    public static final int CELL_INFO_TIMESTAMP_TYPE_MODEM = 2;
    public static final int CELL_INFO_TIMESTAMP_TYPE_OEM_RIL = 3;
    public static final int CELL_INFO_TIMESTAMP_TYPE_JAVA_RIL = 4;

    // Observation time stamped as type in nanoseconds since boot
    private final long mTimeStamp;
    // Where time stamp gets recorded.
    // Value of CELL_INFO_TIMESTAMP_TYPE_XXXX
    private final int mTimeStampType;

    private final boolean mRegistered;

    private final SignalStrength mStrength;
    private final long mTimingAdvance;

    private final int mCellIdentityType;
    private final CellIdentity mCellIdentity;

    /**
     * Public constructor
     * @param timeStampType is one of CELL_INFO_TIMESTAMP_TYPE_XXXX
     * @param timeStamp is observation time in nanoseconds since boot
     * @param timingAdv is observed timing advance
     * @param registered is true when register to this cellIdentity
     * @param strength is observed signal strength
     * @param cellIdentity is observed mobile cell
     */
    public CellInfo(int timeStampType, long timeStamp, long timingAdv,
            boolean registered, SignalStrength strength,
            CellIdentity cellIdentity) {

        if (timeStampType < CELL_INFO_TIMESTAMP_TYPE_UNKNOWN ||
                timeStampType > CELL_INFO_TIMESTAMP_TYPE_JAVA_RIL) {
            mTimeStampType = CELL_INFO_TIMESTAMP_TYPE_UNKNOWN;
        } else {
            mTimeStampType = timeStampType;
        }

        mRegistered = registered;
        mTimeStamp = timeStamp;
        mTimingAdvance = timingAdv;
        mStrength = new SignalStrength(strength);

        mCellIdentityType = cellIdentity.getCellIdType();
        // TODO: make defense copy
        mCellIdentity = cellIdentity;
    }

    public CellInfo(CellInfo ci) {
        this.mTimeStampType = ci.mTimeStampType;
        this.mRegistered = ci.mRegistered;
        this.mTimeStamp = ci.mTimeStamp;
        this.mTimingAdvance = ci.mTimingAdvance;
        this.mCellIdentityType = ci.mCellIdentityType;
        this.mStrength = new SignalStrength(ci.mStrength);
        switch(mCellIdentityType) {
            case CellIdentity.CELLID_TYPE_GSM:
                mCellIdentity = new GsmCellIdentity((GsmCellIdentity)ci.mCellIdentity);
                break;
            default:
                mCellIdentity = null;
        }
    }

    private CellInfo(Parcel in) {
        mTimeStampType = in.readInt();
        mRegistered = (in.readInt() == 1) ? true : false;
        mTimeStamp = in.readLong();
        mTimingAdvance = in.readLong();
        mCellIdentityType = in.readInt();
        mStrength = SignalStrength.CREATOR.createFromParcel(in);
        switch(mCellIdentityType) {
            case CellIdentity.CELLID_TYPE_GSM:
                mCellIdentity = GsmCellIdentity.CREATOR.createFromParcel(in);
                break;
            default:
                mCellIdentity = null;
        }
    }

    /**
     * @return the observation time in nanoseconds since boot
     */
    public long getTimeStamp() {
        return mTimeStamp;
    }

    /**
     * @return Where time stamp gets recorded.
     * one of CELL_INFO_TIMESTAMP_TYPE_XXXX
     */
    public int getTimeStampType() {
        return mTimeStampType;
    }

    /**
     * @return true when register to this cellIdentity
     */
    public boolean isRegistered() {
        return mRegistered;
    }

    /**
     * @return observed timing advance
     */
    public long getTimingAdvance() {
        return mTimingAdvance;
    }

    /**
     * @return observed signal strength
     */
    public SignalStrength getSignalStrength() {
        // make a defense copy
        return new SignalStrength(mStrength);
    }

    /**
     * @return observed cell identity
     */
    public CellIdentity getCellIdentity() {
        // TODO: make a defense copy
        return mCellIdentity;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();

        sb.append("TimeStampType: ");
        switch(mTimeStampType) {
            case 1:
                sb.append("antenna");
                break;
            case 2:
                sb.append("modem");
                break;
            case 3:
                sb.append("oem_ril");
                break;
            case 4:
                sb.append("java_ril");
                break;
            default:
                sb.append("unknown");
        }
        sb.append(", TimeStamp: ").append(mTimeStamp).append(" ns");
        sb.append(", Registered: ").append(mRegistered ? "YES" : "NO");
        sb.append(", TimingAdvance: ").append(mTimingAdvance);
        sb.append(", Strength : " + mStrength);
        sb.append(", Cell Iden: " + mCellIdentity);

        return sb.toString();
    }

    /** Implement the Parcelable interface {@hide} */
    @Override
    public int describeContents() {
        return 0;
    }

    /** Implement the Parcelable interface {@hide} */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mTimeStampType);
        dest.writeInt(mRegistered ? 1 : 0);
        dest.writeLong(mTimeStamp);
        dest.writeLong(mTimingAdvance);
        dest.writeInt(mCellIdentityType);
        mStrength.writeToParcel(dest, flags);
        mCellIdentity.writeToParcel(dest, flags);
    }

    /** Implement the Parcelable interface {@hide} */
    public static final Creator<CellInfo> CREATOR =
            new Creator<CellInfo>() {
        @Override
        public CellInfo createFromParcel(Parcel in) {
            return new CellInfo(in);
        }

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