The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/android: Run spotlessApply to format Java and Kotlin code

+114 -126
+1 -3
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/IServiceNotification.kt
··· 26 26 */ 27 27 fun buildNotification(context: Context, pendingShutdownIntent: PendingIntent): Notification 28 28 29 - /** 30 - * Return the notification ID to use 31 - */ 29 + /** Return the notification ID to use */ 32 30 fun getNotificationId(): Int 33 31 }
+60 -68
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/MonadoView.java
··· 24 24 import androidx.annotation.NonNull; 25 25 import androidx.annotation.Nullable; 26 26 27 - import java.util.Calendar; 28 - 29 27 @Keep 30 - public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, SurfaceHolder.Callback2 { 28 + public class MonadoView extends SurfaceView 29 + implements SurfaceHolder.Callback, SurfaceHolder.Callback2 { 31 30 private static final String TAG = "MonadoView"; 32 31 33 - @NonNull 34 - private final Context context; 32 + @NonNull private final Context context; 35 33 36 34 /// The activity we've connected to. 37 - @Nullable 38 - private final Activity activity; 35 + @Nullable private final Activity activity; 39 36 private final Object currentSurfaceHolderSync = new Object(); 40 37 41 38 public int width = -1; ··· 44 41 45 42 private NativeCounterpart nativeCounterpart; 46 43 47 - @GuardedBy("currentSurfaceHolderSync") 48 - @Nullable 49 - private SurfaceHolder currentSurfaceHolder = null; 44 + @GuardedBy("currentSurfaceHolderSync") @Nullable private SurfaceHolder currentSurfaceHolder = null; 50 45 51 46 private SystemUiController systemUiController = null; 52 47 ··· 80 75 /** 81 76 * Construct and start attaching a MonadoView to a client application. 82 77 * 83 - * @param activity The activity to attach to. 78 + * @param activity The activity to attach to. 84 79 * @param nativePointer The native android_custom_surface pointer, cast to a long. 85 80 * @return The MonadoView instance created and asynchronously attached. 86 81 */ 87 - @NonNull 88 - @Keep 82 + @NonNull @Keep 89 83 @SuppressWarnings("deprecation") 90 - public static MonadoView attachToActivity(@NonNull final Activity activity, long nativePointer) { 84 + public static MonadoView attachToActivity( 85 + @NonNull final Activity activity, long nativePointer) { 91 86 final MonadoView view = new MonadoView(activity, nativePointer); 92 87 view.createSurfaceInActivity(); 93 88 return view; 94 89 } 95 90 96 - @NonNull 97 - @Keep 91 + @NonNull @Keep 98 92 public static MonadoView attachToActivity(@NonNull final Activity activity) { 99 93 final MonadoView view = new MonadoView(activity); 100 94 view.createSurfaceInActivity(); 101 95 return view; 102 96 } 103 97 104 - @NonNull 105 - @Keep 98 + @NonNull @Keep 106 99 public static DisplayMetrics getDisplayMetrics(@NonNull Context context) { 107 100 DisplayMetrics displayMetrics = new DisplayMetrics(); 108 101 WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); ··· 128 121 createSurfaceInActivity(false); 129 122 } 130 123 131 - /** 132 - * @param focusable Indicates MonadoView should be focusable or not 133 - */ 124 + /** @param focusable Indicates MonadoView should be focusable or not */ 134 125 private void createSurfaceInActivity(boolean focusable) { 135 126 Log.i(TAG, "Starting to add a new surface!"); 136 - activity.runOnUiThread(() -> { 137 - Log.i(TAG, "Starting runOnUiThread"); 138 - activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 127 + activity.runOnUiThread( 128 + () -> { 129 + Log.i(TAG, "Starting runOnUiThread"); 130 + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 139 131 140 - WindowManager windowManager = activity.getWindowManager(); 141 - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 142 - if (focusable) { 143 - lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN; 144 - } else { 145 - // There are 2 problems if view is focusable on all-in-one device: 146 - // 1. Navigation bar won't go away because view gets focus. 147 - // 2. Underlying activity lost focus and cannot receive input. 148 - lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN | 149 - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 150 - } 151 - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 152 - lp.layoutInDisplayCutoutMode = 153 - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; 154 - } 155 - windowManager.addView(this, lp); 156 - if (focusable) { 157 - requestFocus(); 158 - } 159 - SurfaceHolder surfaceHolder = getHolder(); 160 - surfaceHolder.addCallback(this); 161 - Log.i(TAG, "Registered callbacks!"); 162 - }); 132 + WindowManager windowManager = activity.getWindowManager(); 133 + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 134 + if (focusable) { 135 + lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN; 136 + } else { 137 + // There are 2 problems if view is focusable on all-in-one device: 138 + // 1. Navigation bar won't go away because view gets focus. 139 + // 2. Underlying activity lost focus and cannot receive input. 140 + lp.flags = 141 + WindowManager.LayoutParams.FLAG_FULLSCREEN 142 + | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 143 + } 144 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 145 + lp.layoutInDisplayCutoutMode = 146 + WindowManager.LayoutParams 147 + .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; 148 + } 149 + windowManager.addView(this, lp); 150 + if (focusable) { 151 + requestFocus(); 152 + } 153 + SurfaceHolder surfaceHolder = getHolder(); 154 + surfaceHolder.addCallback(this); 155 + Log.i(TAG, "Registered callbacks!"); 156 + }); 163 157 } 164 158 165 159 /** 166 160 * Block up to a specified amount of time, waiting for the surfaceCreated callback to be fired 167 161 * and populate the currentSurfaceHolder. 168 - * <p> 169 - * If it returns a SurfaceHolder, the `usedByNativeCode` flag will be set. 170 - * <p> 171 - * Called by native code! 162 + * 163 + * <p>If it returns a SurfaceHolder, the `usedByNativeCode` flag will be set. 164 + * 165 + * <p>Called by native code! 172 166 * 173 167 * @param wait_ms Max duration you prefer to wait, in milliseconds. Spurious wakeups mean this 174 - * not be totally precise. 168 + * not be totally precise. 175 169 * @return A SurfaceHolder or null. 176 170 */ 177 171 @Keep 178 - public @Nullable 179 - SurfaceHolder waitGetSurfaceHolder(int wait_ms) { 172 + public @Nullable SurfaceHolder waitGetSurfaceHolder(int wait_ms) { 180 173 long currentTime = SystemClock.uptimeMillis(); 181 174 long timeout = currentTime + wait_ms; 182 175 SurfaceHolder ret = null; 183 176 synchronized (currentSurfaceHolderSync) { 184 177 ret = currentSurfaceHolder; 185 - while (currentSurfaceHolder == null 186 - && SystemClock.uptimeMillis() < timeout) { 178 + while (currentSurfaceHolder == null && SystemClock.uptimeMillis() < timeout) { 187 179 try { 188 180 currentSurfaceHolderSync.wait(wait_ms, 0); 189 181 ret = currentSurfaceHolder; ··· 194 186 } 195 187 } 196 188 if (ret != null) { 197 - if (nativeCounterpart != null) 198 - nativeCounterpart.markAsUsedByNativeCode(); 189 + if (nativeCounterpart != null) nativeCounterpart.markAsUsedByNativeCode(); 199 190 } 200 191 return ret; 201 192 } ··· 203 194 /** 204 195 * Change the flag and notify those waiting on it, to indicate that native code is done with 205 196 * this object. 206 - * <p> 207 - * Called by native code! 197 + * 198 + * <p>Called by native code! 208 199 */ 209 200 @Keep 210 201 public void markAsDiscardedByNative() { 211 - if (nativeCounterpart != null) 212 - nativeCounterpart.markAsDiscardedByNative(TAG); 202 + if (nativeCounterpart != null) nativeCounterpart.markAsDiscardedByNative(TAG); 213 203 } 214 204 215 205 @Override ··· 222 212 } 223 213 224 214 @Override 225 - public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int format, int width, int height) { 215 + public void surfaceChanged( 216 + @NonNull SurfaceHolder surfaceHolder, int format, int width, int height) { 226 217 227 218 synchronized (currentSurfaceHolderSync) { 228 219 currentSurfaceHolder = surfaceHolder; ··· 245 236 } 246 237 } 247 238 if (lost) { 248 - //! @todo this function should notify native code that the surface is gone. 239 + // ! @todo this function should notify native code that the surface is gone. 249 240 if (nativeCounterpart != null && !nativeCounterpart.blockUntilNativeDiscard(TAG)) { 250 - Log.i(TAG, 251 - "Interrupted in surfaceDestroyed while waiting for native code to finish up."); 241 + Log.i( 242 + TAG, 243 + "Interrupted in surfaceDestroyed while waiting for native code to finish" 244 + + " up."); 252 245 } 253 246 } 254 247 } 255 248 256 249 @Override 257 250 public void surfaceRedrawNeeded(@NonNull SurfaceHolder surfaceHolder) { 258 - // currentSurfaceHolder = surfaceHolder; 251 + // currentSurfaceHolder = surfaceHolder; 259 252 Log.i(TAG, "surfaceRedrawNeeded"); 260 253 } 261 - 262 254 }
+3 -4
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/NameAndLogoProvider.kt
··· 17 17 * Intended for use in dependency injection. 18 18 */ 19 19 interface NameAndLogoProvider { 20 - /** 21 - * Gets a localized runtime name string for the runtime/Monado-incorporating target. 22 - */ 20 + /** Gets a localized runtime name string for the runtime/Monado-incorporating target. */ 23 21 fun getLocalizedRuntimeName(): CharSequence 24 22 25 23 /** 26 - * Gets a drawable for use in the about activity and elsewhere, for the runtime/Monado-incorporating target. 24 + * Gets a drawable for use in the about activity and elsewhere, for the 25 + * runtime/Monado-incorporating target. 27 26 */ 28 27 fun getLogoDrawable(): Drawable? 29 28 }
+22 -23
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/NativeCounterpart.java
··· 20 20 * Object that tracks the native counterpart object for a type. Must be initialized on construction, 21 21 * and may have its native code destroyed/discarded, but may not "re-seat" it to new native code 22 22 * pointer. 23 - * <p> 24 - * Use as a member of any type with a native counterpart (a native-allocated-and-owned object that 25 - * holds a reference to the owning class). Include the following field and delegating method to use 26 - * (note: assumes you have a tag for logging purposes as TAG) 23 + * 24 + * <p>Use as a member of any type with a native counterpart (a native-allocated-and-owned object 25 + * that holds a reference to the owning class). Include the following field and delegating method to 26 + * use (note: assumes you have a tag for logging purposes as TAG) 27 + * 27 28 * <p> 29 + * 28 30 * <pre> 29 31 * private final NativeCounterpart nativeCounterpart; 30 32 * ··· 33 35 * nativeCounterpart.markAsDiscardedByNative(TAG); 34 36 * } 35 37 * </pre> 38 + * 36 39 * Then, initialize it in your constructor, call {@code markAsUsedByNativeCode()} where desired 37 - * (often in your constructor), and call {@code getNativePointer()} and 38 - * {@code blockUntilNativeDiscard()} as needed. 39 - * <p> 40 - * Your native code can use this to turn a void* into a jlong: 41 - * {@code static_cast<long long>(reinterpret_cast<intptr_t>(nativePointer))} 40 + * (often in your constructor), and call {@code getNativePointer()} and {@code 41 + * blockUntilNativeDiscard()} as needed. 42 + * 43 + * <p>Your native code can use this to turn a void* into a jlong: {@code static_cast<long 44 + * long>(reinterpret_cast<intptr_t>(nativePointer))} 42 45 */ 43 46 public final class NativeCounterpart { 44 - /** 45 - * Guards the usedByNativeCodeSync. 46 - */ 47 + /** Guards the usedByNativeCodeSync. */ 47 48 private final Object usedByNativeCodeSync = new Object(); 48 49 49 50 /** 50 51 * Indicates if the containing object is in use by native code. 51 - * <p> 52 - * Guarded by usedByNativeCodeSync. 52 + * 53 + * <p>Guarded by usedByNativeCodeSync. 53 54 */ 54 55 private boolean usedByNativeCode = false; 55 56 56 - /** 57 - * Contains the pointer to the native counterpart object. 58 - */ 57 + /** Contains the pointer to the native counterpart object. */ 59 58 private long nativePointer = 0; 60 59 61 60 /** 62 61 * Constructor 63 62 * 64 63 * @param nativePointer The native pointer, cast appropriately. Must be non-zero. Can cast like: 65 - * {@code static_cast<long long>(reinterpret_cast<intptr_t>(nativePointer))} 64 + * {@code static_cast<long long>(reinterpret_cast<intptr_t>(nativePointer))} 66 65 */ 67 66 public NativeCounterpart(long nativePointer) throws InvalidParameterException { 68 67 if (nativePointer == 0) { ··· 92 91 public void markAsDiscardedByNative(String TAG) { 93 92 synchronized (usedByNativeCodeSync) { 94 93 if (!usedByNativeCode) { 95 - Log.w(TAG, 96 - "This should not have happened: Discarding by native code, but not marked as used!"); 94 + Log.w( 95 + TAG, 96 + "This should not have happened: Discarding by native code, but not marked" 97 + + " as used!"); 97 98 } 98 99 usedByNativeCode = false; 99 100 nativePointer = 0; ··· 130 131 } 131 132 } catch (InterruptedException e) { 132 133 e.printStackTrace(); 133 - Log.i(TAG, 134 - "Interrupted while waiting for native code to finish up: " + e); 134 + Log.i(TAG, "Interrupted while waiting for native code to finish up: " + e); 135 135 return false; 136 136 } 137 - 138 137 } 139 138 }
+27 -24
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/SystemUiController.kt
··· 15 15 import android.view.WindowInsetsController 16 16 import androidx.annotation.RequiresApi 17 17 18 - /** 19 - * Helper class that handles system ui visibility. 20 - */ 18 + /** Helper class that handles system ui visibility. */ 21 19 class SystemUiController(activity: Activity) { 22 - private val impl: Impl = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 23 - WindowInsetsControllerImpl(activity) 24 - } else { 25 - SystemUiVisibilityImpl(activity) 26 - } 20 + private val impl: Impl = 21 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 22 + WindowInsetsControllerImpl(activity) 23 + } else { 24 + SystemUiVisibilityImpl(activity) 25 + } 27 26 28 - /** 29 - * Hide system ui and make fullscreen. 30 - */ 27 + /** Hide system ui and make fullscreen. */ 31 28 fun hide() { 32 29 impl.hide() 33 30 } ··· 51 48 private const val FLAG_FULL_SCREEN_IMMERSIVE_STICKY = 52 49 // Give us a stable view of content insets 53 50 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE // Be able to do fullscreen and hide navigation 54 - or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 55 - or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 56 - or View.SYSTEM_UI_FLAG_FULLSCREEN 57 - or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // we want sticky immersive 58 - or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) 51 + or 52 + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or 53 + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or 54 + View.SYSTEM_UI_FLAG_FULLSCREEN or 55 + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // we want sticky immersive 56 + or 57 + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) 59 58 } 60 59 61 60 init { ··· 75 74 override fun hide() { 76 75 activity.runOnUiThread { 77 76 val controller = activity.window.insetsController 78 - controller!!.hide(WindowInsets.Type.displayCutout() 79 - or WindowInsets.Type.statusBars() 80 - or WindowInsets.Type.navigationBars()) 77 + controller!!.hide( 78 + WindowInsets.Type.displayCutout() or 79 + WindowInsets.Type.statusBars() or 80 + WindowInsets.Type.navigationBars() 81 + ) 81 82 controller.systemBarsBehavior = 82 83 WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE 83 84 } ··· 85 86 86 87 init { 87 88 runOnUiThread { 88 - activity.window.insetsController!!.addOnControllableInsetsChangedListener { _: WindowInsetsController?, typeMask: Int -> 89 - if (typeMask and WindowInsets.Type.displayCutout() == 1 90 - || typeMask and WindowInsets.Type.statusBars() == 1 91 - || typeMask and WindowInsets.Type.navigationBars() == 1 89 + activity.window.insetsController!!.addOnControllableInsetsChangedListener { 90 + _: WindowInsetsController?, 91 + typeMask: Int -> 92 + if ( 93 + typeMask and WindowInsets.Type.displayCutout() == 1 || 94 + typeMask and WindowInsets.Type.statusBars() == 1 || 95 + typeMask and WindowInsets.Type.navigationBars() == 1 92 96 ) { 93 97 hide() 94 98 } ··· 96 100 } 97 101 } 98 102 } 99 - 100 103 }
+1 -4
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/UiProvider.kt
··· 24 24 */ 25 25 fun getNotificationIcon(): Icon? = null 26 26 27 - /** 28 - * Make a {@code PendingIntent} to launch an "About" activity for the runtime/target. 29 - */ 27 + /** Make a {@code PendingIntent} to launch an "About" activity for the runtime/target. */ 30 28 fun makeAboutActivityPendingIntent(): PendingIntent 31 29 32 30 /** 33 31 * Make a {@code PendingIntent} to launch a configuration activity, if provided by the target. 34 32 */ 35 33 fun makeConfigureActivityPendingIntent(): PendingIntent? = null 36 - 37 34 }