Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.telephony.PhoneStateListener;
      4 import android.telephony.TelephonyManager;
      5 import com.xtremelabs.robolectric.internal.Implementation;
      6 import com.xtremelabs.robolectric.internal.Implements;
      7 
      8 @Implements(TelephonyManager.class)
      9 public class ShadowTelephonyManager {
     10 
     11 	private PhoneStateListener listener;
     12 	private int eventFlags;
     13     private String deviceId;
     14     private String networkOperatorName;
     15     private String networkCountryIso;
     16     private String networkOperator;
     17     private boolean readPhoneStatePermission = true;
     18     private int phoneType = TelephonyManager.PHONE_TYPE_GSM;
     19     private String simCountryIso;
     20 
     21     @Implementation
     22 	public void listen(PhoneStateListener listener, int events) {
     23 		this.listener = listener;
     24 		this.eventFlags = events;
     25 	}
     26 
     27 	/**
     28 	 * Non-Android accessor.  Returns the most recent listener
     29 	 * passed to #listen().
     30 	 *
     31 	 * @return
     32 	 */
     33 	public PhoneStateListener getListener() {
     34 		return listener;
     35 	}
     36 
     37 	/**
     38 	 * Non-Android accessor.  Returns the most recent flags
     39 	 * passed to #listen().
     40 	 * @return
     41 	 */
     42 	public int getEventFlags() {
     43 		return eventFlags;
     44 	}
     45 
     46     @Implementation
     47     public String getDeviceId() {
     48         checkReadPhoneStatePermission();
     49         return deviceId;
     50     }
     51 
     52     public void setDeviceId(String newDeviceId) {
     53         deviceId = newDeviceId;
     54     }
     55 
     56     public void setNetworkOperatorName(String networkOperatorName) {
     57         this.networkOperatorName = networkOperatorName;
     58     }
     59 
     60     @Implementation
     61     public String getNetworkOperatorName() {
     62         return networkOperatorName;
     63     }
     64 
     65     public void setNetworkCountryIso(String networkCountryIso) {
     66         this.networkCountryIso = networkCountryIso;
     67     }
     68 
     69     @Implementation
     70     public String getNetworkCountryIso() {
     71         return networkCountryIso;
     72     }
     73 
     74     public void setNetworkOperator(String networkOperator) {
     75         this.networkOperator = networkOperator;
     76     }
     77 
     78     @Implementation
     79     public String getNetworkOperator() {
     80         return networkOperator;
     81     }
     82 
     83     @Implementation
     84     public String getSimCountryIso() {
     85         return simCountryIso;
     86     }
     87 
     88     public void setSimCountryIso(String simCountryIso) {
     89         this.simCountryIso = simCountryIso;
     90     }
     91 
     92     public void setReadPhoneStatePermission(boolean readPhoneStatePermission) {
     93         this.readPhoneStatePermission = readPhoneStatePermission;
     94     }
     95 
     96     private void checkReadPhoneStatePermission() {
     97         if (!readPhoneStatePermission) {
     98             throw new SecurityException();
     99         }
    100     }
    101 
    102     @Implementation
    103     public int getPhoneType() {
    104     	return phoneType;
    105     }
    106 
    107     public void setPhoneType(int phoneType) {
    108     	this.phoneType = phoneType;
    109     }
    110 }
    111