NetworkPolicy.java revision 21c9c45e5caf62b935354b74392fb40c4bf18529
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.net;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * Policy for a specific network, including usage cycle and limits to be
24 * enforced.
25 *
26 * @hide
27 */
28public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
29    public final int cycleDay;
30    public final long warningBytes;
31    public final long limitBytes;
32
33    public NetworkPolicy(int cycleDay, long warningBytes, long limitBytes) {
34        this.cycleDay = cycleDay;
35        this.warningBytes = warningBytes;
36        this.limitBytes = limitBytes;
37    }
38
39    public NetworkPolicy(Parcel in) {
40        cycleDay = in.readInt();
41        warningBytes = in.readLong();
42        limitBytes = in.readLong();
43    }
44
45    /** {@inheritDoc} */
46    public void writeToParcel(Parcel dest, int flags) {
47        dest.writeInt(cycleDay);
48        dest.writeLong(warningBytes);
49        dest.writeLong(limitBytes);
50    }
51
52    /** {@inheritDoc} */
53    public int describeContents() {
54        return 0;
55    }
56
57    /** {@inheritDoc} */
58    public int compareTo(NetworkPolicy another) {
59        if (another == null || limitBytes < another.limitBytes) {
60            return -1;
61        } else {
62            return 1;
63        }
64    }
65
66    @Override
67    public String toString() {
68        return "NetworkPolicy: cycleDay=" + cycleDay + ", warningBytes=" + warningBytes
69                + ", limitBytes=" + limitBytes;
70    }
71
72    public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
73        public NetworkPolicy createFromParcel(Parcel in) {
74            return new NetworkPolicy(in);
75        }
76
77        public NetworkPolicy[] newArray(int size) {
78            return new NetworkPolicy[size];
79        }
80    };
81}
82