Selaa lähdekoodia

Merge pull request #3740 from nextcloud/ezaquarii/refactor-lock-prefs

Move lock prefs to AppPreferences
Andy Scherzinger 6 vuotta sitten
vanhempi
commit
c1fe45749e

+ 36 - 0
src/main/java/com/nextcloud/client/preferences/AppPreferences.java

@@ -112,6 +112,35 @@ public interface AppPreferences {
      */
      */
     void setLastUploadPath(String path);
     void setLastUploadPath(String path);
 
 
+    String getLockPreference();
+    void setLockPreference(String lockPreference);
+
+    /**
+     * Set pass code composed of 4 digits (as strings).
+     *
+     * @todo This must be refactored further to use a passcode stype
+     * @param d1 1st digit
+     * @param d2 2nd digit
+     * @param d3 3rd digit
+     * @param d4 4th digit
+     */
+    void setPassCode(String d1, String d2, String d3, String d4);
+
+    /**
+     * Get 4-digit passcode as array of strings. Strings may be null.
+     *
+     * @return 4 strings with digits or nulls
+     */
+    String[] getPassCode();
+
+    /**
+     * Gets the unlock via fingerprint preference configured by the user.
+     *
+     * @implNote  this is always false
+     * @return useFingerprint     is unlock with fingerprint enabled
+     */
+    boolean isFingerprintUnlockEnabled();
+
     /**
     /**
      * Gets the auto upload paths flag last set.
      * Gets the auto upload paths flag last set.
      *
      *
@@ -213,4 +242,11 @@ public interface AppPreferences {
     void setLastSeenVersionCode(int versionCode);
     void setLastSeenVersionCode(int versionCode);
 
 
     void removeLegacyPreferences();
     void removeLegacyPreferences();
+
+    /**
+     * Clears all user preferences.
+     *
+     * @implNote this clears only shared preferences, not preferences kept in account manager
+     */
+    void clear();
 }
 }

+ 38 - 16
src/main/java/com/nextcloud/client/preferences/PreferenceManager.java

@@ -27,6 +27,7 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.ui.activity.PassCodeActivity;
 import com.owncloud.android.ui.activity.SettingsActivity;
 import com.owncloud.android.ui.activity.SettingsActivity;
 import com.owncloud.android.utils.FileSortOrder;
 import com.owncloud.android.utils.FileSortOrder;
 
 
@@ -63,6 +64,7 @@ public final class PreferenceManager implements AppPreferences {
     private static final String PREF__FOLDER_LAYOUT = "folder_layout";
     private static final String PREF__FOLDER_LAYOUT = "folder_layout";
     public static final String PREF__LOCK_TIMESTAMP = "lock_timestamp";
     public static final String PREF__LOCK_TIMESTAMP = "lock_timestamp";
     private static final String PREF__SHOW_MEDIA_SCAN_NOTIFICATIONS = "show_media_scan_notifications";
     private static final String PREF__SHOW_MEDIA_SCAN_NOTIFICATIONS = "show_media_scan_notifications";
+    private static final String PREF__LOCK = SettingsActivity.PREFERENCE_LOCK;
 
 
     private final Context context;
     private final Context context;
     private final SharedPreferences preferences;
     private final SharedPreferences preferences;
@@ -156,24 +158,39 @@ public final class PreferenceManager implements AppPreferences {
         preferences.edit().putString(AUTO_PREF__LAST_UPLOAD_PATH, path).apply();
         preferences.edit().putString(AUTO_PREF__LAST_UPLOAD_PATH, path).apply();
     }
     }
 
 
-    /**
-     * Gets the lock preference configured by the user.
-     *
-     * @param context Caller {@link Context}, used to access to shared preferences manager.
-     * @return lock     lock preference value.
-     */
-    public static String getLockPreference(Context context) {
-        return getDefaultSharedPreferences(context).getString(SettingsActivity.PREFERENCE_LOCK, "");
+    @Override
+    public String getLockPreference() {
+        return preferences.getString(PREF__LOCK, SettingsActivity.LOCK_NONE);
     }
     }
 
 
