blob: fbaf6366720300e2fca92e59b62560db244b1511 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
package com.android.providers.downloads;
import android.app.Notification;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.test.AssertionFailedError;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
public class FakeSystemFacade implements SystemFacade {
long mTimeMillis = 0;
Integer mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
boolean mIsRoaming = false;
Long mMaxBytesOverMobile = null;
Long mRecommendedMaxBytesOverMobile = null;
List<Intent> mBroadcastsSent = new ArrayList<Intent>();
Map<Long,Notification> mActiveNotifications = new HashMap<Long,Notification>();
List<Notification> mCanceledNotifications = new ArrayList<Notification>();
Queue<Thread> mStartedThreads = new LinkedList<Thread>();
private boolean returnActualTime = false;
void incrementTimeMillis(long delta) {
mTimeMillis += delta;
}
public long currentTimeMillis() {
if (returnActualTime) {
return System.currentTimeMillis();
}
return mTimeMillis;
}
public NetworkInfo getActiveNetworkInfo(int uid) {
if (mActiveNetworkType == null) {
return null;
} else {
return new NetworkInfo(mActiveNetworkType, 0, null, null);
}
}
public boolean isNetworkRoaming() {
return mIsRoaming;
}
public Long getMaxBytesOverMobile() {
return mMaxBytesOverMobile ;
}
public Long getRecommendedMaxBytesOverMobile() {
return mRecommendedMaxBytesOverMobile ;
}
@Override
public void sendBroadcast(Intent intent) {
mBroadcastsSent.add(intent);
}
@Override
public boolean userOwnsPackage(int uid, String pckg) throws NameNotFoundException {
return true;
}
@Override
public void postNotification(long id, Notification notification) {
if (notification == null) {
throw new AssertionFailedError("Posting null notification");
}
mActiveNotifications.put(id, notification);
}
@Override
public void cancelNotification(long id) {
Notification notification = mActiveNotifications.remove(id);
if (notification != null) {
mCanceledNotifications.add(notification);
}
}
@Override
public void cancelAllNotifications() {
for (long id : mActiveNotifications.keySet()) {
cancelNotification(id);
}
}
public boolean startThreadsWithoutWaiting = false;
public void setStartThreadsWithoutWaiting(boolean flag) {
this.startThreadsWithoutWaiting = flag;
}
@Override
public void startThread(Thread thread) {
if (startThreadsWithoutWaiting) {
thread.start();
} else {
mStartedThreads.add(thread);
}
}
public void runAllThreads() {
while (!mStartedThreads.isEmpty()) {
mStartedThreads.poll().run();
}
}
public void setReturnActualTime(boolean flag) {
returnActualTime = flag;
}
}
|