6161import android .app .NotificationManager ;
6262import android .app .PendingIntent ;
6363import android .app .Service ;
64+ import android .content .BroadcastReceiver ;
6465import android .content .Context ;
6566import android .content .DialogInterface ;
6667import android .content .Intent ;
68+ import android .content .IntentFilter ;
6769import android .content .SharedPreferences ;
6870import android .content .SharedPreferences .OnSharedPreferenceChangeListener ;
6971import android .location .Location ;
119121import java .util .List ;
120122import java .util .Map ;
121123import java .util .Queue ;
122- import java .util .Timer ;
123124
124125public class AimsicdService extends Service implements OnSharedPreferenceChangeListener {
125126
@@ -132,6 +133,7 @@ public class AimsicdService extends Service implements OnSharedPreferenceChangeL
132133 */
133134 private final AimscidBinder mBinder = new AimscidBinder ();
134135 private final AIMSICDDbAdapter dbHelper = new AIMSICDDbAdapter (this );
136+ private Context mContext ;
135137 private final int NOTIFICATION_ID = 1 ;
136138 private long mDbResult ;
137139 private TelephonyManager tm ;
@@ -142,7 +144,6 @@ public class AimsicdService extends Service implements OnSharedPreferenceChangeL
142144 private static final long GPS_MIN_UPDATE_TIME = 1000 ;
143145 private static final float GPS_MIN_UPDATE_DISTANCE = 10 ;
144146 public boolean mMultiRilCompatible ;
145- private Timer timer = new Timer ();
146147
147148 /*
148149 * Device Declarations
@@ -177,8 +178,7 @@ public class AimsicdService extends Service implements OnSharedPreferenceChangeL
177178 private String mSimSubs = "" ;
178179 private String mDataActivityType = "" ;
179180 private String mDataActivityTypeShort = "" ;
180- private final Map <Integer ,Integer > mNeighborMapUMTS = new HashMap <>();
181- private final Map <String ,Integer > mNeighborMapGSM = new HashMap <>();
181+ private final Map <String , String > mNeighborMap = new HashMap <>();
182182
183183 /*
184184 * Tracking and Alert Declarations
@@ -237,6 +237,7 @@ public void onCreate() {
237237 //TelephonyManager provides system details
238238 tm = (TelephonyManager ) this .getSystemService (Context .TELEPHONY_SERVICE );
239239 lm = (LocationManager ) this .getSystemService (Context .LOCATION_SERVICE );
240+ mContext = getApplicationContext ();
240241
241242 prefs = this .getSharedPreferences (
242243 AimsicdService .SHARED_PREFERENCES_BASENAME , 0 );
@@ -265,6 +266,9 @@ public void onCreate() {
265266 }
266267 }
267268
269+ //Register receiver for Silent SMS Interception Notification
270+ mContext .registerReceiver (mMessageReceiver , new IntentFilter (SILENT_SMS ));
271+
268272 Log .i (TAG , "Service launched successfully" );
269273 }
270274
@@ -280,6 +284,7 @@ public void onDestroy() {
280284 prefs .unregisterOnSharedPreferenceChangeListener (this );
281285 cancelNotification ();
282286 dbHelper .close ();
287+ mContext .unregisterReceiver (mMessageReceiver );
283288
284289 //Samsung MultiRil Cleanup
285290 if (mRequestExecutor != null ) {
@@ -289,9 +294,23 @@ public void onDestroy() {
289294 mHandler = null ;
290295 mHandlerThread .quit ();
291296 mHandlerThread = null ;
297+
292298 Log .i (TAG , "Service destroyed" );
293299 }
294300
301+ private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver () {
302+ @ Override
303+ public void onReceive (Context context , Intent intent ) {
304+ final Bundle bundle = intent .getExtras ();
305+ if (bundle != null ) {
306+ dbHelper .open ();
307+ dbHelper .insertSilentSms (bundle );
308+ dbHelper .close ();
309+ setSilentSmsStatus (true );
310+ }
311+ }
312+ };
313+
295314 /**
296315 * Check the status of the Rill Executor
297316 *
@@ -411,7 +430,7 @@ private synchronized List<String> executeAtServiceModeCommand(int type, int subt
411430
412431 private static class KeyStep {
413432 public final char keychar ;
414- public boolean captureResponse ;
433+ public final boolean captureResponse ;
415434
416435 public KeyStep (char keychar , boolean captureResponse ) {
417436 this .keychar = keychar ;
@@ -1015,7 +1034,7 @@ public String getNetworkTypeName() {
10151034 return mNetType ;
10161035 }
10171036
1018- public void getDataActivity () {
1037+ void getDataActivity () {
10191038 int direction = tm .getDataActivity ();
10201039 mDataActivityTypeShort = "un" ;
10211040 mDataActivityType = "undef" ;
@@ -1043,7 +1062,7 @@ public void getDataActivity() {
10431062 }
10441063 }
10451064
1046- public void getDataState () {
1065+ void getDataState () {
10471066 int state = tm .getDataState ();
10481067 mDataState = "undef" ;
10491068 mDataStateShort = "un" ;
@@ -1186,8 +1205,17 @@ public void updateCdmaLocation() {
11861205 mLastLocation .setLatitude (mLatitude );
11871206 }
11881207
1189- public void setSilentSmsStatus (boolean state ) {
1208+ void setSilentSmsStatus (boolean state ) {
11901209 mClassZeroSmsDetected = state ;
1210+ setNotification ();
1211+ if (state ) {
1212+ final AlertDialog .Builder builder = new AlertDialog .Builder (this );
1213+ builder .setMessage (R .string .sms_message )
1214+ .setTitle (R .string .location_error_title );
1215+ AlertDialog alert = builder .create ();
1216+ alert .getWindow ().setType (WindowManager .LayoutParams .TYPE_SYSTEM_ALERT );
1217+ alert .show ();
1218+ }
11911219 }
11921220
11931221 /**
@@ -1275,11 +1303,11 @@ private void setNotification() {
12751303 break ;
12761304 }
12771305
1278- Context context = getApplicationContext ( );
1279- Intent notificationIntent = new Intent ( context , AIMSICD . class );
1306+ Intent notificationIntent = new Intent ( mContext , AIMSICD . class );
1307+ notificationIntent . putExtra ( "silent_sms" , mClassZeroSmsDetected );
12801308 notificationIntent .addFlags (Intent .FLAG_ACTIVITY_SINGLE_TOP | Intent .FLAG_FROM_BACKGROUND );
12811309 PendingIntent contentIntent = PendingIntent .getActivity (
1282- context , NOTIFICATION_ID , notificationIntent , PendingIntent .FLAG_CANCEL_CURRENT );
1310+ mContext , NOTIFICATION_ID , notificationIntent , PendingIntent .FLAG_CANCEL_CURRENT );
12831311 Notification mBuilder =
12841312 new NotificationCompat .Builder (this )
12851313 .setSmallIcon (icon )
@@ -1313,24 +1341,25 @@ private void cancelNotification() {
13131341 *
13141342 */
13151343 public void updateNeighbouringCells () {
1316- //Update Neighbouring Cell Map
1317- for (String key : mNeighborMapGSM .keySet ())
1318- mNeighborMapGSM .put (key ,-113 );
1319- for (int key : mNeighborMapUMTS .keySet ())
1320- mNeighborMapUMTS .put (key ,-115 );
1321-
13221344 List <NeighboringCellInfo > neighboringCellInfo ;
13231345 neighboringCellInfo = tm .getNeighboringCellInfo ();
1324- mNeighbouringCellSize = neighboringCellInfo .size ();
1325- for (NeighboringCellInfo i : neighboringCellInfo ) {
1326- int networktype = i .getNetworkType ();
1327- if ((networktype == TelephonyManager .NETWORK_TYPE_UMTS ) ||
1328- (networktype == TelephonyManager .NETWORK_TYPE_HSDPA ) ||
1329- (networktype == TelephonyManager .NETWORK_TYPE_HSUPA ) ||
1330- (networktype == TelephonyManager .NETWORK_TYPE_HSPA ))
1331- mNeighborMapUMTS .put (i .getPsc (), i .getRssi ()-115 );
1332- else
1333- mNeighborMapGSM .put (i .getLac ()+"-" +i .getCid (), (-113 +2 *(i .getRssi ())));
1346+ if (neighboringCellInfo != null ) {
1347+ mNeighbouringCellSize = neighboringCellInfo .size ();
1348+ for (int i = 0 ; i > neighboringCellInfo .size (); i ++) {
1349+ if (neighboringCellInfo .get (i ) != null ) {
1350+ String dBm ;
1351+ int rssi = neighboringCellInfo .get (i ).getRssi ();
1352+
1353+ if (rssi == NeighboringCellInfo .UNKNOWN_RSSI ) {
1354+ dBm = "Unknown RSSI" ;
1355+ } else {
1356+ dBm = String .valueOf (-113 + 2 * rssi ) + " dBm" ;
1357+ }
1358+
1359+ mNeighborMap .put (neighboringCellInfo .get (i ).getLac () +
1360+ ":" + neighboringCellInfo .get (i ).getCid (), dBm );
1361+ }
1362+ }
13341363 }
13351364 }
13361365
@@ -1339,19 +1368,9 @@ public void updateNeighbouringCells() {
13391368 *
13401369 * @return Map of GSM Neighbouring Cell Information
13411370 */
1342- public Map getGSMNeighbouringCells () {
1343- return mNeighborMapGSM ;
1371+ public Map getNeighbouringCells () {
1372+ return mNeighborMap ;
13441373 }
1345-
1346- /**
1347- * Neighbouring UMTS Cell Map
1348- *
1349- * @return Map of UMTS Neighbouring Cell Information
1350- */
1351- public Map getUMTSNeighbouringCells () {
1352- return mNeighborMapUMTS ;
1353- }
1354-
13551374 /**
13561375 * Neighbouring Cell Size
13571376 *
@@ -1665,7 +1684,7 @@ public void onStatusChanged(String provider, int status,
16651684 * @param location The new Location that you want to evaluate
16661685 * @param currentBestLocation The current Location fix, to which you want to compare the new one
16671686 */
1668- protected boolean isBetterLocation (Location location , Location currentBestLocation ) {
1687+ boolean isBetterLocation (Location location , Location currentBestLocation ) {
16691688 if (currentBestLocation == null ) {
16701689 // A new location is always better than no location
16711690 return true ;
0 commit comments