-    /**
-     * Gets the lock via fingerprint preference configured by the user.
-     *
-     * @param context Caller {@link Context}, used to access to shared preferences manager.
-     * @return useFingerprint     is lock via fingerprint preference.
-     */
-    public static boolean isUseFingerprint(Context context) {
-        return getDefaultSharedPreferences(context).getBoolean(SettingsActivity.PREFERENCE_USE_FINGERPRINT, false);
+    @Override
+    public void setLockPreference(String lockPreference) {
+        preferences.edit().putString(PREF__LOCK, lockPreference).apply();
+    }
+
+    @Override
+    public void setPassCode(String d1, String d2, String d3, String d4) {
+        preferences
+            .edit()
+            .putString(PassCodeActivity.PREFERENCE_PASSCODE_D1, d1)
+            .putString(PassCodeActivity.PREFERENCE_PASSCODE_D2, d2)
+            .putString(PassCodeActivity.PREFERENCE_PASSCODE_D3, d3)
+            .putString(PassCodeActivity.PREFERENCE_PASSCODE_D4, d4)
+            .apply();
+    }
+
+    @Override
+    public String[] getPassCode() {
+        return new String[] {
+            preferences.getString(PassCodeActivity.PREFERENCE_PASSCODE_D1, null),
+            preferences.getString(PassCodeActivity.PREFERENCE_PASSCODE_D2, null),
+            preferences.getString(PassCodeActivity.PREFERENCE_PASSCODE_D3, null),
+            preferences.getString(PassCodeActivity.PREFERENCE_PASSCODE_D4, null),
+        };
+    }
+
+    public boolean isFingerprintUnlockEnabled() {
+        return preferences.getBoolean(SettingsActivity.PREFERENCE_USE_FINGERPRINT, false);
     }
     }
 
 
     @Override
     @Override
@@ -440,4 +457,9 @@ public final class PreferenceManager implements AppPreferences {
                 .remove("prefs_instant_behaviour")
                 .remove("prefs_instant_behaviour")
                 .apply();
                 .apply();
     }
     }
+
+    @Override
+    public void clear() {
+        preferences.edit().clear().apply();
+    }
 }
 }

+ 5 - 3
src/main/java/com/owncloud/android/MainApp.java

@@ -115,6 +115,7 @@ public class MainApp extends MultiDexApplication {
 
 
     private SharedPreferences sharedPreferences;
     private SharedPreferences sharedPreferences;
     private AppPreferences preferences;
     private AppPreferences preferences;
+    private PassCodeManager passCodeManager;
 
 
     @SuppressWarnings("unused")
     @SuppressWarnings("unused")
     private boolean mBound;
     private boolean mBound;
@@ -132,6 +133,7 @@ public class MainApp extends MultiDexApplication {
         sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         preferences = PreferenceManager.fromContext(this);
         preferences = PreferenceManager.fromContext(this);
         fixStoragePath();
         fixStoragePath();
+        passCodeManager = new PassCodeManager(preferences);
 
 
         MainApp.storagePath = sharedPreferences.getString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
         MainApp.storagePath = sharedPreferences.getString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
                                                  getApplicationContext().getFilesDir().getAbsolutePath());
                                                  getApplicationContext().getFilesDir().getAbsolutePath());
@@ -190,13 +192,13 @@ public class MainApp extends MultiDexApplication {
             public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
             public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                 Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting");
                 Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting");
                 WhatsNewActivity.runIfNeeded(activity);
                 WhatsNewActivity.runIfNeeded(activity);
-                PassCodeManager.getPassCodeManager().onActivityCreated(activity);
+                passCodeManager.onActivityCreated(activity);
             }
             }
 
 
             @Override
             @Override
             public void onActivityStarted(Activity activity) {
             public void onActivityStarted(Activity activity) {
                 Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting");
                 Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting");
-                PassCodeManager.getPassCodeManager().onActivityStarted(activity);
+                passCodeManager.onActivityStarted(activity);
             }
             }
 
 
             @Override
             @Override
