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
This commit is contained in:
emanuele-f 2022-01-14 12:51:19 +01:00
parent e7bc6ba8d1
commit cebeb37a38
2 changed files with 5 additions and 2 deletions

View File

@ -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;
}

View File

@ -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));