Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c425e29 authored by Stefan Niedermann's avatar Stefan Niedermann Committed by Niedermann IT-Dienstleistungen
Browse files

Fix #1098 Prevent screen capture

parent 0003e8ba
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -3,14 +3,15 @@ package it.niedermann.owncloud.notes;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;

import it.niedermann.owncloud.notes.exception.ExceptionHandler;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
import it.niedermann.owncloud.notes.exception.ExceptionHandler;

public abstract class LockedActivity extends BrandedActivity {

@@ -25,6 +26,10 @@ public abstract class LockedActivity extends BrandedActivity {

        Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));

        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_prevent_screen_capture), false)) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
        }

        if (isTaskRoot()) {
            askToUnlock();
        }
+8 −7
Original line number Diff line number Diff line
@@ -12,13 +12,13 @@ import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.Branded;
import it.niedermann.owncloud.notes.branding.BrandedSwitchPreference;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.persistence.SyncWorker;
import it.niedermann.owncloud.notes.shared.util.DeviceCredentialUtil;
import it.niedermann.owncloud.notes.NotesApplication;

import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets;

@@ -31,6 +31,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
    private BrandedSwitchPreference wifiOnlyPref;
    private BrandedSwitchPreference brandingPref;
    private BrandedSwitchPreference gridViewPref;
    private BrandedSwitchPreference preventScreenCapturePref;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -70,16 +71,15 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
            Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\"");
        }

        preventScreenCapturePref = findPreference(getString(R.string.pref_key_prevent_screen_capture));
        if (preventScreenCapturePref == null) {
            Log.e(TAG, "Could not find \"" + getString(R.string.pref_key_prevent_screen_capture) + "\"-preference.");
        }

        lockPref = findPreference(getString(R.string.pref_key_lock));
        if (lockPref != null) {
            if (!DeviceCredentialUtil.areCredentialsAvailable(requireContext())) {
                lockPref.setVisible(false);
                Preference securityCategory = findPreference(getString(R.string.pref_category_security));
                if (securityCategory != null) {
                    securityCategory.setVisible(false);
                } else {
                    Log.e(TAG, "Could not find preference " + getString(R.string.pref_category_security));
                }
            } else {
                lockPref.setOnPreferenceChangeListener((preference, newValue) -> {
                    NotesApplication.setLockedPreference((Boolean) newValue);
@@ -134,5 +134,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
        wifiOnlyPref.applyBrand(mainColor, textColor);
        brandingPref.applyBrand(mainColor, textColor);
        gridViewPref.applyBrand(mainColor, textColor);
        preventScreenCapturePref.applyBrand(mainColor, textColor);
    }
}
+5 −0
Original line number Diff line number Diff line
<vector android:height="24dp" android:tint="#757575"
    android:viewportHeight="24" android:viewportWidth="24"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M10,16h4c0.55,0 1,-0.45 1,-1v-3c0,-0.55 -0.45,-1 -1,-1v-1c0,-1.11 -0.9,-2 -2,-2 -1.11,0 -2,0.9 -2,2v1c-0.55,0 -1,0.45 -1,1v3c0,0.55 0.45,1 1,1zM10.8,10c0,-0.66 0.54,-1.2 1.2,-1.2 0.66,0 1.2,0.54 1.2,1.2v1h-2.4v-1zM17,1L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-2 -2,-2zM17,19L7,19L7,5h10v14z"/>
</vector>
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
    <string name="settings_lock">App lock (Beta)</string>
    <string name="settings_lock_summary">Device credentials</string>
    <string name="settings_background_sync">Background synchronization</string>
    <string name="settings_prevent_screen_capture">Prevent screen capture</string>

    <string name="error_sync">Synchronization failed: %1$s</string>
    <string name="error_synchronization">Synchronization failed</string>
@@ -103,6 +104,7 @@
    <string name="pref_key_font_size" translatable="false">fontSize</string>
    <string name="pref_key_wifi_only" translatable="false">wifiOnly</string>
    <string name="pref_key_lock" translatable="false">lock</string>
    <string name="pref_key_prevent_screen_capture" translatable="false">preventScreenCapture</string>
    <string name="pref_category_security" translatable="false">security</string>
    <string name="pref_key_last_note_mode" translatable="false">lastNoteMode</string>
    <string name="pref_key_background_sync" translatable="false">backgroundSync</string>
+7 −0
Original line number Diff line number Diff line
@@ -95,6 +95,13 @@
            android:layout="@layout/item_pref"
            android:summary="@string/settings_lock_summary"
            android:title="@string/settings_lock" />

        <it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
            android:defaultValue="false"
            android:icon="@drawable/ic_baseline_screen_lock_portrait_24"
            android:key="@string/pref_key_prevent_screen_capture"
            android:layout="@layout/item_pref"
            android:title="@string/settings_prevent_screen_capture" />
    </it.niedermann.owncloud.notes.branding.BrandedPreferenceCategory>

</PreferenceScreen>