aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-08-11 13:00:57 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-08-11 13:00:57 +0000
commita288c70c5916a67c770b3a6ba2e1809000aa58eb (patch)
tree95dfbe6eb2cefa92190a76aa1a8eb0e6a1983c38 /app
parent31a7c2be3ad39cdeba88515cb7343810f84db249 (diff)
downloadinfinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.tar
infinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.tar.gz
infinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.tar.bz2
infinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.tar.lz
infinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.tar.xz
infinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.tar.zst
infinity-for-reddit-a288c70c5916a67c770b3a6ba2e1809000aa58eb.zip
Secure mode is available.
Diffstat (limited to '')
-rw-r--r--app/build.gradle1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java59
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/values/strings.xml2
-rw-r--r--app/src/main/res/xml/security_preferences.xml6
9 files changed, 83 insertions, 24 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 907a6801..823bf11e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -174,6 +174,7 @@ dependencies {
implementation 'com.github.FunkyMuse:Crashy:1.1.0'
//implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
+ //annotationProcessor "androidx.lifecycle:compiler:2.2.0"
implementation 'androidx.palette:palette:1.0.0'
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 47c27b13..2fc08bd9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -284,4 +284,6 @@ public interface AppComponent {
void inject(TrendingActivity trendingActivity);
void inject(WikiActivity wikiActivity);
+
+ void inject(Infinity infinity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
index 1ea45d67..fafedeac 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
@@ -1,10 +1,13 @@
package ml.docilealligator.infinityforreddit;
+import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Bundle;
+import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -15,15 +18,26 @@ import com.livefront.bridge.Bridge;
import com.livefront.bridge.SavedStateHandler;
import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
+import javax.inject.Inject;
+import javax.inject.Named;
import ml.docilealligator.infinityforreddit.broadcastreceivers.NetworkWifiStatusReceiver;
import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
+import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class Infinity extends Application implements LifecycleObserver {
private AppComponent mAppComponent;
private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver;
+ private boolean lock = false;
+ private boolean isSecureMode;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
@Override
public void onCreate() {
@@ -33,12 +47,16 @@ public class Infinity extends Application implements LifecycleObserver {
.appModule(new AppModule(this))
.build();
- //ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
+ mAppComponent.inject(this);
- /*registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
+ isSecureMode = mSharedPreferences.getBoolean(SharedPreferencesUtils.SECURE_MODE, false);
+
+ registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
- activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
+ if (isSecureMode) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
+ }
}
@Override
@@ -48,7 +66,11 @@ public class Infinity extends Application implements LifecycleObserver {
@Override
public void onActivityResumed(@NonNull Activity activity) {
-
+ /*if (lock && !(activity instanceof LockScreenActivity)) {
+ lock = false;
+ Intent intent = new Intent(activity, LockScreenActivity.class);
+ activity.startActivity(intent);
+ }*/
}
@Override
@@ -70,7 +92,9 @@ public class Infinity extends Application implements LifecycleObserver {
public void onActivityDestroyed(@NonNull Activity activity) {
}
- });*/
+ });
+
+ //ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
@Override
@@ -86,6 +110,8 @@ public class Infinity extends Application implements LifecycleObserver {
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
+ EventBus.getDefault().register(this);
+
mNetworkWifiStatusReceiver =
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext()))));
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
@@ -93,17 +119,22 @@ public class Infinity extends Application implements LifecycleObserver {
registerReceiver(new WallpaperChangeReceiver(), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
}
-// @OnLifecycleEvent(Lifecycle.Event.ON_START)
-// public void appInForeground(){
-// Toast.makeText(this, "Foreground", Toast.LENGTH_SHORT).show();
-// }
-//
-// @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
-// public void appInBackground(){
-// Toast.makeText(this, "Background", Toast.LENGTH_SHORT).show();
-// }
+ /*@OnLifecycleEvent(Lifecycle.Event.ON_START)
+ public void appInForeground() {
+ lock = true;
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+ public void appInBackground(){
+
+ }*/
public AppComponent getAppComponent() {
return mAppComponent;
}
+
+ @Subscribe
+ public void onToggleSecureModeEvent(ToggleSecureModeEvent secureModeEvent) {
+ isSecureMode = secureModeEvent.isSecureMode;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
index 8dc39275..3ba73440 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit.activities;
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -17,9 +20,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
-import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
-
public class LockScreenActivity extends BaseActivity {
@Inject
@@ -79,7 +79,5 @@ public class LockScreenActivity extends BaseActivity {
}
@Override
- public void onBackPressed() {
- moveTaskToBack(true);
- }
+ public void onBackPressed() { }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java
new file mode 100644
index 00000000..a7c27eb3
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.events;
+
+public class ToggleSecureModeEvent {
+ public boolean isSecureMode;
+
+ public ToggleSecureModeEvent(boolean isSecureMode) {
+ this.isSecureMode = isSecureMode;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java
index cb6917c8..c4dd2b16 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit.settings;
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -18,14 +21,12 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
-import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
+import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
-import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
-
public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
private AppCompatActivity activity;
@@ -40,6 +41,7 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
((Infinity) activity.getApplication()).getAppComponent().inject(this);
SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER);
+ SwitchPreference secureModeSwitch = findPreference(SharedPreferencesUtils.SECURE_MODE);
if (requireAuthToAccountSectionSwitch != null) {
requireAuthToAccountSectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
@@ -47,6 +49,13 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ if (secureModeSwitch != null) {
+ secureModeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ToggleSecureModeEvent((Boolean) newValue));
+ return true;
+ });
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index 47b1f109..f3247d99 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -186,6 +186,7 @@ public class SharedPreferencesUtils {
public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed";
public static final String DEFAULT_LINK_POST_LAYOUT_KEY = "default_link_post_layout";
public static final String USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER = "use_bottom_toolbar_in_media_viewer";
+ public static final String SECURE_MODE = "secure_mode";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 847457e2..f0fba961 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -593,6 +593,8 @@
<string name="settings_separate_post_and_comments_in_portrait_mode">Separate Post And Comments in Portrait Mode</string>
<string name="settings_separate_post_and_comments_in_landscape_mode">Separate Post And Comments in Landscape Mode</string>
<string name="settings_use_bottom_toolbar_in_media_viewer_title">Use Bottom Toolbar in Media Viewer</string>
+ <string name="settings_secure_mode_title">Secure Mode</string>
+ <string name="settings_secure_mode_summary">Screenshot and video recording are not allowed. No preview in recent app screen.</string>
<string name="no_link_available">Cannot get the link</string>
diff --git a/app/src/main/res/xml/security_preferences.xml b/app/src/main/res/xml/security_preferences.xml
index d43c2384..636f1798 100644
--- a/app/src/main/res/xml/security_preferences.xml
+++ b/app/src/main/res/xml/security_preferences.xml
@@ -5,4 +5,10 @@
app:key="require_auth_to_account_section"
app:title="@string/settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title" />
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="secure_mode"
+ app:title="@string/settings_secure_mode_title"
+ app:summary="@string/settings_secure_mode_summary" />
+
</PreferenceScreen> \ No newline at end of file