@ -19,7 +19,6 @@ import com.beemdevelopment.aegis.services.NotificationService;
import com.beemdevelopment.aegis.ui.dialogs.Dialogs ;
import java.io.File ;
import java.io.FileNotFoundException ;
import java.io.FileOutputStream ;
import java.io.IOException ;
import java.io.OutputStream ;
@ -30,8 +29,6 @@ public class VaultManager {
private final Context _context ;
private final Preferences _prefs ;
private VaultFile _vaultFile ;
private VaultRepositoryException _vaultFileError ;
private VaultRepository _repo ;
private final VaultBackupManager _backups ;
@ -46,35 +43,11 @@ public class VaultManager {
_backups = new VaultBackupManager ( _context ) ;
_androidBackups = new BackupManager ( context ) ;
_lockListeners = new ArrayList < > ( ) ;
loadVaultFile ( ) ;
}
private void loadVaultFile ( ) {
try {
_vaultFile = VaultRepository . readVaultFile ( _context ) ;
} catch ( VaultRepositoryException e ) {
if ( ! ( e . getCause ( ) instanceof FileNotFoundException ) ) {
_vaultFileError = e ;
e . printStackTrace ( ) ;
}
}
if ( _vaultFile ! = null & & ! _vaultFile . isEncrypted ( ) ) {
try {
loadFrom ( _vaultFile , null ) ;
} catch ( VaultRepositoryException e ) {
e . printStackTrace ( ) ;
_vaultFile = null ;
_vaultFileError = e ;
}
}
}
/ * *
* Initializes the vault repository with a new empty vault and the given creds . It can
* only be called if isVaultLoaded ( ) returns false .
*
* Calling this method removes the manager ' s internal reference to the raw vault file ( if it had one ) .
* /
@NonNull
public VaultRepository initNew ( @Nullable VaultFileCredentials creds ) throws VaultRepositoryException {
@ -82,8 +55,6 @@ public class VaultManager {
throw new IllegalStateException ( "Vault manager is already initialized" ) ;
}
_vaultFile = null ;
_vaultFileError = null ;
_repo = new VaultRepository ( _context , new Vault ( ) , creds ) ;
save ( ) ;
@ -97,8 +68,6 @@ public class VaultManager {
/ * *
* Initializes the vault repository by decrypting the given vaultFile with the given
* creds . It can only be called if isVaultLoaded ( ) returns false .
*
* Calling this method removes the manager ' s internal reference to the raw vault file ( if it had one ) .
* /
@NonNull
public VaultRepository loadFrom ( @NonNull VaultFile vaultFile , @Nullable VaultFileCredentials creds ) throws VaultRepositoryException {
@ -106,8 +75,6 @@ public class VaultManager {
throw new IllegalStateException ( "Vault manager is already initialized" ) ;
}
_vaultFile = null ;
_vaultFileError = null ;
_repo = VaultRepository . fromFile ( _context , vaultFile , creds ) ;
if ( getVault ( ) . isEncryptionEnabled ( ) ) {
@ -117,32 +84,9 @@ public class VaultManager {
return getVault ( ) ;
}
/ * *
* Initializes the vault repository by loading and decrypting the vault file stored in
* internal storage , with the given creds . It can only be called if isVaultLoaded ( )
* returns false .
*
* Calling this method removes the manager ' s internal reference to the raw vault file ( if it had one ) .
* /
@NonNull
public VaultRepository load ( @Nullable VaultFileCredentials creds ) throws VaultRepositoryException {
if ( isVaultLoaded ( ) ) {
throw new IllegalStateException ( "Vault manager is already initialized" ) ;
}
loadVaultFile ( ) ;
if ( isVaultLoaded ( ) ) {
return _repo ;
}
return loadFrom ( getVaultFile ( ) , creds ) ;
}
@NonNull
public VaultRepository unlock ( @NonNull VaultFileCredentials creds ) throws VaultRepositoryException {
VaultRepository repo = loadFrom ( getVaultFile ( ) , creds ) ;
startNotificationService ( ) ;
return repo ;
public VaultRepository loadFrom ( @NonNull VaultFile vaultFile ) throws VaultRepositoryException {
return loadFrom ( vaultFile , null ) ;
}
/ * *
@ -157,7 +101,6 @@ public class VaultManager {
}
stopNotificationService ( ) ;
loadVaultFile ( ) ;
}
public void enableEncryption ( VaultFileCredentials creds ) throws VaultRepositoryException {
@ -270,12 +213,8 @@ public class VaultManager {
return _repo ! = null ;
}
public boolean isVaultFileLoaded ( ) {
return _vaultFile ! = null ;
}
public boolean isVaultInitNeeded ( ) {
return ! isVaultLoaded ( ) & & ! isVaultFileLoaded( ) & & getVaultFileError ( ) = = null ;
return ! isVaultLoaded ( ) & & ! VaultRepository . fileExists ( _context ) ;
}
@NonNull
@ -287,20 +226,6 @@ public class VaultManager {
return _repo ;
}
@NonNull
public VaultFile getVaultFile ( ) {
if ( _vaultFile = = null ) {
throw new IllegalStateException ( "Vault file is not in memory" ) ;
}
return _vaultFile ;
}
@Nullable
public VaultRepositoryException getVaultFileError ( ) {
return _vaultFileError ;
}
/ * *
* Starts an external activity , temporarily blocks automatic lock of Aegis and
* shows an error dialog if the target activity is not found .