1 /* 2 * Copyright (C) 2009 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 17 package com.android.internal.os; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import java.util.HashMap; 23 import java.util.Map; 24 25 /** 26 * implementation of PkgUsageStats associated with an 27 * application package. 28 * @hide 29 */ 30 public class PkgUsageStats implements Parcelable { 31 public String packageName; 32 public int launchCount; 33 public long usageTime; 34 public Map<String, Long> componentResumeTimes; 35 36 public static final Parcelable.Creator<PkgUsageStats> CREATOR 37 = new Parcelable.Creator<PkgUsageStats>() { 38 public PkgUsageStats createFromParcel(Parcel in) { 39 return new PkgUsageStats(in); 40 } 41 42 public PkgUsageStats[] newArray(int size) { 43 return new PkgUsageStats[size]; 44 } 45 }; 46 47 public String toString() { 48 return "PkgUsageStats{" 49 + Integer.toHexString(System.identityHashCode(this)) 50 + " " + packageName + "}"; 51 } 52 53 public PkgUsageStats(String pkgName, int count, long time, Map<String, Long> lastResumeTimes) { 54 packageName = pkgName; 55 launchCount = count; 56 usageTime = time; 57 componentResumeTimes = new HashMap<String, Long>(lastResumeTimes); 58 } 59 60 public PkgUsageStats(Parcel source) { 61 packageName = source.readString(); 62 launchCount = source.readInt(); 63 usageTime = source.readLong(); 64 final int N = source.readInt(); 65 componentResumeTimes = new HashMap<String, Long>(N); 66 for (int i = 0; i < N; i++) { 67 String component = source.readString(); 68 long lastResumeTime = source.readLong(); 69 componentResumeTimes.put(component, lastResumeTime); 70 } 71 } 72 73 public PkgUsageStats(PkgUsageStats pStats) { 74 packageName = pStats.packageName; 75 launchCount = pStats.launchCount; 76 usageTime = pStats.usageTime; 77 componentResumeTimes = new HashMap<String, Long>(pStats.componentResumeTimes); 78 } 79 80 public int describeContents() { 81 return 0; 82 } 83 84 public void writeToParcel(Parcel dest, int parcelableFlags) { 85 dest.writeString(packageName); 86 dest.writeInt(launchCount); 87 dest.writeLong(usageTime); 88 dest.writeInt(componentResumeTimes.size()); 89 for (Map.Entry<String, Long> ent : componentResumeTimes.entrySet()) { 90 dest.writeString(ent.getKey()); 91 dest.writeLong(ent.getValue()); 92 } 93 } 94 } 95