From c8338b2918d81d0238a7254ec2a6556211beb957 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 4 May 2019 14:41:38 +0200 Subject: [PATCH] Recover if expand/collapse panels is not available Some devices don't have the required method. Recover gracefully without crashing the server. Fixes . --- .../scrcpy/wrappers/StatusBarManager.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java index 8f79f51f..e8723ff5 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java @@ -2,38 +2,50 @@ package com.genymobile.scrcpy.wrappers; import android.os.IInterface; +import com.genymobile.scrcpy.Ln; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class StatusBarManager { private final IInterface manager; - private final Method expandNotificationsPanelMethod; - private final Method collapsePanelsMethod; + private Method expandNotificationsPanelMethod; + private Method collapsePanelsMethod; public StatusBarManager(IInterface manager) { this.manager = manager; - try { - expandNotificationsPanelMethod = manager.getClass().getMethod("expandNotificationsPanel"); - collapsePanelsMethod = manager.getClass().getMethod("collapsePanels"); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } } public void expandNotificationsPanel() { + if (expandNotificationsPanelMethod == null) { + try { + expandNotificationsPanelMethod = manager.getClass().getMethod("expandNotificationsPanel"); + } catch (NoSuchMethodException e) { + Ln.e("ServiceBarManager.expandNotificationsPanel() is not available on this device"); + return; + } + } try { expandNotificationsPanelMethod.invoke(manager); } catch (InvocationTargetException | IllegalAccessException e) { - throw new AssertionError(e); + Ln.e("Cannot invoke ServiceBarManager.expandNotificationsPanel()", e); } } public void collapsePanels() { + if (collapsePanelsMethod == null) { + try { + collapsePanelsMethod = manager.getClass().getMethod("collapsePanels"); + } catch (NoSuchMethodException e) { + Ln.e("ServiceBarManager.collapsePanels() is not available on this device"); + return; + } + } try { collapsePanelsMethod.invoke(manager); } catch (InvocationTargetException | IllegalAccessException e) { - throw new AssertionError(e); + Ln.e("Cannot invoke ServiceBarManager.collapsePanels()", e); } } }