10
10
import android .location .Location ;
11
11
import android .os .BatteryManager ;
12
12
import android .support .v4 .content .LocalBroadcastManager ;
13
+ import android .telephony .TelephonyManager ;
13
14
import android .util .Log ;
14
15
15
16
import org .mozilla .mozstumbler .service .AppGlobals ;
@@ -45,7 +46,7 @@ private boolean isBatteryLow() {
45
46
int scale = intent .getIntExtra (BatteryManager .EXTRA_SCALE , -1 );
46
47
int status = intent .getIntExtra (BatteryManager .EXTRA_STATUS , -1 );
47
48
boolean isCharging = (status == BatteryManager .BATTERY_STATUS_CHARGING );
48
- int level = Math .round (rawLevel * scale / 100.0f );
49
+ int level = Math .round (rawLevel * scale / 100.0f );
49
50
50
51
final int kMinBatteryPct = 15 ;
51
52
return !isCharging && level < kMinBatteryPct ;
@@ -61,7 +62,10 @@ public void newPassiveGpsLocation() {
61
62
}
62
63
63
64
mWifiScanner .start (ActiveOrPassiveStumbling .PASSIVE_STUMBLING );
64
- mCellScanner .start (ActiveOrPassiveStumbling .PASSIVE_STUMBLING );
65
+
66
+ if (mCellScanner != null ) {
67
+ mCellScanner .start (ActiveOrPassiveStumbling .PASSIVE_STUMBLING );
68
+ }
65
69
66
70
// how often to flush a leftover bundle to the reports table
67
71
// If there is a bundle, and nothing happens for 10sec, then flush it
@@ -75,23 +79,23 @@ public void newPassiveGpsLocation() {
75
79
when .setTime (when .getTime () + flushRate_ms );
76
80
mPassiveModeFlushTimer = new Timer ();
77
81
mPassiveModeFlushTimer .schedule (new TimerTask () {
78
- @ Override
79
- public void run () {
80
- Intent flush = new Intent (Reporter .ACTION_FLUSH_TO_BUNDLE );
81
- LocalBroadcastManager .getInstance (mContext ).sendBroadcastSync (flush );
82
- }
82
+ @ Override
83
+ public void run () {
84
+ Intent flush = new Intent (Reporter .ACTION_FLUSH_TO_BUNDLE );
85
+ LocalBroadcastManager .getInstance (mContext ).sendBroadcastSync (flush );
86
+ }
83
87
}, when );
84
88
}
85
89
86
- public synchronized void setPassiveMode (boolean on ) {
87
- mStumblingMode = (on )? ActiveOrPassiveStumbling .PASSIVE_STUMBLING :
88
- ActiveOrPassiveStumbling .ACTIVE_STUMBLING ;
89
- }
90
-
91
90
public synchronized boolean isPassiveMode () {
92
91
return ActiveOrPassiveStumbling .PASSIVE_STUMBLING == mStumblingMode ;
93
92
}
94
93
94
+ public synchronized void setPassiveMode (boolean on ) {
95
+ mStumblingMode = (on ) ? ActiveOrPassiveStumbling .PASSIVE_STUMBLING :
96
+ ActiveOrPassiveStumbling .ACTIVE_STUMBLING ;
97
+ }
98
+
95
99
public synchronized void startScanning (Context context ) {
96
100
if (this .isScanning ()) {
97
101
return ;
@@ -101,7 +105,13 @@ public synchronized void startScanning(Context context) {
101
105
if (mGPSScanner == null ) {
102
106
mGPSScanner = new GPSScanner (context , this );
103
107
mWifiScanner = new WifiScanner (context );
104
- mCellScanner = new CellScanner (context );
108
+
109
+ TelephonyManager telephonyManager = (TelephonyManager ) mContext .getSystemService (Context .TELEPHONY_SERVICE );
110
+ if (telephonyManager != null &&
111
+ (telephonyManager .getPhoneType () == TelephonyManager .PHONE_TYPE_CDMA ||
112
+ telephonyManager .getPhoneType () == TelephonyManager .PHONE_TYPE_GSM )) {
113
+ mCellScanner = new CellScanner (context );
114
+ }
105
115
}
106
116
107
117
if (AppGlobals .isDebug ) {
@@ -111,7 +121,11 @@ public synchronized void startScanning(Context context) {
111
121
mGPSScanner .start (mStumblingMode );
112
122
if (mStumblingMode == ActiveOrPassiveStumbling .ACTIVE_STUMBLING ) {
113
123
mWifiScanner .start (mStumblingMode );
114
- mCellScanner .start (mStumblingMode );
124
+
125
+ if (mCellScanner != null ) {
126
+ mCellScanner .start (mStumblingMode );
127
+ }
128
+
115
129
// in passive mode, these scans are started by passive gps notifications
116
130
}
117
131
mIsScanning = true ;
@@ -128,7 +142,9 @@ public synchronized boolean stopScanning() {
128
142
129
143
mGPSScanner .stop ();
130
144
mWifiScanner .stop ();
131
- mCellScanner .stop ();
145
+ if (mCellScanner != null ) {
146
+ mCellScanner .stop ();
147
+ }
132
148
133
149
mIsScanning = false ;
134
150
return true ;
@@ -143,27 +159,27 @@ public synchronized boolean isScanning() {
143
159
}
144
160
145
161
public int getAPCount () {
146
- return (mWifiScanner == null )? 0 : mWifiScanner .getAPCount ();
162
+ return (mWifiScanner == null ) ? 0 : mWifiScanner .getAPCount ();
147
163
}
148
164
149
165
public int getVisibleAPCount () {
150
- return (mWifiScanner == null )? 0 :mWifiScanner .getVisibleAPCount ();
166
+ return (mWifiScanner == null ) ? 0 : mWifiScanner .getVisibleAPCount ();
151
167
}
152
168
153
169
public int getWifiStatus () {
154
- return (mWifiScanner == null )? 0 : mWifiScanner .getStatus ();
170
+ return (mWifiScanner == null ) ? 0 : mWifiScanner .getStatus ();
155
171
}
156
172
157
173
public int getCellInfoCount () {
158
- return (mCellScanner == null )? 0 :mCellScanner .getCellInfoCount ();
174
+ return (mCellScanner == null ) ? 0 : mCellScanner .getCellInfoCount ();
159
175
}
160
176
161
177
public int getLocationCount () {
162
- return (mGPSScanner == null )? 0 : mGPSScanner .getLocationCount ();
178
+ return (mGPSScanner == null ) ? 0 : mGPSScanner .getLocationCount ();
163
179
}
164
180
165
181
public Location getLocation () {
166
- return (mGPSScanner == null )? new Location ("null" ) : mGPSScanner .getLocation ();
182
+ return (mGPSScanner == null ) ? new Location ("null" ) : mGPSScanner .getLocation ();
167
183
}
168
184
169
185
}
0 commit comments