Home | History | Annotate | Download | only in downloads
      1 package com.android.providers.downloads;
      2 
      3 import android.content.Intent;
      4 import android.content.pm.PackageManager.NameNotFoundException;
      5 import android.net.ConnectivityManager;
      6 import android.net.NetworkInfo;
      7 import android.net.NetworkInfo.DetailedState;
      8 
      9 import java.util.ArrayList;
     10 import java.util.List;
     11 public class FakeSystemFacade implements SystemFacade {
     12     long mTimeMillis = 0;
     13     Integer mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
     14     boolean mIsRoaming = false;
     15     boolean mIsMetered = false;
     16     Long mMaxBytesOverMobile = null;
     17     Long mRecommendedMaxBytesOverMobile = null;
     18     List<Intent> mBroadcastsSent = new ArrayList<Intent>();
     19     private boolean mReturnActualTime = false;
     20 
     21     public void setUp() {
     22         mTimeMillis = 0;
     23         mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
     24         mIsRoaming = false;
     25         mIsMetered = false;
     26         mMaxBytesOverMobile = null;
     27         mRecommendedMaxBytesOverMobile = null;
     28         mBroadcastsSent.clear();
     29         mReturnActualTime = false;
     30     }
     31 
     32     void incrementTimeMillis(long delta) {
     33         mTimeMillis += delta;
     34     }
     35 
     36     @Override
     37     public long currentTimeMillis() {
     38         if (mReturnActualTime) {
     39             return System.currentTimeMillis();
     40         }
     41         return mTimeMillis;
     42     }
     43 
     44     @Override
     45     public NetworkInfo getActiveNetworkInfo(int uid) {
     46         if (mActiveNetworkType == null) {
     47             return null;
     48         } else {
     49             final NetworkInfo info = new NetworkInfo(mActiveNetworkType, 0, null, null);
     50             info.setDetailedState(DetailedState.CONNECTED, null, null);
     51             return info;
     52         }
     53     }
     54 
     55     @Override
     56     public boolean isActiveNetworkMetered() {
     57         return mIsMetered;
     58     }
     59 
     60     @Override
     61     public boolean isNetworkRoaming() {
     62         return mIsRoaming;
     63     }
     64 
     65     @Override
     66     public Long getMaxBytesOverMobile() {
     67         return mMaxBytesOverMobile;
     68     }
     69 
     70     @Override
     71     public Long getRecommendedMaxBytesOverMobile() {
     72         return mRecommendedMaxBytesOverMobile;
     73     }
     74 
     75     @Override
     76     public void sendBroadcast(Intent intent) {
     77         mBroadcastsSent.add(intent);
     78     }
     79 
     80     @Override
     81     public boolean userOwnsPackage(int uid, String pckg) throws NameNotFoundException {
     82         return true;
     83     }
     84 
     85     public void setReturnActualTime(boolean flag) {
     86         mReturnActualTime = flag;
     87     }
     88 }
     89