1/**
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16package android.app.usage;
17
18import android.content.res.Configuration;
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * Represents the usage statistics of a device {@link android.content.res.Configuration} for a
24 * specific time range.
25 */
26public final class ConfigurationStats implements Parcelable {
27
28    /**
29     * {@hide}
30     */
31    public Configuration mConfiguration;
32
33    /**
34     * {@hide}
35     */
36    public long mBeginTimeStamp;
37
38    /**
39     * {@hide}
40     */
41    public long mEndTimeStamp;
42
43    /**
44     * {@hide}
45     */
46    public long mLastTimeActive;
47
48    /**
49     * {@hide}
50     */
51    public long mTotalTimeActive;
52
53    /**
54     * {@hide}
55     */
56    public int mActivationCount;
57
58    /**
59     * {@hide}
60     */
61    public ConfigurationStats() {
62    }
63
64    public ConfigurationStats(ConfigurationStats stats) {
65        mConfiguration = stats.mConfiguration;
66        mBeginTimeStamp = stats.mBeginTimeStamp;
67        mEndTimeStamp = stats.mEndTimeStamp;
68        mLastTimeActive = stats.mLastTimeActive;
69        mTotalTimeActive = stats.mTotalTimeActive;
70        mActivationCount = stats.mActivationCount;
71    }
72
73    public Configuration getConfiguration() {
74        return mConfiguration;
75    }
76
77    /**
78     * Get the beginning of the time range this {@link ConfigurationStats} represents,
79     * measured in milliseconds since the epoch.
80     * <p/>
81     * See {@link System#currentTimeMillis()}.
82     */
83    public long getFirstTimeStamp() {
84        return mBeginTimeStamp;
85    }
86
87    /**
88     * Get the end of the time range this {@link ConfigurationStats} represents,
89     * measured in milliseconds since the epoch.
90     * <p/>
91     * See {@link System#currentTimeMillis()}.
92     */
93    public long getLastTimeStamp() {
94        return mEndTimeStamp;
95    }
96
97    /**
98     * Get the last time this configuration was active, measured in milliseconds since the epoch.
99     * <p/>
100     * See {@link System#currentTimeMillis()}.
101     */
102    public long getLastTimeActive() {
103        return mLastTimeActive;
104    }
105
106    /**
107     * Get the total time this configuration was active, measured in milliseconds.
108     */
109    public long getTotalTimeActive() {
110        return mTotalTimeActive;
111    }
112
113    /**
114     * Get the number of times this configuration was active.
115     */
116    public int getActivationCount() {
117        return mActivationCount;
118    }
119
120    @Override
121    public int describeContents() {
122        return 0;
123    }
124
125    @Override
126    public void writeToParcel(Parcel dest, int flags) {
127        if (mConfiguration != null) {
128            dest.writeInt(1);
129            mConfiguration.writeToParcel(dest, flags);
130        } else {
131            dest.writeInt(0);
132        }
133
134        dest.writeLong(mBeginTimeStamp);
135        dest.writeLong(mEndTimeStamp);
136        dest.writeLong(mLastTimeActive);
137        dest.writeLong(mTotalTimeActive);
138        dest.writeInt(mActivationCount);
139    }
140
141    public static final Creator<ConfigurationStats> CREATOR = new Creator<ConfigurationStats>() {
142        @Override
143        public ConfigurationStats createFromParcel(Parcel source) {
144            ConfigurationStats stats = new ConfigurationStats();
145            if (source.readInt() != 0) {
146                stats.mConfiguration = Configuration.CREATOR.createFromParcel(source);
147            }
148            stats.mBeginTimeStamp = source.readLong();
149            stats.mEndTimeStamp = source.readLong();
150            stats.mLastTimeActive = source.readLong();
151            stats.mTotalTimeActive = source.readLong();
152            stats.mActivationCount = source.readInt();
153            return stats;
154        }
155
156        @Override
157        public ConfigurationStats[] newArray(int size) {
158            return new ConfigurationStats[size];
159        }
160    };
161}
162