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 package com.android.providers.applications; 17 18 import com.android.internal.os.PkgUsageStats; 19 20 import java.util.HashMap; 21 import java.util.Map; 22 23 /** 24 * The real ActivityManager is difficult to mock out (has a package visibility 25 * constructor), so this doesn't extend it. 26 */ 27 public class MockActivityManager { 28 29 private Map<String, PkgUsageStats> mPackageUsageStats = new HashMap<String, PkgUsageStats>(); 30 addLastResumeTime(String packageName, String componentName, long lastResumeTime)31 public void addLastResumeTime(String packageName, String componentName, long lastResumeTime) { 32 if (!mPackageUsageStats.containsKey(packageName)) { 33 PkgUsageStats stats = new PkgUsageStats(packageName, 1, 0, new HashMap<String, Long>()); 34 mPackageUsageStats.put(packageName, stats); 35 } 36 mPackageUsageStats.get(packageName).componentResumeTimes.put(componentName, lastResumeTime); 37 } 38 getAllPackageUsageStats()39 public PkgUsageStats[] getAllPackageUsageStats() { 40 return mPackageUsageStats.values().toArray(new PkgUsageStats[mPackageUsageStats.size()]); 41 } 42 } 43