Merge "Return copies for get methods" into qt-dev

This commit is contained in:
Jack Yu
2019-04-18 12:42:12 +00:00
committed by Android (Google) Code Review
4 changed files with 98 additions and 33 deletions

View File

@@ -95,6 +95,21 @@ public final class DataSpecificRegistrationInfo implements Parcelable {
this.mIsUsingCarrierAggregation = isUsingCarrierAggregation; this.mIsUsingCarrierAggregation = isUsingCarrierAggregation;
} }
/**
* Constructor from another data specific registration info
*
* @param dsri another data specific registration info
* @hide
*/
DataSpecificRegistrationInfo(DataSpecificRegistrationInfo dsri) {
maxDataCalls = dsri.maxDataCalls;
isDcNrRestricted = dsri.isDcNrRestricted;
isNrAvailable = dsri.isNrAvailable;
isEnDcAvailable = dsri.isEnDcAvailable;
mLteVopsSupportInfo = dsri.mLteVopsSupportInfo;
mIsUsingCarrierAggregation = dsri.mIsUsingCarrierAggregation;
}
private DataSpecificRegistrationInfo(Parcel source) { private DataSpecificRegistrationInfo(Parcel source) {
maxDataCalls = source.readInt(); maxDataCalls = source.readInt();
isDcNrRestricted = source.readBoolean(); isDcNrRestricted = source.readBoolean();

View File

@@ -279,6 +279,39 @@ public final class NetworkRegistrationInfo implements Parcelable {
mNrState = source.readInt(); mNrState = source.readInt();
} }
/**
* Constructor from another network registration info
*
* @param nri Another network registration info
* @hide
*/
public NetworkRegistrationInfo(NetworkRegistrationInfo nri) {
mDomain = nri.mDomain;
mTransportType = nri.mTransportType;
mRegistrationState = nri.mRegistrationState;
mRoamingType = nri.mRoamingType;
mAccessNetworkTechnology = nri.mAccessNetworkTechnology;
mRejectCause = nri.mRejectCause;
mEmergencyOnly = nri.mEmergencyOnly;
mAvailableServices = new ArrayList<>(nri.mAvailableServices);
if (nri.mCellIdentity != null) {
Parcel p = Parcel.obtain();
nri.mCellIdentity.writeToParcel(p, 0);
p.setDataPosition(0);
// TODO: Instead of doing this, we should create a formal way for cloning cell identity.
// Cell identity is not an immutable object so we have to deep copy it.
mCellIdentity = CellIdentity.CREATOR.createFromParcel(p);
}
if (nri.mVoiceSpecificInfo != null) {
mVoiceSpecificInfo = new VoiceSpecificRegistrationInfo(nri.mVoiceSpecificInfo);
}
if (nri.mDataSpecificInfo != null) {
mDataSpecificInfo = new DataSpecificRegistrationInfo(nri.mDataSpecificInfo);
}
mNrState = nri.mNrState;
}
/** /**
* @return The transport type. * @return The transport type.
*/ */

View File

@@ -421,7 +421,7 @@ public class ServiceState implements Parcelable {
Arrays.copyOf(s.mCellBandwidths, s.mCellBandwidths.length); Arrays.copyOf(s.mCellBandwidths, s.mCellBandwidths.length);
mLteEarfcnRsrpBoost = s.mLteEarfcnRsrpBoost; mLteEarfcnRsrpBoost = s.mLteEarfcnRsrpBoost;
mNetworkRegistrationInfos = s.mNetworkRegistrationInfos == null ? null : mNetworkRegistrationInfos = s.mNetworkRegistrationInfos == null ? null :
new ArrayList<>(s.mNetworkRegistrationInfos); s.getNetworkRegistrationInfoList();
mNrFrequencyRange = s.mNrFrequencyRange; mNrFrequencyRange = s.mNrFrequencyRange;
mOperatorAlphaLongRaw = s.mOperatorAlphaLongRaw; mOperatorAlphaLongRaw = s.mOperatorAlphaLongRaw;
mOperatorAlphaShortRaw = s.mOperatorAlphaShortRaw; mOperatorAlphaShortRaw = s.mOperatorAlphaShortRaw;
@@ -1130,16 +1130,16 @@ public class ServiceState implements Parcelable {
/** @hide */ /** @hide */
@TestApi @TestApi
public void setVoiceRoamingType(@RoamingType int type) { public void setVoiceRoamingType(@RoamingType int type) {
NetworkRegistrationInfo regState = getNetworkRegistrationInfo( NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
if (regState == null) { if (regInfo == null) {
regState = new NetworkRegistrationInfo.Builder() regInfo = new NetworkRegistrationInfo.Builder()
.setDomain(NetworkRegistrationInfo.DOMAIN_CS) .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
.setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
.build(); .build();
addNetworkRegistrationInfo(regState);
} }
regState.setRoamingType(type); regInfo.setRoamingType(type);
addNetworkRegistrationInfo(regInfo);
} }
/** @hide */ /** @hide */
@@ -1151,16 +1151,16 @@ public class ServiceState implements Parcelable {
/** @hide */ /** @hide */
@TestApi @TestApi
public void setDataRoamingType(@RoamingType int type) { public void setDataRoamingType(@RoamingType int type) {
NetworkRegistrationInfo regState = getNetworkRegistrationInfo( NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
if (regState == null) { if (regInfo == null) {
regState = new NetworkRegistrationInfo.Builder() regInfo = new NetworkRegistrationInfo.Builder()
.setDomain(NetworkRegistrationInfo.DOMAIN_PS) .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
.setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
.build(); .build();
addNetworkRegistrationInfo(regState);
} }
regState.setRoamingType(type); regInfo.setRoamingType(type);
addNetworkRegistrationInfo(regInfo);
} }
/** /**
@@ -1324,16 +1324,16 @@ public class ServiceState implements Parcelable {
Rlog.e(LOG_TAG, "ServiceState.setRilVoiceRadioTechnology() called. It's encouraged to " Rlog.e(LOG_TAG, "ServiceState.setRilVoiceRadioTechnology() called. It's encouraged to "
+ "use addNetworkRegistrationInfo() instead *******"); + "use addNetworkRegistrationInfo() instead *******");
// Sync to network registration state // Sync to network registration state
NetworkRegistrationInfo regState = getNetworkRegistrationInfo( NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
if (regState == null) { if (regInfo == null) {
regState = new NetworkRegistrationInfo.Builder() regInfo = new NetworkRegistrationInfo.Builder()
.setDomain(NetworkRegistrationInfo.DOMAIN_CS) .setDomain(NetworkRegistrationInfo.DOMAIN_CS)
.setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
.build(); .build();
addNetworkRegistrationInfo(regState);
} }
regState.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt)); regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt));
addNetworkRegistrationInfo(regInfo);
} }
@@ -1345,17 +1345,17 @@ public class ServiceState implements Parcelable {
// Sync to network registration state. Always write down the WWAN transport. For AP-assisted // Sync to network registration state. Always write down the WWAN transport. For AP-assisted
// mode device, use addNetworkRegistrationInfo() to set the correct transport if RAT // mode device, use addNetworkRegistrationInfo() to set the correct transport if RAT
// is IWLAN. // is IWLAN.
NetworkRegistrationInfo regState = getNetworkRegistrationInfo( NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
if (regState == null) { if (regInfo == null) {
regState = new NetworkRegistrationInfo.Builder() regInfo = new NetworkRegistrationInfo.Builder()
.setDomain(NetworkRegistrationInfo.DOMAIN_PS) .setDomain(NetworkRegistrationInfo.DOMAIN_PS)
.setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) .setTransportType(AccessNetworkConstants.TRANSPORT_TYPE_WWAN)
.build(); .build();
addNetworkRegistrationInfo(regState);
} }
regState.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt)); regInfo.setAccessNetworkTechnology(rilRadioTechnologyToNetworkType(rt));
addNetworkRegistrationInfo(regInfo);
} }
/** @hide */ /** @hide */
@@ -1397,10 +1397,10 @@ public class ServiceState implements Parcelable {
* @hide * @hide
*/ */
public @NRState int getNrState() { public @NRState int getNrState() {
final NetworkRegistrationInfo regState = getNetworkRegistrationInfo( final NetworkRegistrationInfo regInfo = getNetworkRegistrationInfo(
NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
if (regState == null) return NetworkRegistrationInfo.NR_STATE_NONE; if (regInfo == null) return NetworkRegistrationInfo.NR_STATE_NONE;
return regState.getNrState(); return regInfo.getNrState();
} }
/** /**
@@ -1794,7 +1794,11 @@ public class ServiceState implements Parcelable {
@SystemApi @SystemApi
public List<NetworkRegistrationInfo> getNetworkRegistrationInfoList() { public List<NetworkRegistrationInfo> getNetworkRegistrationInfoList() {
synchronized (mNetworkRegistrationInfos) { synchronized (mNetworkRegistrationInfos) {
return new ArrayList<>(mNetworkRegistrationInfos); List<NetworkRegistrationInfo> newList = new ArrayList<>();
for (NetworkRegistrationInfo nri : mNetworkRegistrationInfos) {
newList.add(new NetworkRegistrationInfo(nri));
}
return newList;
} }
} }
@@ -1814,7 +1818,7 @@ public class ServiceState implements Parcelable {
synchronized (mNetworkRegistrationInfos) { synchronized (mNetworkRegistrationInfos) {
for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) { for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
if (networkRegistrationInfo.getTransportType() == transportType) { if (networkRegistrationInfo.getTransportType() == transportType) {
list.add(networkRegistrationInfo); list.add(new NetworkRegistrationInfo(networkRegistrationInfo));
} }
} }
} }
@@ -1838,7 +1842,7 @@ public class ServiceState implements Parcelable {
synchronized (mNetworkRegistrationInfos) { synchronized (mNetworkRegistrationInfos) {
for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) { for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
if (networkRegistrationInfo.getDomain() == domain) { if (networkRegistrationInfo.getDomain() == domain) {
list.add(networkRegistrationInfo); list.add(new NetworkRegistrationInfo(networkRegistrationInfo));
} }
} }
} }
@@ -1863,7 +1867,7 @@ public class ServiceState implements Parcelable {
for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) { for (NetworkRegistrationInfo networkRegistrationInfo : mNetworkRegistrationInfos) {
if (networkRegistrationInfo.getTransportType() == transportType if (networkRegistrationInfo.getTransportType() == transportType
&& networkRegistrationInfo.getDomain() == domain) { && networkRegistrationInfo.getDomain() == domain) {
return networkRegistrationInfo; return new NetworkRegistrationInfo(networkRegistrationInfo);
} }
} }
} }
@@ -1875,20 +1879,20 @@ public class ServiceState implements Parcelable {
* @hide * @hide
*/ */
@TestApi @TestApi
public void addNetworkRegistrationInfo(NetworkRegistrationInfo regState) { public void addNetworkRegistrationInfo(NetworkRegistrationInfo nri) {
if (regState == null) return; if (nri == null) return;
synchronized (mNetworkRegistrationInfos) { synchronized (mNetworkRegistrationInfos) {
for (int i = 0; i < mNetworkRegistrationInfos.size(); i++) { for (int i = 0; i < mNetworkRegistrationInfos.size(); i++) {
NetworkRegistrationInfo curRegState = mNetworkRegistrationInfos.get(i); NetworkRegistrationInfo curRegState = mNetworkRegistrationInfos.get(i);
if (curRegState.getTransportType() == regState.getTransportType() if (curRegState.getTransportType() == nri.getTransportType()
&& curRegState.getDomain() == regState.getDomain()) { && curRegState.getDomain() == nri.getDomain()) {
mNetworkRegistrationInfos.remove(i); mNetworkRegistrationInfos.remove(i);
break; break;
} }
} }
mNetworkRegistrationInfos.add(regState); mNetworkRegistrationInfos.add(new NetworkRegistrationInfo(nri));
} }
} }

View File

@@ -65,6 +65,19 @@ public class VoiceSpecificRegistrationInfo implements Parcelable{
this.defaultRoamingIndicator = defaultRoamingIndicator; this.defaultRoamingIndicator = defaultRoamingIndicator;
} }
/**
* Constructor from another voice specific registration info
*
* @param vsri another voice specific registration info
* @hide
*/
VoiceSpecificRegistrationInfo(VoiceSpecificRegistrationInfo vsri) {
cssSupported = vsri.cssSupported;
roamingIndicator = vsri.roamingIndicator;
systemIsInPrl = vsri.systemIsInPrl;
defaultRoamingIndicator = vsri.defaultRoamingIndicator;
}
private VoiceSpecificRegistrationInfo(Parcel source) { private VoiceSpecificRegistrationInfo(Parcel source) {
this.cssSupported = source.readBoolean(); this.cssSupported = source.readBoolean();
this.roamingIndicator = source.readInt(); this.roamingIndicator = source.readInt();