@@ -212,7 +214,7 @@ public class MainApp extends MultiDexApplication {
             @Override
             @Override
             public void onActivityStopped(Activity activity) {
             public void onActivityStopped(Activity activity) {
                 Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending");
                 Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending");
-                PassCodeManager.getPassCodeManager().onActivityStopped(activity);
+                passCodeManager.onActivityStopped(activity);
             }
             }
 
 
             @Override
             @Override

+ 16 - 17
src/main/java/com/owncloud/android/authentication/PassCodeManager.java

@@ -27,6 +27,7 @@ import android.os.PowerManager;
 import android.view.Window;
 import android.view.Window;
 import android.view.WindowManager;
 import android.view.WindowManager;
 
 
+import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.PreferenceManager;
 import com.nextcloud.client.preferences.PreferenceManager;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.ui.activity.PassCodeActivity;
 import com.owncloud.android.ui.activity.PassCodeActivity;
@@ -50,26 +51,24 @@ public final class PassCodeManager {
         // other activities may be exempted, if needed
         // other activities may be exempted, if needed
     }
     }
 
 
+    /**
+     *  Keeping a "low" positive value is the easiest way to prevent
+     *  the pass code being requested on screen rotations.
+     */
     private static final int PASS_CODE_TIMEOUT = 5000;
     private static final int PASS_CODE_TIMEOUT = 5000;
-        // keeping a "low" positive value is the easiest way to prevent the pass code is requested on rotations
-
-    private static PassCodeManager passCodeManagerInstance;
 
 
+    private AppPreferences preferences;
     private int visibleActivitiesCounter;
     private int visibleActivitiesCounter;
 
 
