Skip to content

Commit 208b139

Browse files
committed
Bypass TelephonyManager exceptions (to be fixed later with additional READ_PHONE_STATE permission)
1 parent c3dc4be commit 208b139

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

app/src/main/java/eu/chainfire/holeylight/misc/AODControl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ public static Boolean setAODBrightness(Context context, boolean high, HelperInte
135135
public static Boolean setAODEnabled(Context context, boolean enabled, HelperIntentResultReceiver async) {
136136
if (!Settings.getInstance(context).isAODHelperControl()) return false;
137137
if (isAODEnabled(context) == enabled) return true;
138-
if (((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getCallState() != TelephonyManager.CALL_STATE_IDLE) return false;
138+
try {
139+
if (((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getCallState() != TelephonyManager.CALL_STATE_IDLE) return false;
140+
} catch (SecurityException e) {
141+
// we don't have READ_PHONE_STATE
142+
}
139143
return (Boolean)sendHelperIntent(context, getIntent("SET_AOD", enabled), (context1, intent, resultCode, resultData, resultExtras) -> {
140144
if (resultCode == 1) {
141145
Slog.d("AODControl", "SET_AOD called --> %d", enabled ? 1 : 0);

app/src/main/java/eu/chainfire/holeylight/service/NotificationListenerService.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ public void onCreate() {
266266

267267
tracker = NotificationTracker.getInstance();
268268

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+
}
270275

271276
intentFilter = new IntentFilter();
272277
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
@@ -331,7 +336,11 @@ public void onListenerConnected() {
331336
connected = true;
332337
tracker.clear();
333338
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+
}
335344
registerReceiver(broadcastReceiver, intentFilter);
336345
handleLEDNotifications();
337346
startMotionSensor();
@@ -353,7 +362,11 @@ public void onListenerDisconnected() {
353362
getContentResolver().unregisterContentObserver(refreshLEDObserverSlow);
354363
stopMotionSensor();
355364
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+
}
357370
Overlay overlay = Overlay.getInstance();
358371
if (overlay != null) overlay.hide(true);
359372
tracker.clear();

0 commit comments

Comments
 (0)