RealSystemFacade.java revision 0a77c62a82503b38c484e0079648f0231dd85d53
1package com.android.providers.downloads;
2
3import android.content.Context;
4import android.content.Intent;
5import android.content.pm.PackageManager.NameNotFoundException;
6import android.net.ConnectivityManager;
7import android.net.NetworkInfo;
8import android.telephony.TelephonyManager;
9import android.util.Log;
10
11class RealSystemFacade implements SystemFacade {
12    private Context mContext;
13
14    public RealSystemFacade(Context context) {
15        mContext = context;
16    }
17
18    public long currentTimeMillis() {
19        return System.currentTimeMillis();
20    }
21
22    public Integer getActiveNetworkType() {
23        ConnectivityManager connectivity =
24                (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
25        if (connectivity == null) {
26            Log.w(Constants.TAG, "couldn't get connectivity manager");
27            return null;
28        }
29
30        NetworkInfo activeInfo = connectivity.getActiveNetworkInfo();
31        if (activeInfo == null) {
32            if (Constants.LOGVV) {
33                Log.v(Constants.TAG, "network is not available");
34            }
35            return null;
36        }
37        return activeInfo.getType();
38    }
39
40    public boolean isNetworkRoaming() {
41        ConnectivityManager connectivity =
42            (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
43        if (connectivity == null) {
44            Log.w(Constants.TAG, "couldn't get connectivity manager");
45            return false;
46        }
47
48        NetworkInfo info = connectivity.getActiveNetworkInfo();
49        boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
50        boolean isRoaming = isMobile && TelephonyManager.getDefault().isNetworkRoaming();
51        if (Constants.LOGVV && isRoaming) {
52            Log.v(Constants.TAG, "network is roaming");
53        }
54        return isRoaming;
55    }
56
57    public Integer getMaxBytesOverMobile() {
58        return null;
59    }
60
61    @Override
62    public void sendBroadcast(Intent intent) {
63        mContext.sendBroadcast(intent);
64    }
65
66    @Override
67    public boolean userOwnsPackage(int uid, String packageName) throws NameNotFoundException {
68        return mContext.getPackageManager().getApplicationInfo(packageName, 0).uid == uid;
69    }
70}
71