\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
+import android.accounts.AccountsException;\r
import android.content.Context;\r
import android.content.SharedPreferences;\r
import android.preference.PreferenceManager;\r
* @param context\r
* @param account\r
* @return url or null on failure\r
+ * @throws AccountNotFoundException When 'account' is unknown for the AccountManager\r
*/\r
- public static String constructFullURLForAccount(Context context, Account account) {\r
- try {\r
- AccountManager ama = AccountManager.get(context);\r
- String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);\r
- String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION);\r
- boolean supportsOAuth = (ama.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null);\r
- OwnCloudVersion ver = new OwnCloudVersion(strver);\r
- String webdavpath = getWebdavPath(ver, supportsOAuth);\r
+ public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException {\r
+ AccountManager ama = AccountManager.get(context);\r
+ String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);\r
+ String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION);\r
+ boolean supportsOAuth = (ama.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null);\r
+ OwnCloudVersion ver = new OwnCloudVersion(strver);\r
+ String webdavpath = getWebdavPath(ver, supportsOAuth);\r
\r
- if (webdavpath == null) return null;\r
- return baseurl + webdavpath;\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return null;\r
+ if (baseurl == null || webdavpath == null) \r
+ throw new AccountNotFoundException(account, "Account not found", null);\r
+ \r
+ return baseurl + webdavpath;\r
+ }\r
+ \r
+ \r
+ public static class AccountNotFoundException extends AccountsException {\r
+ \r
+ private static final long serialVersionUID = 4276870654168776992L;\r
+ \r
+ private Account mFailedAccount; \r
+ \r
+ public AccountNotFoundException(Account failedAccount, String message, Throwable cause) {\r
+ super(message, cause);\r
+ mFailedAccount = failedAccount;\r
+ }\r
+ \r
+ public Account getFailedAccount() {\r
+ return mFailedAccount;\r
}\r
}\r
\r
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;
* @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));
}
- 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);
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;
/**
/** Generated - should be refreshed every time the class changes!! */
private static final long serialVersionUID = -7805531062432602444L;
+
private static final String TAG = "RemoteOperationResult";
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;
} 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) {
} 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";
}
import org.apache.http.protocol.HttpContext;\r
\r
import com.owncloud.android.authentication.AccountUtils;\r
+import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException;\r
import com.owncloud.android.datamodel.DataStorageManager;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
\r
return null;\r
}\r
\r
- protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException {\r
- if (AccountUtils.constructFullURLForAccount(getContext(), account) == null) {\r
- throw new UnknownHostException();\r
- }\r
+ protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {\r
+ AccountUtils.constructFullURLForAccount(getContext(), account);\r
mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext());\r
}\r
\r
+++ /dev/null
-/* 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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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");
- }
- }
-
-}
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;
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);