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