@ -84,9 +84,8 @@ public final class SurfaceControl {
}
}
private static Method getGetBuiltInDisplayMethod ( ) {
private static Method getGetBuiltInDisplayMethod ( ) throws NoSuchMethodException {
if ( getBuiltInDisplayMethod = = null ) {
try {
// the method signature has changed in Android Q
// <https://github.com/Genymobile/scrcpy/issues/586>
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . Q ) {
@ -94,19 +93,14 @@ public final class SurfaceControl {
} else {
getBuiltInDisplayMethod = CLASS . getMethod ( "getInternalDisplayToken" ) ;
}
} catch ( NoSuchMethodException e ) {
Ln . e ( "Could not find method" , e ) ;
}
}
return getBuiltInDisplayMethod ;
}
public static IBinder getBuiltInDisplay ( ) {
Method method = getGetBuiltInDisplayMethod ( ) ;
if ( method = = null ) {
return null ;
}
try {
Method method = getGetBuiltInDisplayMethod ( ) ;
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . Q ) {
// call getBuiltInDisplay(0)
return ( IBinder ) method . invoke ( null , 0 ) ;
@ -114,32 +108,25 @@ public final class SurfaceControl {
// call getInternalDisplayToken()
return ( IBinder ) method . invoke ( null ) ;
} catch ( InvocationTargetException | IllegalAccessException e ) {
Ln . e ( "Could not invoke " + method . getName ( ) , e ) ;
} catch ( InvocationTargetException | IllegalAccessException | NoSuchMethodException e ) {
Ln . e ( "Could not invoke method" , e ) ;
return null ;
}
}
private static Method getSetDisplayPowerModeMethod ( ) {
private static Method getSetDisplayPowerModeMethod ( ) throws NoSuchMethodException {
if ( setDisplayPowerModeMethod = = null ) {
try {
setDisplayPowerModeMethod = CLASS . getMethod ( "setDisplayPowerMode" , IBinder . class , int . class ) ;
} catch ( NoSuchMethodException e ) {
Ln . e ( "Could not find method" , e ) ;
}
}
return setDisplayPowerModeMethod ;
}
public static void setDisplayPowerMode ( IBinder displayToken , int mode ) {
Method method = getSetDisplayPowerModeMethod ( ) ;
if ( method = = null ) {
return ;
}
try {
Method method = getSetDisplayPowerModeMethod ( ) ;
method . invoke ( null , displayToken , mode ) ;
} catch ( InvocationTargetException | IllegalAccessException e ) {
Ln . e ( "Could not invoke " + method . getName ( ) , e ) ;
} catch ( InvocationTargetException | IllegalAccessException | NoSuchMethodException e ) {
Ln . e ( "Could not invoke method" , e ) ;
}
}