Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash fixes #4

Merged
merged 6 commits into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ private void tearDownAppWebCookie() {

Preferences.ofCookie(this).setAppCookies(appHost, appCookies);

CookieManager.getInstance().removeAllCookie();
if (CookieManager.getInstance().hasCookies()) {
CookieManager.getInstance().removeAllCookie();
}
}

private static final class AppWebClient extends WebViewClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ private AccountManager getAccountManager() {

@Override
public void onAccountsUpdated(Account[] accounts) {
if (isVisible()) {
return;
}

if (getAccounts().isEmpty()) {
setUpAccount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ public boolean onPreferenceClick(Preference preference) {
}

private void tearDownAccount() {
Account account = getAccounts().get(0);
if (!getAccounts().isEmpty()) {
Account account = getAccounts().get(0);

getAccountManager().removeAccount(account, this, null);
getAccountManager().removeAccount(account, this, null);
} else {
tearDownActivity();
}
}

private List<Account> getAccounts() {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/amahi/anywhere/receiver/AudioReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ public class AudioReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
if (intent == null) {
return;
}

String action = intent.getAction();

if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
handleAudioChangeEvent();
}

if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
if (Intent.ACTION_MEDIA_BUTTON.equals(action)) {
handleAudioControlEvent(intent);
}
}
Expand All @@ -56,6 +62,10 @@ private void handleAudioChangeEvent() {
private void handleAudioControlEvent(Intent intent) {
KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

if (event == null) {
return;
}

if (event.getAction() != KeyEvent.ACTION_DOWN) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ public Uri getFileUri(ServerShare share, ServerFile file) {
}

public ServerFileMetadata getFileMetadata(ServerShare share, ServerFile file) {
if (share == null || file == null){
if ((server == null) || (share == null) || (file == null)){
return null;
}

try {
return serverApi.getFileMetadata(server.getSession(), file.getName(), share.getTag());
} catch (RetrofitError error) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/amahi/anywhere/util/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Downloader extends BroadcastReceiver

@Inject
public Downloader(Context context) {
this.context = context;
this.context = context.getApplicationContext();

this.downloadId = Integer.MIN_VALUE;
}
Expand Down Expand Up @@ -116,7 +116,11 @@ private void finishDownloading() {
}

private void tearDownDownloadReceiver() {
context.unregisterReceiver(this);
try {
context.unregisterReceiver(this);
} catch (IllegalArgumentException e) {
// False alarm, no need to unregister.
}
}

public void finishFileDownloading() {
Expand Down