Add Callback to notify changes of barring status am: 61b5d6741b

Change-Id: Ib306f821c9f37a5f4c3df39ed75386768f8c9160
This commit is contained in:
Nathan Harold
2020-03-19 00:08:24 +00:00
committed by Automerger Merge Worker
11 changed files with 578 additions and 0 deletions

View File

@@ -44680,6 +44680,38 @@ package android.telephony {
field public static final int PRIORITY_MED = 2; // 0x2
}
public final class BarringInfo implements android.os.Parcelable {
method public int describeContents();
method @NonNull public android.telephony.BarringInfo.BarringServiceInfo getBarringServiceInfo(int);
method public boolean isServiceBarred(int);
method public void writeToParcel(@NonNull android.os.Parcel, int);
field public static final int BARRING_SERVICE_TYPE_CS_FALLBACK = 5; // 0x5
field public static final int BARRING_SERVICE_TYPE_CS_SERVICE = 0; // 0x0
field public static final int BARRING_SERVICE_TYPE_CS_VOICE = 2; // 0x2
field public static final int BARRING_SERVICE_TYPE_EMERGENCY = 8; // 0x8
field public static final int BARRING_SERVICE_TYPE_MMTEL_VIDEO = 7; // 0x7
field public static final int BARRING_SERVICE_TYPE_MMTEL_VOICE = 6; // 0x6
field public static final int BARRING_SERVICE_TYPE_MO_DATA = 4; // 0x4
field public static final int BARRING_SERVICE_TYPE_MO_SIGNALLING = 3; // 0x3
field public static final int BARRING_SERVICE_TYPE_PS_SERVICE = 1; // 0x1
field public static final int BARRING_SERVICE_TYPE_SMS = 9; // 0x9
field @NonNull public static final android.os.Parcelable.Creator<android.telephony.BarringInfo> CREATOR;
}
public static final class BarringInfo.BarringServiceInfo implements android.os.Parcelable {
method public int describeContents();
method public int getBarringType();
method public int getConditionalBarringFactor();
method public int getConditionalBarringTimeSeconds();
method public boolean isBarred();
method public boolean isConditionallyBarred();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field public static final int BARRING_TYPE_CONDITIONAL = 1; // 0x1
field public static final int BARRING_TYPE_NONE = 0; // 0x0
field public static final int BARRING_TYPE_UNCONDITIONAL = 2; // 0x2
field @NonNull public static final android.os.Parcelable.Creator<android.telephony.BarringInfo.BarringServiceInfo> CREATOR;
}
public class CarrierConfigManager {
method @Nullable public android.os.PersistableBundle getConfig();
method @Nullable public android.os.PersistableBundle getConfigByComponentForSubId(@NonNull String, int);
@@ -45442,6 +45474,7 @@ package android.telephony {
ctor public PhoneStateListener();
ctor public PhoneStateListener(@NonNull java.util.concurrent.Executor);
method public void onActiveDataSubscriptionIdChanged(int);
method public void onBarringInfoChanged(@NonNull android.telephony.BarringInfo);
method @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public void onCallDisconnectCauseChanged(int, int);
method public void onCallForwardingIndicatorChanged(boolean);
method public void onCallStateChanged(int, String);
@@ -45460,6 +45493,7 @@ package android.telephony {
method public void onSignalStrengthsChanged(android.telephony.SignalStrength);
method public void onUserMobileDataStateChanged(boolean);
field public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 4194304; // 0x400000
field @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public static final int LISTEN_BARRING_INFO = -2147483648; // 0x80000000
field @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public static final int LISTEN_CALL_DISCONNECT_CAUSES = 33554432; // 0x2000000
field public static final int LISTEN_CALL_FORWARDING_INDICATOR = 8; // 0x8
field public static final int LISTEN_CALL_STATE = 32; // 0x20

View File

@@ -8169,6 +8169,11 @@ package android.telephony {
field public static final int FREQUENCY_RANGE_GROUP_UNKNOWN = 0; // 0x0
}
public final class BarringInfo implements android.os.Parcelable {
ctor public BarringInfo();
method @NonNull public android.telephony.BarringInfo createLocationInfoSanitizedCopy();
}
public final class CallAttributes implements android.os.Parcelable {
ctor public CallAttributes(@NonNull android.telephony.PreciseCallState, int, @NonNull android.telephony.CallQuality);
method public int describeContents();

View File

@@ -3098,6 +3098,15 @@ package android.telephony {
field public static final int FREQUENCY_RANGE_GROUP_UNKNOWN = 0; // 0x0
}
public final class BarringInfo implements android.os.Parcelable {
ctor public BarringInfo();
ctor public BarringInfo(@Nullable android.telephony.CellIdentity, @NonNull android.util.SparseArray<android.telephony.BarringInfo.BarringServiceInfo>);
}
public static final class BarringInfo.BarringServiceInfo implements android.os.Parcelable {
ctor public BarringInfo.BarringServiceInfo(int, boolean, int, int);
}
public final class CallQuality implements android.os.Parcelable {
ctor public CallQuality(int, int, int, int, int, int, int, int, int, int, int);
ctor public CallQuality(int, int, int, int, int, int, int, int, int, int, int, boolean, boolean, boolean);

View File

@@ -427,6 +427,17 @@ public class PhoneStateListener {
@RequiresPermission(Manifest.permission.READ_PHONE_STATE)
public static final int LISTEN_REGISTRATION_FAILURE = 0x40000000;
/**
* Listen for Barring Information for the current registered / camped cell.
*
* <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling
* app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
*
* @see #onBarringInfoChanged()
*/
@RequiresPermission(Manifest.permission.READ_PHONE_STATE)
public static final int LISTEN_BARRING_INFO = 0x80000000;
/*
* Subscription used to listen to the phone state changes
* @hide
@@ -1035,6 +1046,20 @@ public class PhoneStateListener {
// default implementation empty
}
/**
* Report updated barring information for the current camped/registered cell.
*
* <p>Barring info is provided for all services applicable to the current camped/registered
* cell, for the registered PLMN and current access class/access category.
*
* @param barringInfo for all services on the current cell.
*
* @see android.telephony.BarringInfo
*/
public void onBarringInfoChanged(@NonNull BarringInfo barringInfo) {
// default implementation empty
}
/**
* The callback methods need to be called on the handler thread where
* this object was created. If the binder did that for us it'd be nice.
@@ -1328,6 +1353,14 @@ public class PhoneStateListener {
cellIdentity, chosenPlmn, domain, causeCode, additionalCauseCode)));
// default implementation empty
}
public void onBarringInfoChanged(BarringInfo barringInfo) {
PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
if (psl == null) return;
Binder.withCleanCallingIdentity(
() -> mExecutor.execute(() -> psl.onBarringInfoChanged(barringInfo)));
}
}

View File

@@ -729,4 +729,21 @@ public class TelephonyRegistryManager {
} catch (RemoteException ex) {
}
}
/**
* Notify {@link BarringInfo} has changed for a specific subscription.
*
* @param slotIndex for the phone object that got updated barring info.
* @param subId for which the BarringInfo changed.
* @param barringInfo updated BarringInfo.
*/
public void notifyBarringInfoChanged(
int slotIndex, int subId, @NonNull BarringInfo barringInfo) {
try {
sRegistry.notifyBarringInfoChanged(slotIndex, subId, barringInfo);
} catch (RemoteException ex) {
// system server crash
}
}
}

View File

@@ -16,6 +16,7 @@
package com.android.internal.telephony;
import android.telephony.BarringInfo;
import android.telephony.CallAttributes;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
@@ -66,4 +67,5 @@ oneway interface IPhoneStateListener {
void onImsCallDisconnectCauseChanged(in ImsReasonInfo imsReasonInfo);
void onRegistrationFailed(in CellIdentity cellIdentity,
String chosenPlmn, int domain, int causeCode, int additionalCauseCode);
void onBarringInfoChanged(in BarringInfo barringInfo);
}

View File

@@ -19,6 +19,7 @@ package com.android.internal.telephony;
import android.content.Intent;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
import android.telephony.BarringInfo;
import android.telephony.CallQuality;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
@@ -102,4 +103,5 @@ interface ITelephonyRegistry {
void notifyImsDisconnectCause(int subId, in ImsReasonInfo imsReasonInfo);
void notifyRegistrationFailed(int slotIndex, int subId, in CellIdentity cellIdentity,
String chosenPlmn, int domain, int causeCode, int additionalCauseCode);
void notifyBarringInfoChanged(int slotIndex, int subId, in BarringInfo barringInfo);
}

View File

@@ -45,6 +45,7 @@ import android.telephony.Annotation;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SrvccState;
import android.telephony.BarringInfo;
import android.telephony.CallAttributes;
import android.telephony.CallQuality;
import android.telephony.CellIdentity;
@@ -258,6 +259,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
private int[] mCallPreciseDisconnectCause;
private List<BarringInfo> mBarringInfo = null;
private boolean mCarrierNetworkChangeState = false;
private PhoneCapability mPhoneCapability = null;
@@ -451,6 +454,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
cutListToSize(mCellInfo, mNumPhones);
cutListToSize(mImsReasonInfo, mNumPhones);
cutListToSize(mPreciseDataConnectionStates, mNumPhones);
cutListToSize(mBarringInfo, mNumPhones);
return;
}
@@ -483,6 +487,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
mPreciseDataConnectionStates.add(new HashMap<String, PreciseDataConnectionState>());
mDisplayInfos[i] = null;
mBarringInfo.add(i, new BarringInfo());
}
}
@@ -541,6 +546,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mOutgoingCallEmergencyNumber = new EmergencyNumber[numPhones];
mOutgoingSmsEmergencyNumber = new EmergencyNumber[numPhones];
mDisplayInfos = new DisplayInfo[numPhones];
mBarringInfo = new ArrayList<>();
for (int i = 0; i < numPhones; i++) {
mCallState[i] = TelephonyManager.CALL_STATE_IDLE;
mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
@@ -569,6 +575,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
mBackgroundCallState[i] = PreciseCallState.PRECISE_CALL_STATE_IDLE;
mPreciseDataConnectionStates.add(new HashMap<String, PreciseDataConnectionState>());
mDisplayInfos[i] = null;
mBarringInfo.add(i, new BarringInfo());
}
mAppOps = mContext.getSystemService(AppOpsManager.class);
@@ -1031,6 +1038,19 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
remove(r.binder);
}
}
if ((events & PhoneStateListener.LISTEN_BARRING_INFO) != 0) {
BarringInfo barringInfo = mBarringInfo.get(phoneId);
BarringInfo biNoLocation = barringInfo != null
? barringInfo.createLocationInfoSanitizedCopy() : null;
if (VDBG) log("listen: call onBarringInfoChanged=" + barringInfo);
try {
r.callback.onBarringInfoChanged(
checkFineLocationAccess(r, Build.VERSION_CODES.R)
? barringInfo : biNoLocation);
} catch (RemoteException ex) {
remove(r.binder);
}
}
}
}
} else {
@@ -2207,6 +2227,52 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
}
}
/**
* Send a notification of changes to barring status to PhoneStateListener registrants.
*
* @param phoneId the phoneId
* @param subId the subId
* @param barringInfo a structure containing the complete updated barring info.
*/
public void notifyBarringInfoChanged(int phoneId, int subId, @NonNull BarringInfo barringInfo) {
if (!checkNotifyPermission("notifyBarringInfo()")) {
return;
}
if (barringInfo == null) {
log("Received null BarringInfo for subId=" + subId + ", phoneId=" + phoneId);
mBarringInfo.set(phoneId, new BarringInfo());
return;
}
synchronized (mRecords) {
if (validatePhoneId(phoneId)) {
mBarringInfo.set(phoneId, barringInfo);
// Barring info is non-null
BarringInfo biNoLocation = barringInfo.createLocationInfoSanitizedCopy();
if (VDBG) log("listen: call onBarringInfoChanged=" + barringInfo);
for (Record r : mRecords) {
if (r.matchPhoneStateListenerEvent(
PhoneStateListener.LISTEN_BARRING_INFO)
&& idMatch(r.subId, subId, phoneId)) {
try {
if (DBG_LOC) {
log("notifyBarringInfo: mBarringInfo="
+ barringInfo + " r=" + r);
}
r.callback.onBarringInfoChanged(
checkFineLocationAccess(r, Build.VERSION_CODES.R)
? barringInfo : biNoLocation);
} catch (RemoteException ex) {
mRemoveList.add(r.binder);
}
}
}
}
handleRemoveListLocked();
}
}
@Override
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
@@ -2247,6 +2313,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
pw.println("mPreciseDataConnectionStates=" + mPreciseDataConnectionStates.get(i));
pw.println("mOutgoingCallEmergencyNumber=" + mOutgoingCallEmergencyNumber[i]);
pw.println("mOutgoingSmsEmergencyNumber=" + mOutgoingSmsEmergencyNumber[i]);
pw.println("mBarringInfo=" + mBarringInfo.get(i));
pw.decreaseIndent();
}
pw.println("mCarrierNetworkChangeState=" + mCarrierNetworkChangeState);

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2019 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.
*/
/** @hide */
package android.telephony;
parcelable BarringInfo;

