Fix NPE crash on startup when storage manager is not set

Fixes #4941

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2019-12-18 14:25:24 +00:00
parent 447f747927
commit 3f3c5a1951
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
2 changed files with 14 additions and 11 deletions

View file

@ -69,6 +69,13 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
return accountManager; return accountManager;
} }
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Account account = accountManager.getCurrentAccount();
setAccount(account, false);
}
@Override @Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) { protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
@ -97,12 +104,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
} }
} }
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
Account account = accountManager.getCurrentAccount();
setAccount(account, false);
}
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
@ -177,6 +178,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
if (newAccount == null) { if (newAccount == null) {
/// no account available: force account creation /// no account available: force account creation
createAccount(true); createAccount(true);
finish();
} else { } else {
currentAccount = newAccount; currentAccount = newAccount;
} }

View file

@ -2539,8 +2539,9 @@ public class FileDisplayActivity extends FileActivity
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
Optional<User> optionalUser = getUser(); final Optional<User> optionalUser = getUser();
if (optionalUser.isPresent()) { final FileDataStorageManager storageManager = getStorageManager();
if (optionalUser.isPresent() && storageManager != null) {
/// Check whether the 'main' OCFile handled by the Activity is contained in the /// Check whether the 'main' OCFile handled by the Activity is contained in the
// current Account // current Account
OCFile file = getFile(); OCFile file = getFile();
@ -2552,17 +2553,17 @@ public class FileDisplayActivity extends FileActivity
// cache until the upload is successful get parent from path // cache until the upload is successful get parent from path
parentPath = file.getRemotePath().substring(0, parentPath = file.getRemotePath().substring(0,
file.getRemotePath().lastIndexOf(file.getFileName())); file.getRemotePath().lastIndexOf(file.getFileName()));
if (getStorageManager().getFileByPath(parentPath) == null) { if (storageManager.getFileByPath(parentPath) == null) {
file = null; // not able to know the directory where the file is uploading file = null; // not able to know the directory where the file is uploading
} }
} else { } else {
file = getStorageManager().getFileByPath(file.getRemotePath()); file = storageManager.getFileByPath(file.getRemotePath());
// currentDir = null if not in the current Account // currentDir = null if not in the current Account
} }
} }
if (file == null) { if (file == null) {
// fall back to root folder // fall back to root folder
file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null file = storageManager.getFileByPath(OCFile.ROOT_PATH); // never returns null
} }
setFile(file); setFile(file);