• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import com.xtremelabs.robolectric.internal.Implementation;
4 import com.xtremelabs.robolectric.internal.Implements;
5 
6 import android.os.StatFs;
7 
8 import java.io.File;
9 import java.util.HashMap;
10 import java.util.Map;
11 
12 @Implements(StatFs.class)
13 public class ShadowStatFs {
14     public static final int BLOCK_SIZE = 4096;
15     private static final Stats DEFAULT_STATS = new Stats(0, 0, 0);
16     private static Map<String, Stats> stats = new HashMap<String, Stats>();
17     private Stats stat;
18 
__constructor__(String path)19     public void __constructor__(String path) {
20         restat(path);
21     }
22 
23     @Implementation
getBlockSize()24     public int getBlockSize() {
25         return BLOCK_SIZE;
26     }
27 
28     @Implementation
getBlockCount()29     public int getBlockCount() {
30         return stat.blockCount;
31     }
32 
33     @Implementation
getFreeBlocks()34     public int getFreeBlocks() {
35         return stat.freeBlocks;
36     }
37 
38     @Implementation
getAvailableBlocks()39     public int getAvailableBlocks() {
40         return stat.availableBlocks;
41     }
42 
43     @Implementation
restat(String path)44     public void restat(String path) {
45         stat = stats.get(path);
46         if (stat == null) {
47             stat = DEFAULT_STATS;
48         }
49     }
50 
registerStats(File path, int blockCount, int freeBlocks, int availableBlocks)51     public static void registerStats(File path, int blockCount, int freeBlocks, int availableBlocks) {
52         registerStats(path.getAbsolutePath(), blockCount, freeBlocks, availableBlocks);
53     }
54 
registerStats(String path, int blockCount, int freeBlocks, int availableBlocks)55     public static void registerStats(String path, int blockCount, int freeBlocks, int availableBlocks) {
56         stats.put(path, new Stats(blockCount, freeBlocks, availableBlocks));
57     }
58 
reset()59     public static void reset() {
60         stats.clear();
61     }
62 
63     private static class Stats {
Stats(int blockCount, int freeBlocks, int availableBlocks)64         Stats(int blockCount, int freeBlocks, int availableBlocks) {
65             this.blockCount = blockCount;
66             this.freeBlocks = freeBlocks;
67             this.availableBlocks = availableBlocks;
68         }
69         int blockCount, freeBlocks, availableBlocks;
70     }
71 }