Do not print a trace when calling the private finish() overload fails

This commit is contained in:
Alexander Bakker 2022-11-09 20:42:59 +01:00
parent 715c5112ab
commit 9f55d4f659

View file

@ -74,15 +74,20 @@ public abstract class AegisActivity extends AppCompatActivity implements VaultMa
} }
@SuppressLint("SoonBlockedPrivateApi") @SuppressLint("SoonBlockedPrivateApi")
@SuppressWarnings("JavaReflectionMemberAccess")
@Override @Override
public void onLocked(boolean userInitiated) { public void onLocked(boolean userInitiated) {
setResult(RESULT_CANCELED, null); setResult(RESULT_CANCELED, null);
try { try {
// Call a private overload of the finish() method to prevent the app
// from disappearing from the recent apps menu
Method method = Activity.class.getDeclaredMethod("finish", int.class); Method method = Activity.class.getDeclaredMethod("finish", int.class);
method.setAccessible(true); method.setAccessible(true);
method.invoke(this, 2); // FINISH_TASK_WITH_ACTIVITY = 2 method.invoke(this, 2); // FINISH_TASK_WITH_ACTIVITY = 2
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace(); // On recent Android versions, the overload of the finish() method
// used above is no longer accessible
finishAndRemoveTask(); finishAndRemoveTask();
} }
} }