View File

@@ -0,0 +1,388 @@
/*
* Copyright 2019 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.Nullable;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseArray;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Objects;
/**
* Provides the barring configuration for a particular service type.
*
* Provides indication about the barring of a particular service for use. Certain barring types
* are only valid for certain technology families. Any service that does not have a barring
* configuration is unbarred by default.
*/
public final class BarringInfo implements Parcelable {
/**
* Barring Service Type
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = "BARRING_SERVICE_TYPE_", value = {
BARRING_SERVICE_TYPE_CS_SERVICE,
BARRING_SERVICE_TYPE_PS_SERVICE,
BARRING_SERVICE_TYPE_CS_VOICE,
BARRING_SERVICE_TYPE_MO_SIGNALLING,
BARRING_SERVICE_TYPE_MO_DATA,
BARRING_SERVICE_TYPE_CS_FALLBACK,
BARRING_SERVICE_TYPE_MMTEL_VOICE,
BARRING_SERVICE_TYPE_MMTEL_VIDEO,
BARRING_SERVICE_TYPE_EMERGENCY,
BARRING_SERVICE_TYPE_SMS})
public @interface BarringServiceType {}
/* Applicabe to UTRAN */
/** Barring indicator for circuit-switched service; applicable to UTRAN */
public static final int BARRING_SERVICE_TYPE_CS_SERVICE =
android.hardware.radio.V1_5.BarringServiceType.CS_SERVICE;
/** Barring indicator for packet-switched service; applicable to UTRAN */
public static final int BARRING_SERVICE_TYPE_PS_SERVICE =
android.hardware.radio.V1_5.BarringServiceType.PS_SERVICE;
/** Barring indicator for circuit-switched voice service; applicable to UTRAN */
public static final int BARRING_SERVICE_TYPE_CS_VOICE =
android.hardware.radio.V1_5.BarringServiceType.CS_VOICE;
/* Applicable to EUTRAN, NGRAN */
/** Barring indicator for mobile-originated signalling; applicable to EUTRAN and NGRAN */
public static final int BARRING_SERVICE_TYPE_MO_SIGNALLING =
android.hardware.radio.V1_5.BarringServiceType.MO_SIGNALLING;
/** Barring indicator for mobile-originated data traffic; applicable to EUTRAN and NGRAN */
public static final int BARRING_SERVICE_TYPE_MO_DATA =
android.hardware.radio.V1_5.BarringServiceType.MO_DATA;
/** Barring indicator for circuit-switched fallback for voice; applicable to EUTRAN and NGRAN */
public static final int BARRING_SERVICE_TYPE_CS_FALLBACK =
android.hardware.radio.V1_5.BarringServiceType.CS_FALLBACK;
/** Barring indicator for MMTEL (IMS) voice; applicable to EUTRAN and NGRAN */
public static final int BARRING_SERVICE_TYPE_MMTEL_VOICE =
android.hardware.radio.V1_5.BarringServiceType.MMTEL_VOICE;
/** Barring indicator for MMTEL (IMS) video; applicable to EUTRAN and NGRAN */
public static final int BARRING_SERVICE_TYPE_MMTEL_VIDEO =
android.hardware.radio.V1_5.BarringServiceType.MMTEL_VIDEO;
/* Applicable to UTRAN, EUTRAN, NGRAN */
/** Barring indicator for emergency services; applicable to UTRAN, EUTRAN, and NGRAN */
public static final int BARRING_SERVICE_TYPE_EMERGENCY =
android.hardware.radio.V1_5.BarringServiceType.EMERGENCY;
/** Barring indicator for SMS sending; applicable to UTRAN, EUTRAN, and NGRAN */
public static final int BARRING_SERVICE_TYPE_SMS =
android.hardware.radio.V1_5.BarringServiceType.SMS;
//TODO: add barring constants for Operator-Specific barring codes
/** Describe the current barring configuration of a cell */
public static final class BarringServiceInfo implements Parcelable {
/**
* Barring Type
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = "BARRING_TYPE_", value =
{BARRING_TYPE_NONE,
BARRING_TYPE_UNCONDITIONAL,
BARRING_TYPE_CONDITIONAL})
public @interface BarringType {}
/** Barring is inactive */
public static final int BARRING_TYPE_NONE = android.hardware.radio.V1_5.BarringType.NONE;
/** The service is barred */
public static final int BARRING_TYPE_UNCONDITIONAL =
android.hardware.radio.V1_5.BarringType.UNCONDITIONAL;
/** The service may be barred based on additional factors */
public static final int BARRING_TYPE_CONDITIONAL =
android.hardware.radio.V1_5.BarringType.CONDITIONAL;
private final @BarringType int mBarringType;
private final boolean mIsConditionallyBarred;
private final int mConditionalBarringFactor;
private final int mConditionalBarringTimeSeconds;
/** @hide */
public BarringServiceInfo() {
this(BARRING_TYPE_NONE, false, 0, 0);
}
/** @hide */
@TestApi
public BarringServiceInfo(@BarringType int barringType, boolean isConditionallyBarred,
int conditionalBarringFactor, int conditionalBarringTimeSeconds) {
mBarringType = barringType;
mIsConditionallyBarred = isConditionallyBarred;
mConditionalBarringFactor = conditionalBarringFactor;
mConditionalBarringTimeSeconds = conditionalBarringTimeSeconds;
}
public @BarringType int getBarringType() {
return mBarringType;
}
/**
* @return true if the conditional barring parameters have resulted in the service being
* barred; false if the service has either not been evaluated for conditional
* barring or has been evaluated and isn't barred.
*/
public boolean isConditionallyBarred() {
return mIsConditionallyBarred;
}
/**
* @return the conditional barring factor as a percentage 0-100, which is the probability of
* a random device being barred for the service type.
*/
public int getConditionalBarringFactor() {
return mConditionalBarringFactor;
}
/**
* @return the conditional barring time seconds, which is the interval between successive
* evaluations for conditional barring based on the barring factor.
*/
@SuppressLint("MethodNameUnits")
public int getConditionalBarringTimeSeconds() {
return mConditionalBarringTimeSeconds;
}
/**
* Return whether a service is currently barred based on the BarringInfo
*
* @return true if the service is currently being barred, otherwise false
*/
public boolean isBarred() {
return mBarringType == BarringServiceInfo.BARRING_TYPE_UNCONDITIONAL
|| (mBarringType == BarringServiceInfo.BARRING_TYPE_CONDITIONAL
&& mIsConditionallyBarred);
}
@Override
public int hashCode() {
return Objects.hash(mBarringType, mIsConditionallyBarred,
mConditionalBarringFactor, mConditionalBarringTimeSeconds);
}
@Override
public boolean equals(Object rhs) {
if (!(rhs instanceof BarringServiceInfo)) return false;
BarringServiceInfo other = (BarringServiceInfo) rhs;
return mBarringType == other.mBarringType
&& mIsConditionallyBarred == other.mIsConditionallyBarred
&& mConditionalBarringFactor == other.mConditionalBarringFactor
&& mConditionalBarringTimeSeconds == other.mConditionalBarringTimeSeconds;
}
/** @hide */
public BarringServiceInfo(Parcel p) {
mBarringType = p.readInt();
mIsConditionallyBarred = p.readBoolean();
mConditionalBarringFactor = p.readInt();
mConditionalBarringTimeSeconds = p.readInt();
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mBarringType);
dest.writeBoolean(mIsConditionallyBarred);
dest.writeInt(mConditionalBarringFactor);
dest.writeInt(mConditionalBarringTimeSeconds);
}
/* @inheritDoc */
public static final @NonNull Parcelable.Creator<BarringServiceInfo> CREATOR =
new Parcelable.Creator<BarringServiceInfo>() {
@Override
public BarringServiceInfo createFromParcel(Parcel source) {
return new BarringServiceInfo(source);
}
@Override
public BarringServiceInfo[] newArray(int size) {
return new BarringServiceInfo[size];
}
};
@Override
public int describeContents() {
return 0;
}
}
private CellIdentity mCellIdentity;
// A SparseArray potentially mapping each BarringService type to a BarringServiceInfo config
// that describes the current barring status of that particular service.
private SparseArray<BarringServiceInfo> mBarringServiceInfos;
/** @hide */
@TestApi
@SystemApi
public BarringInfo() {
mBarringServiceInfos = new SparseArray<>();
}
/**
* Constructor for new BarringInfo instances.
*
* @hide
*/
@TestApi
public BarringInfo(@Nullable CellIdentity barringCellId,
@NonNull SparseArray<BarringServiceInfo> barringServiceInfos) {
mCellIdentity = barringCellId;
mBarringServiceInfos = barringServiceInfos;
}
/** @hide */
public static BarringInfo create(
@NonNull android.hardware.radio.V1_5.CellIdentity halBarringCellId,
@NonNull List<android.hardware.radio.V1_5.BarringInfo> halBarringInfos) {
CellIdentity ci = CellIdentity.create(halBarringCellId);
SparseArray<BarringServiceInfo> serviceInfos = new SparseArray<>();
for (android.hardware.radio.V1_5.BarringInfo halBarringInfo : halBarringInfos) {
if (halBarringInfo.type == android.hardware.radio.V1_5.BarringType.CONDITIONAL) {
if (halBarringInfo.typeSpecificInfo.getDiscriminator()
!= android.hardware.radio.V1_5.BarringTypeSpecificInfo
.hidl_discriminator.conditionalBarringInfo) {
// this is an error case where the barring info is conditional but the
// conditional barring fields weren't included
continue;
}
android.hardware.radio.V1_5.ConditionalBarringInfo conditionalInfo =
halBarringInfo.typeSpecificInfo.conditionalBarringInfo();
serviceInfos.put(
halBarringInfo.service, new BarringServiceInfo(
halBarringInfo.type, // will always be CONDITIONAL here
conditionalInfo.isBarred,
conditionalInfo.barringFactor,
conditionalInfo.barringTimeSeconds));
} else {
// Barring type is either NONE or UNCONDITIONAL
serviceInfos.put(
halBarringInfo.service, new BarringServiceInfo(halBarringInfo.type,
false, 0, 0));
}
}
return new BarringInfo(ci, serviceInfos);
}
/**
* Return whether a service is currently barred based on the BarringInfo
*
* @param service the service to be checked.
* @return true if the service is currently being barred, otherwise false
*/
public boolean isServiceBarred(@BarringServiceType int service) {
BarringServiceInfo bsi = mBarringServiceInfos.get(service);
return bsi != null && (bsi.isBarred());
}
/**
* Get the BarringServiceInfo for a specified service.
*
* @return a BarringServiceInfo struct describing the current barring status for a service
*/
public @NonNull BarringServiceInfo getBarringServiceInfo(@BarringServiceType int service) {
BarringServiceInfo bsi = mBarringServiceInfos.get(service);
return (bsi != null) ? bsi : new BarringServiceInfo();
}
/** @hide */
@SystemApi
public @NonNull BarringInfo createLocationInfoSanitizedCopy() {
return new BarringInfo(mCellIdentity.sanitizeLocationInfo(), mBarringServiceInfos);
}
/** @hide */
public BarringInfo(Parcel p) {
mCellIdentity = p.readParcelable(CellIdentity.class.getClassLoader());
mBarringServiceInfos = p.readSparseArray(BarringServiceInfo.class.getClassLoader());
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeParcelable(mCellIdentity, flags);
dest.writeSparseArray(mBarringServiceInfos);
}
public static final @NonNull Parcelable.Creator<BarringInfo> CREATOR =
new Parcelable.Creator<BarringInfo>() {
@Override
public BarringInfo createFromParcel(Parcel source) {
return new BarringInfo(source);
}
@Override
public BarringInfo[] newArray(int size) {
return new BarringInfo[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public int hashCode() {
int hash = mCellIdentity != null ? mCellIdentity.hashCode() : 7;
for (int i = 0; i < mBarringServiceInfos.size(); i++) {
hash = hash + 15 * mBarringServiceInfos.keyAt(i);
hash = hash + 31 * mBarringServiceInfos.valueAt(i).hashCode();
}
return hash;
}
@Override
public boolean equals(Object rhs) {
if (!(rhs instanceof BarringInfo)) return false;
BarringInfo bi = (BarringInfo) rhs;
if (hashCode() != bi.hashCode()) return false;
if (mBarringServiceInfos.size() != bi.mBarringServiceInfos.size()) return false;
for (int i = 0; i < mBarringServiceInfos.size(); i++) {
if (mBarringServiceInfos.keyAt(i) != bi.mBarringServiceInfos.keyAt(i)) return false;
if (!Objects.equals(mBarringServiceInfos.valueAt(i),
bi.mBarringServiceInfos.valueAt(i))) {
return false;
}
}
return true;
}
@Override
public String toString() {
return "BarringInfo {mCellIdentity=" + mCellIdentity
+ ", mBarringServiceInfos=" + mBarringServiceInfos + "}";
}
}

View File

@@ -557,4 +557,5 @@ public interface RILConstants {
int RIL_UNSOL_EMERGENCY_NUMBER_LIST = 1102;
int RIL_UNSOL_UICC_APPLICATIONS_ENABLEMENT_CHANGED = 1103;
int RIL_UNSOL_REGISTRATION_FAILED = 1104;
int RIL_UNSOL_BARRING_INFO_CHANGED = 1105;
}