@@ -266,7 +266,12 @@ public void onCreate() {
266
266
267
267
tracker = NotificationTracker .getInstance ();
268
268
269
- callState = ((TelephonyManager )getSystemService (TELEPHONY_SERVICE )).getCallState ();
269
+ try {
270
+ callState = ((TelephonyManager )getSystemService (TELEPHONY_SERVICE )).getCallState ();
271
+ } catch (SecurityException e ) {
272
+ // we don't have READ_PHONE_STATE
273
+ callState = TelephonyManager .CALL_STATE_IDLE ;
274
+ }
270
275
271
276
intentFilter = new IntentFilter ();
272
277
intentFilter .addAction (Intent .ACTION_SCREEN_ON );
@@ -331,7 +336,11 @@ public void onListenerConnected() {
331
336
connected = true ;
332
337
tracker .clear ();
333
338
isUserPresent = Display .isOn (this , false ) && !keyguardManager .isKeyguardLocked ();
334
- ((TelephonyManager )getSystemService (TELEPHONY_SERVICE )).listen (phoneStateListener , PhoneStateListener .LISTEN_CALL_STATE );
339
+ try {
340
+ ((TelephonyManager )getSystemService (TELEPHONY_SERVICE )).listen (phoneStateListener , PhoneStateListener .LISTEN_CALL_STATE );
341
+ } catch (SecurityException e ) {
342
+ // we don't have READ_PHONE_STATE
343
+ }
335
344
registerReceiver (broadcastReceiver , intentFilter );
336
345
handleLEDNotifications ();
337
346
startMotionSensor ();
@@ -353,7 +362,11 @@ public void onListenerDisconnected() {
353
362
getContentResolver ().unregisterContentObserver (refreshLEDObserverSlow );
354
363
stopMotionSensor ();
355
364
unregisterReceiver (broadcastReceiver );
356
- ((TelephonyManager )getSystemService (TELEPHONY_SERVICE )).listen (phoneStateListener , PhoneStateListener .LISTEN_NONE );
365
+ try {
366
+ ((TelephonyManager )getSystemService (TELEPHONY_SERVICE )).listen (phoneStateListener , PhoneStateListener .LISTEN_NONE );
367
+ } catch (SecurityException e ) {
368
+ // we don't have READ_PHONE_STATE
369
+ }
357
370
Overlay overlay = Overlay .getInstance ();
358
371
if (overlay != null ) overlay .hide (true );
359
372
tracker .clear ();
0 commit comments