Secure mode is available.

This commit is contained in:
Alex Ning 2021-08-11 21:00:57 +08:00
parent 31a7c2be3a
commit a288c70c59
9 changed files with 83 additions and 24 deletions

View File

@ -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'

View File

@ -284,4 +284,6 @@ public interface AppComponent {
void inject(TrendingActivity trendingActivity);
void inject(WikiActivity wikiActivity);
void inject(Infinity infinity);
}

View File

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

View File

@ -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() { }
}

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.events;
public class ToggleSecureModeEvent {
public boolean isSecureMode;
public ToggleSecureModeEvent(boolean isSecureMode) {
this.isSecureMode = isSecureMode;
}
}

View File

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

View File

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

View File

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

View File

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