From: David A. Velasco Date: Tue, 18 Jun 2013 12:04:51 +0000 (+0200) Subject: Fixed crash, error notified instead X-Git-Tag: oc-android-1.4.3~14^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6ca1e170f7518e69dbebb4393e7899729c042ac6?hp=--cc Fixed crash, error notified instead --- 6ca1e170f7518e69dbebb4393e7899729c042ac6 diff --git a/src/com/owncloud/android/authentication/AccountUtils.java b/src/com/owncloud/android/authentication/AccountUtils.java index 10f77719..cfa00e32 100644 --- a/src/com/owncloud/android/authentication/AccountUtils.java +++ b/src/com/owncloud/android/authentication/AccountUtils.java @@ -22,6 +22,7 @@ import com.owncloud.android.utils.OwnCloudVersion; import android.accounts.Account; import android.accounts.AccountManager; +import android.accounts.AccountsException; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -135,21 +136,36 @@ public class AccountUtils { * @param context * @param account * @return url or null on failure + * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ - public static String constructFullURLForAccount(Context context, Account account) { - try { - AccountManager ama = AccountManager.get(context); - String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL); - String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION); - boolean supportsOAuth = (ama.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null); - OwnCloudVersion ver = new OwnCloudVersion(strver); - String webdavpath = getWebdavPath(ver, supportsOAuth); + public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { + AccountManager ama = AccountManager.get(context); + String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL); + String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION); + boolean supportsOAuth = (ama.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null); + OwnCloudVersion ver = new OwnCloudVersion(strver); + String webdavpath = getWebdavPath(ver, supportsOAuth); - if (webdavpath == null) return null; - return baseurl + webdavpath; - } catch (Exception e) { - e.printStackTrace(); - return null; + if (baseurl == null || webdavpath == null) + throw new AccountNotFoundException(account, "Account not found", null); + + return baseurl + webdavpath; + } + + + public static class AccountNotFoundException extends AccountsException { + + private static final long serialVersionUID = 4276870654168776992L; + + private Account mFailedAccount; + + public AccountNotFoundException(Account failedAccount, String message, Throwable cause) { + super(message, cause); + mFailedAccount = failedAccount; + } + + public Account getFailedAccount() { + return mFailedAccount; } } diff --git a/src/com/owncloud/android/network/OwnCloudClientUtils.java b/src/com/owncloud/android/network/OwnCloudClientUtils.java index 80be2e1d..04fb7ac6 100644 --- a/src/com/owncloud/android/network/OwnCloudClientUtils.java +++ b/src/com/owncloud/android/network/OwnCloudClientUtils.java @@ -38,6 +38,7 @@ import org.apache.http.conn.ssl.X509HostnameVerifier; import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; import com.owncloud.android.Log_OC; import eu.alefzero.webdav.WebdavClient; @@ -83,8 +84,9 @@ public class OwnCloudClientUtils { * @throws AuthenticatorException If the authenticator failed to get the authorization token for the account. * @throws OperationCanceledException If the authenticator operation was cancelled while getting the authorization token for the account. * @throws IOException If there was some I/O error while getting the authorization token for the account. + * @throws AccountNotFoundException If 'account' is unknown for the AccountManager */ - public static WebdavClient createOwnCloudClient (Account account, Context appContext) throws OperationCanceledException, AuthenticatorException, IOException { + public static WebdavClient createOwnCloudClient (Account account, Context appContext) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { //Log_OC.d(TAG, "Creating WebdavClient associated to " + account.name); Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account)); @@ -105,7 +107,7 @@ public class OwnCloudClientUtils { } - public static WebdavClient createOwnCloudClient (Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException { + public static WebdavClient createOwnCloudClient (Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account)); WebdavClient client = createOwnCloudClient(uri, appContext); AccountManager am = AccountManager.get(appContext); diff --git a/src/com/owncloud/android/operations/RemoteOperationResult.java b/src/com/owncloud/android/operations/RemoteOperationResult.java index 16b47798..6f4f2910 100644 --- a/src/com/owncloud/android/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/operations/RemoteOperationResult.java @@ -32,7 +32,11 @@ import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.DavException; +import android.accounts.Account; +import android.accounts.AccountsException; + import com.owncloud.android.Log_OC; +import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; import com.owncloud.android.network.CertificateCombinedException; /** @@ -47,6 +51,7 @@ public class RemoteOperationResult implements Serializable { /** Generated - should be refreshed every time the class changes!! */ private static final long serialVersionUID = -7805531062432602444L; + private static final String TAG = "RemoteOperationResult"; @@ -77,7 +82,9 @@ public class RemoteOperationResult implements Serializable { LOCAL_STORAGE_NOT_MOVED, LOCAL_STORAGE_NOT_COPIED, OAUTH2_ERROR_ACCESS_DENIED, - QUOTA_EXCEEDED + QUOTA_EXCEEDED, + ACCOUNT_NOT_FOUND, + ACCOUNT_EXCEPTION } private boolean mSuccess = false; @@ -142,6 +149,12 @@ public class RemoteOperationResult implements Serializable { } else if (e instanceof UnknownHostException) { mCode = ResultCode.HOST_NOT_AVAILABLE; + } else if (e instanceof AccountNotFoundException) { + mCode = ResultCode.ACCOUNT_NOT_FOUND; + + } else if (e instanceof AccountsException) { + mCode = ResultCode.ACCOUNT_EXCEPTION; + } else if (e instanceof SSLException || e instanceof RuntimeException) { CertificateCombinedException se = getCertificateCombinedException(e); if (se != null) { @@ -242,6 +255,13 @@ public class RemoteOperationResult implements Serializable { } else if (mException instanceof IOException) { return "Unrecovered transport exception"; + } else if (mException instanceof AccountNotFoundException) { + Account failedAccount = ((AccountNotFoundException)mException).getFailedAccount(); + return mException.getMessage() + " (" + (failedAccount != null ? failedAccount.name : "NULL") + ")"; + + } else if (mException instanceof AccountsException) { + return "Exception while using account"; + } else { return "Unexpected exception"; } diff --git a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java index 267eaba7..e9f7a9b6 100644 --- a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -29,6 +29,7 @@ import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.protocol.HttpContext; import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.network.OwnCloudClientUtils; @@ -142,10 +143,8 @@ public abstract class AbstractOwnCloudSyncAdapter extends return null; } - protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException { - if (AccountUtils.constructFullURLForAccount(getContext(), account) == null) { - throw new UnknownHostException(); - } + protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { + AccountUtils.constructFullURLForAccount(getContext(), account); mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext()); } diff --git a/src/com/owncloud/android/ui/adapter/FileListActionListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListActionListAdapter.java deleted file mode 100644 index 54202e46..00000000 --- a/src/com/owncloud/android/ui/adapter/FileListActionListAdapter.java +++ /dev/null @@ -1,159 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.owncloud.android.ui.adapter; - -import java.io.File; - -import com.owncloud.android.authentication.AccountUtils; -import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; - -import com.owncloud.android.R; -import eu.alefzero.webdav.WebdavUtils; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.database.DataSetObserver; -import android.net.Uri; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.ListAdapter; -import android.widget.TextView; - -public class FileListActionListAdapter implements ListAdapter { - - private Context mContext; - private Account mAccount; - private String mFilename, mFileType, mFilePath, mFileStoragePath; - - private final int ITEM_DOWNLOAD = 0; - - // private final int ITEM_SHARE = 1; - - public FileListActionListAdapter(Cursor c, Context co, Account account) { - mContext = co; - mFilename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME)); - mFileType = c.getString(c - .getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)); - mFilePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)); - mFileStoragePath = c.getString(c - .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)); - // mItemId = c.getString(c.getColumnIndex(ProviderTableMeta._ID)); - mAccount = account; - } - - public boolean areAllItemsEnabled() { - return true; - } - - public boolean isEnabled(int position) { - return true; - } - - public int getCount() { - return 1; - } - - public Object getItem(int position) { - if (position == 0) { - Intent intent = new Intent(Intent.ACTION_VIEW); - if (TextUtils.isEmpty(mFileStoragePath)) { - intent.putExtra("toDownload", true); - AccountManager accm = (AccountManager) mContext - .getSystemService(Context.ACCOUNT_SERVICE); - String ocurl = accm.getUserData(mAccount, - AccountUtils.constructFullURLForAccount(mContext, mAccount)); - ocurl += WebdavUtils.encodePath(mFilePath + mFilename); - intent.setData(Uri.parse(ocurl)); - } else { - intent.putExtra("toDownload", false); - intent.setDataAndType(Uri.fromFile(new File(mFileStoragePath)), - mFileType); - } - return intent; - } - return null; - } - - public long getItemId(int position) { - return 0; - } - - public int getItemViewType(int position) { - return 0; - } - - public View getView(int position, View convertView, ViewGroup parent) { - View v = convertView; - if (v == null) { - LayoutInflater vi = (LayoutInflater) mContext - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - v = vi.inflate(R.layout.file_display_action_list_element, null); - } - - TextView tv; - ImageView iv; - switch (position) { - case ITEM_DOWNLOAD: - tv = (TextView) v.findViewById(R.id.textView1); - if (mFileStoragePath == null) { - tv.setText("Download"); - } else { - setActionName(tv); - } - iv = (ImageView) v.findViewById(R.id.imageView1); - iv.setImageResource(R.drawable.download); - break; - } - - return v; - } - - public int getViewTypeCount() { - return 2; - } - - public boolean hasStableIds() { - return false; - } - - public boolean isEmpty() { - return false; - } - - public void registerDataSetObserver(DataSetObserver observer) { } - - public void unregisterDataSetObserver(DataSetObserver observer) { } - - private void setActionName(TextView tv) { - if (mFileType.matches("image/.*")) { - tv.setText("View"); - } else if (mFileType.matches("audio/.*") - || mFileType.matches("video/.*")) { - tv.setText("Play"); - } else { - tv.setText("Open"); - } - } - -} diff --git a/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java index 0d25bf30..c4b6dce7 100644 --- a/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java @@ -35,6 +35,7 @@ import android.widget.VideoView; import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.media.MediaService; @@ -117,9 +118,14 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen mVideoPlayer.setVideoPath(mFile.getStoragePath()); } else if (mAccount != null) { - // not working now - String url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath(); - mVideoPlayer.setVideoURI(Uri.parse(url)); + // not working yet + String url; + try { + url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath(); + mVideoPlayer.setVideoURI(Uri.parse(url)); + } catch (AccountNotFoundException e) { + onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account); + } } else { onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);