-    public static PassCodeManager getPassCodeManager() {
-        if (passCodeManagerInstance == null) {
-            passCodeManagerInstance = new PassCodeManager();
-        }
-        return passCodeManagerInstance;
-    }
 
 
-    private PassCodeManager() {}
+    public PassCodeManager(AppPreferences preferences) {
+        this.preferences = preferences;
+    }
 
 
     public void onActivityCreated(Activity activity) {
     public void onActivityCreated(Activity activity) {
         Window window = activity.getWindow();
         Window window = activity.getWindow();
         if (window != null) {
         if (window != null) {
-            if (passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) {
+            if (isPassCodeEnabled() || deviceCredentialsAreEnabled(activity)) {
                 window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
                 window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
             } else {
             } else {
                 window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
                 window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
@@ -103,7 +102,7 @@ public final class PassCodeManager {
         }
         }
         setUnlockTimestamp(activity);
         setUnlockTimestamp(activity);
         PowerManager powerMgr = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
         PowerManager powerMgr = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
-        if ((passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) && powerMgr != null
+        if ((isPassCodeEnabled() || deviceCredentialsAreEnabled(activity)) && powerMgr != null
                 && !powerMgr.isScreenOn()) {
                 && !powerMgr.isScreenOn()) {
             activity.moveTaskToBack(true);
             activity.moveTaskToBack(true);
         }
         }
@@ -115,11 +114,11 @@ public final class PassCodeManager {
 
 
     private boolean passCodeShouldBeRequested(Long timestamp) {
     private boolean passCodeShouldBeRequested(Long timestamp) {
         return (System.currentTimeMillis() - timestamp) > PASS_CODE_TIMEOUT &&
         return (System.currentTimeMillis() - timestamp) > PASS_CODE_TIMEOUT &&
-            visibleActivitiesCounter <= 0 && passCodeIsEnabled();
+            visibleActivitiesCounter <= 0 && isPassCodeEnabled();
     }
     }
 
 
-    private boolean passCodeIsEnabled() {
-        return SettingsActivity.LOCK_PASSCODE.equals(PreferenceManager.getLockPreference(MainApp.getAppContext()));
+    private boolean isPassCodeEnabled() {
+        return SettingsActivity.LOCK_PASSCODE.equals(preferences.getLockPreference());
     }
     }
 
 
     private boolean deviceCredentialsShouldBeRequested(Long timestamp, Activity activity) {
     private boolean deviceCredentialsShouldBeRequested(Long timestamp, Activity activity) {
@@ -128,9 +127,9 @@ public final class PassCodeManager {
     }
     }
 
 
     private boolean deviceCredentialsAreEnabled(Activity activity) {
     private boolean deviceCredentialsAreEnabled(Activity activity) {
-        return SettingsActivity.LOCK_DEVICE_CREDENTIALS.equals(PreferenceManager.getLockPreference(MainApp.getAppContext()))
+        return SettingsActivity.LOCK_DEVICE_CREDENTIALS.equals(preferences.getLockPreference())
                 || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                 || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
-                        (PreferenceManager.isUseFingerprint(MainApp.getAppContext())
+                        (preferences.isFingerprintUnlockEnabled()
                                 && DeviceCredentialUtils.areCredentialsAvailable(activity));
                                 && DeviceCredentialUtils.areCredentialsAvailable(activity));
     }
     }
 }
 }

+ 5 - 4
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -45,6 +45,7 @@ import android.widget.Toast;
 
 
 import com.evernote.android.job.JobRequest;
 import com.evernote.android.job.JobRequest;
 import com.evernote.android.job.util.Device;
 import com.evernote.android.job.util.Device;
+import com.nextcloud.client.preferences.AppPreferences;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AccountUtils;
@@ -93,10 +94,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
 
 
     @Override
     @Override
     public Cursor queryRoots(String[] projection) throws FileNotFoundException {
     public Cursor queryRoots(String[] projection) throws FileNotFoundException {
-
-        SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
-        if (SettingsActivity.LOCK_PASSCODE.equals(appPrefs.getString(SettingsActivity.PREFERENCE_LOCK, "")) ||
-            SettingsActivity.LOCK_DEVICE_CREDENTIALS.equals(appPrefs.getString(SettingsActivity.PREFERENCE_LOCK, ""))) {
+        Context context = MainApp.getAppContext();
+        AppPreferences preferences = com.nextcloud.client.preferences.PreferenceManager.fromContext(context);
+        if (SettingsActivity.LOCK_PASSCODE.equals(preferences.getLockPreference()) ||
+            SettingsActivity.LOCK_DEVICE_CREDENTIALS.equals(preferences.getLockPreference())) {
             return new FileCursor();
             return new FileCursor();
         }
         }
 
 

+ 21 - 27
src/main/java/com/owncloud/android/ui/activity/ManageSpaceActivity.java

@@ -20,16 +20,16 @@
 
 
 package com.owncloud.android.ui.activity;
 package com.owncloud.android.ui.activity;
 
 
-import android.content.SharedPreferences;
 import android.os.AsyncTask;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Bundle;
-import android.preference.PreferenceManager;
 import android.view.MenuItem;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View;
 import android.widget.Button;
 import android.widget.Button;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import com.google.android.material.snackbar.Snackbar;
 import com.google.android.material.snackbar.Snackbar;
+import com.nextcloud.client.preferences.AppPreferences;
+import com.nextcloud.client.preferences.PreferenceManager;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
 
 
@@ -43,6 +43,8 @@ public class ManageSpaceActivity extends AppCompatActivity {
     private static final String TAG = ManageSpaceActivity.class.getSimpleName();
     private static final String TAG = ManageSpaceActivity.class.getSimpleName();
     private static final String LIB_FOLDER = "lib";
     private static final String LIB_FOLDER = "lib";
 
 
+    private AppPreferences preferences;
+
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
@@ -59,10 +61,12 @@ public class ManageSpaceActivity extends AppCompatActivity {
         clearDataButton.setOnClickListener(new View.OnClickListener() {
         clearDataButton.setOnClickListener(new View.OnClickListener() {
             @Override
             @Override
             public void onClick(View v) {
             public void onClick(View v) {
-                ClearDataAsynTask clearDataTask = new ClearDataAsynTask();
+                ClearDataAsyncTask clearDataTask = new ClearDataAsyncTask();
                 clearDataTask.execute();
                 clearDataTask.execute();
             }
             }
         });
         });
+
+        preferences = PreferenceManager.fromContext(this);
     }
     }
 
 
     @Override
     @Override
@@ -83,46 +87,36 @@ public class ManageSpaceActivity extends AppCompatActivity {
     /**
     /**
      * AsyncTask for Clear Data, saving the passcode
      * AsyncTask for Clear Data, saving the passcode
      */
      */
-    private class ClearDataAsynTask extends AsyncTask<Void, Void, Boolean>{
+    private class ClearDataAsyncTask extends AsyncTask<Void, Void, Boolean>{
+
+        private final AppPreferences preferences = ManageSpaceActivity.this.preferences;
 
 
         @Override
         @Override
         protected Boolean doInBackground(Void... params) {
         protected Boolean doInBackground(Void... params) {
 
 
-            // Save passcode from Share preferences
-            SharedPreferences appPrefs = PreferenceManager
-                    .getDefaultSharedPreferences(getApplicationContext());
-
-            String lockPref = appPrefs.getString(SettingsActivity.PREFERENCE_LOCK, SettingsActivity.LOCK_NONE);
-            boolean passCodeEnable = SettingsActivity.LOCK_PASSCODE.equals(
-                appPrefs.getString(SettingsActivity.PREFERENCE_LOCK, ""));
+            String lockPref = preferences.getLockPreference();
+            boolean passCodeEnable = SettingsActivity.LOCK_PASSCODE.equals(lockPref);
 
 
             String passCodeDigits[] = new String[4];
             String passCodeDigits[] = new String[4];
             if (passCodeEnable) {
             if (passCodeEnable) {
-                passCodeDigits[0] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D1, null);
-                passCodeDigits[1] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D2, null);
-                passCodeDigits[2] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D3, null);
-                passCodeDigits[3] = appPrefs.getString(PassCodeActivity.PREFERENCE_PASSCODE_D4, null);
+                passCodeDigits = preferences.getPassCode();
             }
             }
 
 
             // Clear data
             // Clear data
+            preferences.clear();
             boolean result = clearApplicationData();
             boolean result = clearApplicationData();
 
 
-            // Clear SharedPreferences
-            SharedPreferences.Editor appPrefsEditor = PreferenceManager
-                    .getDefaultSharedPreferences(getApplicationContext()).edit();
-            appPrefsEditor.clear();
-            result = result && appPrefsEditor.commit();
-
             // Recover passcode
             // Recover passcode
             if (passCodeEnable) {
             if (passCodeEnable) {
-                appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D1, passCodeDigits[0]);
-                appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D2, passCodeDigits[1]);
-                appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D3, passCodeDigits[2]);
-                appPrefsEditor.putString(PassCodeActivity.PREFERENCE_PASSCODE_D4, passCodeDigits[3]);
+                preferences.setPassCode(
+                    passCodeDigits[0],
+                    passCodeDigits[1],
+                    passCodeDigits[2],
+                    passCodeDigits[3]
+                );
             }
             }
 
 
-            appPrefsEditor.putString(SettingsActivity.PREFERENCE_LOCK, lockPref);
-            result = result && appPrefsEditor.commit();
+            preferences.setLockPreference(lockPref);
 
 
             return result;
             return result;
         }
         }

+ 8 - 10
src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java

@@ -39,6 +39,7 @@ import android.widget.EditText;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
 import com.google.android.material.snackbar.Snackbar;
 import com.google.android.material.snackbar.Snackbar;
+import com.nextcloud.client.preferences.AppPreferences;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.ThemeUtils;
 import com.owncloud.android.utils.ThemeUtils;
@@ -47,7 +48,7 @@ import java.util.Arrays;
 
 
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.app.AppCompatActivity;
 
 
-public class    PassCodeActivity extends AppCompatActivity {
+public class PassCodeActivity extends AppCompatActivity {
 
 
     private static final String TAG = PassCodeActivity.class.getSimpleName();
     private static final String TAG = PassCodeActivity.class.getSimpleName();
 
 
@@ -64,6 +65,7 @@ public class    PassCodeActivity extends AppCompatActivity {
     public final static String PREFERENCE_PASSCODE_D3 = "PrefPinCode3";
     public final static String PREFERENCE_PASSCODE_D3 = "PrefPinCode3";
     public final static String PREFERENCE_PASSCODE_D4 = "PrefPinCode4";
     public final static String PREFERENCE_PASSCODE_D4 = "PrefPinCode4";
 
 
+    private AppPreferences preferences;
     private Button mBCancel;
     private Button mBCancel;
     private TextView mPassCodeHdr;
     private TextView mPassCodeHdr;
     private TextView mPassCodeHdrExplanation;
     private TextView mPassCodeHdrExplanation;
@@ -88,6 +90,7 @@ public class    PassCodeActivity extends AppCompatActivity {
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
         setContentView(R.layout.passcodelock);
         setContentView(R.layout.passcodelock);
+        preferences = com.nextcloud.client.preferences.PreferenceManager.fromContext(this);
 
 
         int elementColor = ThemeUtils.elementColor(this);
         int elementColor = ThemeUtils.elementColor(this);
 
 
@@ -308,15 +311,10 @@ public class    PassCodeActivity extends AppCompatActivity {
      *
      *
      * @return     'True' if entered pass code equals to the saved one.
      * @return     'True' if entered pass code equals to the saved one.
      */
      */
-    protected boolean checkPassCode(){
-        SharedPreferences appPrefs = PreferenceManager
-            .getDefaultSharedPreferences(getApplicationContext());
-
-        String savedPassCodeDigits[] = new String[4];
-        savedPassCodeDigits[0] = appPrefs.getString(PREFERENCE_PASSCODE_D1, null);
-        savedPassCodeDigits[1] = appPrefs.getString(PREFERENCE_PASSCODE_D2, null);
-        savedPassCodeDigits[2] = appPrefs.getString(PREFERENCE_PASSCODE_D3, null);
-        savedPassCodeDigits[3] = appPrefs.getString(PREFERENCE_PASSCODE_D4, null);
+    protected boolean checkPassCode() {
+
+
+        String savedPassCodeDigits[] = preferences.getPassCode();
 
 
         boolean result = true;
         boolean result = true;
         for (int i = 0; i < mPassCodeDigits.length && result; i++) {
         for (int i = 0; i < mPassCodeDigits.length && result; i++) {

+ 3 - 2
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -174,8 +174,9 @@ public final class DisplayUtils {
      * @return A human friendly version of the MIME type, {@link #MIME_TYPE_UNKNOWN} if it can't be converted
      * @return A human friendly version of the MIME type, {@link #MIME_TYPE_UNKNOWN} if it can't be converted
      */
      */
     public static String convertMIMEtoPrettyPrint(String mimetype) {
     public static String convertMIMEtoPrettyPrint(String mimetype) {
-        if (mimeType2HumanReadable.containsKey(mimetype)) {
-            return mimeType2HumanReadable.get(mimetype);
+        final String humanReadableMime = mimeType2HumanReadable.get(mimetype);
+        if (humanReadableMime != null) {
+            return humanReadableMime;
         }
         }
         if (mimetype.split("/").length >= MIMETYPE_PARTS_COUNT) {
         if (mimetype.split("/").length >= MIMETYPE_PARTS_COUNT) {
             return mimetype.split("/")[1].toUpperCase(Locale.getDefault()) + " file";
             return mimetype.split("/")[1].toUpperCase(Locale.getDefault()) + " file";