1 package com.android.server.wifi.hotspot2.pps; 2 3 import com.android.server.wifi.hotspot2.Utils; 4 import com.android.server.wifi.hotspot2.omadm.OMAException; 5 import com.android.server.wifi.hotspot2.omadm.OMANode; 6 import com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager; 7 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_CreationDate; 12 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_DataLimit; 13 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_ExpirationDate; 14 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_StartDate; 15 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_TimeLimit; 16 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_TypeOfSubscription; 17 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UsageLimits; 18 import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UsageTimePeriod; 19 20 public class SubscriptionParameters { 21 private final long mCDate; 22 private final long mXDate; 23 private final String mType; 24 private final List<Limit> mLimits; 25 26 public SubscriptionParameters(OMANode node) throws OMAException { 27 mCDate = PasspointManagementObjectManager.getTime(node.getChild(TAG_CreationDate)); 28 mXDate = PasspointManagementObjectManager.getTime(node.getChild(TAG_ExpirationDate)); 29 mType = PasspointManagementObjectManager.getString(node.getChild(TAG_TypeOfSubscription)); 30 31 OMANode ulNode = node.getChild(TAG_UsageLimits); 32 if (ulNode == null) { 33 mLimits = null; 34 } 35 else { 36 mLimits = new ArrayList<>(ulNode.getChildren().size()); 37 for (OMANode instance : ulNode.getChildren()) { 38 if (instance.isLeaf()) { 39 throw new OMAException("Not expecting leaf node in " + 40 TAG_UsageLimits); 41 } 42 mLimits.add(new Limit(instance)); 43 } 44 } 45 46 } 47 48 private static class Limit { 49 private final long mDataLimit; 50 private final long mStartDate; 51 private final long mTimeLimit; 52 private final long mUsageTimePeriod; 53 54 private Limit(OMANode node) throws OMAException { 55 mDataLimit = PasspointManagementObjectManager 56 .getLong(node, TAG_DataLimit, Long.MAX_VALUE); 57 mStartDate = PasspointManagementObjectManager 58 .getTime(node.getChild(TAG_StartDate)); 59 mTimeLimit = PasspointManagementObjectManager 60 .getLong(node, TAG_TimeLimit, Long.MAX_VALUE) 61 * PasspointManagementObjectManager.IntervalFactor; 62 mUsageTimePeriod = PasspointManagementObjectManager 63 .getLong(node, TAG_UsageTimePeriod, null); 64 } 65 66 @Override 67 public String toString() { 68 return "Limit{" + 69 "dataLimit=" + mDataLimit + 70 ", startDate=" + Utils.toUTCString(mStartDate) + 71 ", timeLimit=" + mTimeLimit + 72 ", usageTimePeriod=" + mUsageTimePeriod + 73 '}'; 74 } 75 } 76 77 @Override 78 public String toString() { 79 return "SubscriptionParameters{" + 80 "cDate=" + Utils.toUTCString(mCDate) + 81 ", xDate=" + Utils.toUTCString(mXDate) + 82 ", type='" + mType + '\'' + 83 ", limits=" + mLimits + 84 '}'; 85 } 86 } 87