Skip to content

Commit

Permalink
[VisionGlass] Sanitize the usage of FLAG_KEEP_SCREEN_ON
Browse files Browse the repository at this point in the history
The correct way to use it is:
1. Enable it *after* calling setContentView()
2. Enable it in onResume()
3. Disable it in onPause()

We had duplicated calls in onCreate() instead.
  • Loading branch information
svillar committed Jan 10, 2025
1 parent 38044a8 commit fc1f9f7
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ private void onConnectionStateChanged(PhoneUIViewModel.ConnectionState connectio

private void initVisionGlassPhoneUI() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setTheme(R.style.FxR_Dark);

ContextThemeWrapper themedContext = new ContextThemeWrapper(this, R.style.Theme_WolvicPhone);
LayoutInflater themedInflater = getLayoutInflater().cloneInContext(themedContext);
mBinding = DataBindingUtil.setContentView(this, R.layout.visionglass_layout);
mBinding = DataBindingUtil.inflate(themedInflater, R.layout.visionglass_layout, null, false);
setContentView(mBinding.getRoot());
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mViewModel = new ViewModelProvider(this).get(PhoneUIViewModel.class);
mBinding.setViewModel(mViewModel);
Expand All @@ -265,8 +265,6 @@ private void initVisionGlassPhoneUI() {

Button backButton = findViewById(R.id.back_button);
backButton.setOnClickListener(v -> onBackPressed());

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

private void showAlertDialog(String description) {
Expand Down Expand Up @@ -404,6 +402,7 @@ public boolean onGenericMotionEvent(MotionEvent aEvent) {
protected void onPause() {
Log.d(LOGTAG, "PlatformActivity onPause");
super.onPause();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

// This check is needed to prevent a crash when pausing before 3D mode has started.
if (mActivePresentation != null) {
Expand All @@ -425,6 +424,7 @@ protected void onPause() {
protected void onResume() {
Log.d(LOGTAG, "PlatformActivity onResume");
super.onResume();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

registerPhoneIMUListener();

Expand Down

0 comments on commit fc1f9f7

Please sign in to comment.