From cebeb37a384ac73757fbdec52a06b281f9e19f03 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Fri, 14 Jan 2022 12:51:19 +0100 Subject: [PATCH] Fix CaptureCtrl crash on Android 11/12 The CaptureCtrl is only started when the PCAPdroid control API is invoked. The crash occurred because getInsetsController was called before setContentView. Fixes #179 --- app/src/main/java/com/emanuelef/remote_capture/Utils.java | 2 +- .../com/emanuelef/remote_capture/activities/CaptureCtrl.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/Utils.java b/app/src/main/java/com/emanuelef/remote_capture/Utils.java index 8f086df4..92118d67 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/Utils.java +++ b/app/src/main/java/com/emanuelef/remote_capture/Utils.java @@ -922,7 +922,7 @@ public class Utils { return BuildType.WORKFLOW; } } catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) { - Log.e("Utils", "Could not retrieve package version"); + Log.e("Utils", "Could not determine the build type"); } return BuildType.UNKNOWN; } diff --git a/app/src/main/java/com/emanuelef/remote_capture/activities/CaptureCtrl.java b/app/src/main/java/com/emanuelef/remote_capture/activities/CaptureCtrl.java index 67461116..f07a5bae 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/activities/CaptureCtrl.java +++ b/app/src/main/java/com/emanuelef/remote_capture/activities/CaptureCtrl.java @@ -65,7 +65,11 @@ public class CaptureCtrl extends AppCompatActivity { @Override @SuppressWarnings("deprecation") protected void onCreate(@Nullable Bundle savedInstanceState) { + // Important: calls must occur in the following order: + // requestWindowFeature -> setContentView -> getInsetsController() requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.ctrl_consent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { final WindowInsetsController insetsController = getWindow().getInsetsController(); if (insetsController != null) @@ -115,7 +119,6 @@ public class CaptureCtrl extends AppCompatActivity { } // Show authorization window - setContentView(R.layout.ctrl_consent); findViewById(R.id.allow_btn).setOnClickListener(v -> controlAction(intent, action, true)); findViewById(R.id.deny_btn).setOnClickListener(v -> controlAction(intent, action, false));