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  */
16 package android.app.usage;
17 
18 import android.compat.annotation.UnsupportedAppUsage;
19 import android.content.res.Configuration;
20 import android.os.Build;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * Represents the usage statistics of a device {@link android.content.res.Configuration} for a
26  * specific time range.
27  */
28 public final class ConfigurationStats implements Parcelable {
29 
30     /**
31      * {@hide}
32      */
33     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
34     public Configuration mConfiguration;
35 
36     /**
37      * {@hide}
38      */
39     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
40     public long mBeginTimeStamp;
41 
42     /**
43      * {@hide}
44      */
45     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
46     public long mEndTimeStamp;
47 
48     /**
49      * {@hide}
50      */
51     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
52     public long mLastTimeActive;
53 
54     /**
55      * {@hide}
56      */
57     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
58     public long mTotalTimeActive;
59 
60     /**
61      * {@hide}
62      */
63     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
64     public int mActivationCount;
65 
66     /**
67      * {@hide}
68      */
ConfigurationStats()69     public ConfigurationStats() {
70     }
71 
ConfigurationStats(ConfigurationStats stats)72     public ConfigurationStats(ConfigurationStats stats) {
73         mConfiguration = stats.mConfiguration;
74         mBeginTimeStamp = stats.mBeginTimeStamp;
75         mEndTimeStamp = stats.mEndTimeStamp;
76         mLastTimeActive = stats.mLastTimeActive;
77         mTotalTimeActive = stats.mTotalTimeActive;
78         mActivationCount = stats.mActivationCount;
79     }
80 
getConfiguration()81     public Configuration getConfiguration() {
82         return mConfiguration;
83     }
84 
85     /**
86      * Get the beginning of the time range this {@link ConfigurationStats} represents,
87      * measured in milliseconds since the epoch.
88      * <p/>
89      * See {@link System#currentTimeMillis()}.
90      */
getFirstTimeStamp()91     public long getFirstTimeStamp() {
92         return mBeginTimeStamp;
93     }
94 
95     /**
96      * Get the end of the time range this {@link ConfigurationStats} represents,
97      * measured in milliseconds since the epoch.
98      * <p/>
99      * See {@link System#currentTimeMillis()}.
100      */
getLastTimeStamp()101     public long getLastTimeStamp() {
102         return mEndTimeStamp;
103     }
104 
105     /**
106      * Get the last time this configuration was active, measured in milliseconds since the epoch.
107      * <p/>
108      * See {@link System#currentTimeMillis()}.
109      */
getLastTimeActive()110     public long getLastTimeActive() {
111         return mLastTimeActive;
112     }
113 
114     /**
115      * Get the total time this configuration was active, measured in milliseconds.
116      */
getTotalTimeActive()117     public long getTotalTimeActive() {
118         return mTotalTimeActive;
119     }
120 
121     /**
122      * Get the number of times this configuration was active.
123      */
getActivationCount()124     public int getActivationCount() {
125         return mActivationCount;
126     }
127 
128     @Override
describeContents()129     public int describeContents() {
130         return 0;
131     }
132 
133     @Override
writeToParcel(Parcel dest, int flags)134     public void writeToParcel(Parcel dest, int flags) {
135         if (mConfiguration != null) {
136             dest.writeInt(1);
137             mConfiguration.writeToParcel(dest, flags);
138         } else {
139             dest.writeInt(0);
140         }
141 
142         dest.writeLong(mBeginTimeStamp);
143         dest.writeLong(mEndTimeStamp);
144         dest.writeLong(mLastTimeActive);
145         dest.writeLong(mTotalTimeActive);
146         dest.writeInt(mActivationCount);
147     }
148 
149     public static final @android.annotation.NonNull Creator<ConfigurationStats> CREATOR = new Creator<ConfigurationStats>() {
150         @Override
151         public ConfigurationStats createFromParcel(Parcel source) {
152             ConfigurationStats stats = new ConfigurationStats();
153             if (source.readInt() != 0) {
154                 stats.mConfiguration = Configuration.CREATOR.createFromParcel(source);
155             }
156             stats.mBeginTimeStamp = source.readLong();
157             stats.mEndTimeStamp = source.readLong();
158             stats.mLastTimeActive = source.readLong();
159             stats.mTotalTimeActive = source.readLong();
160             stats.mActivationCount = source.readInt();
161             return stats;
162         }
163 
164         @Override
165         public ConfigurationStats[] newArray(int size) {
166             return new ConfigurationStats[size];
167         }
168     };
169 }
170