From e91fc225e1c9757aa4c78fd753ed6ae7c7df76ae Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 31 Dec 2015 21:53:14 +0100 Subject: [PATCH] after receiving panic trigger, quit remove from history This makes the app fully exit, and removes it from the Recent Apps listing with the goal of hiding whatever the user was currently watching, and/or searching for. PanicKit provides a common framework for creating "panic button" apps that can trigger actions in "panic responder" apps. In this case, the response is to lock the app, if it has been configured to do so https://dev.guardianproject.info/projects/panic/wiki --- app/src/main/AndroidManifest.xml | 13 +++++++ .../java/org/schabi/newpipe/ExitActivity.java | 36 +++++++++++++++++++ .../newpipe/PanicResponderActivity.java | 32 +++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 app/src/main/java/org/schabi/newpipe/ExitActivity.java create mode 100644 app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05eda83c5..ae3f5f056 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -84,5 +84,18 @@ android:name=".SettingsActivity" android:label="@string/title_activity_settings" > + + + + + + + diff --git a/app/src/main/java/org/schabi/newpipe/ExitActivity.java b/app/src/main/java/org/schabi/newpipe/ExitActivity.java new file mode 100644 index 000000000..c193ffbde --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/ExitActivity.java @@ -0,0 +1,36 @@ + +package org.schabi.newpipe; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; + +public class ExitActivity extends Activity { + + @SuppressLint("NewApi") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (Build.VERSION.SDK_INT >= 21) { + finishAndRemoveTask(); + } else { + finish(); + } + + System.exit(0); + } + + public static void exitAndRemoveFromRecentApps(Activity activity) { + Intent intent = new Intent(activity, ExitActivity.class); + + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS + | Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_NO_ANIMATION); + + activity.startActivity(intent); + } +} diff --git a/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java b/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java new file mode 100644 index 000000000..e9bf0e985 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java @@ -0,0 +1,32 @@ + +package org.schabi.newpipe; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; + +public class PanicResponderActivity extends Activity { + + public static final String PANIC_TRIGGER_ACTION = "info.guardianproject.panic.action.TRIGGER"; + + @SuppressLint("NewApi") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Intent intent = getIntent(); + if (intent != null && PANIC_TRIGGER_ACTION.equals(intent.getAction())) { + // TODO explicitly clear the search results once they are restored when the app restarts + // or if the app reloads the current video after being killed, that should be cleared also + ExitActivity.exitAndRemoveFromRecentApps(this); + } + + if (Build.VERSION.SDK_INT >= 21) { + finishAndRemoveTask(); + } else { + finish(); + } + } +}