1 /* ownCloud Jelly Bean Workaround for lost credentials
2 * Copyright (C) 2013 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.workaround
.accounts
;
21 import android
.accounts
.AbstractAccountAuthenticator
;
22 import android
.accounts
.Account
;
23 import android
.accounts
.AccountAuthenticatorResponse
;
24 import android
.accounts
.AccountManager
;
25 import android
.accounts
.NetworkErrorException
;
26 import android
.app
.Service
;
27 import android
.content
.Context
;
28 import android
.content
.Intent
;
29 import android
.os
.Bundle
;
30 import android
.os
.IBinder
;
31 //import android.util.Log;
33 public class AccountAuthenticatorService
extends Service
{
35 private AccountAuthenticator mAuthenticator
;
36 static final public String ACCOUNT_TYPE
= "owncloud";
39 public void onCreate() {
41 mAuthenticator
= new AccountAuthenticator(this);
45 public IBinder
onBind(Intent intent
) {
46 return mAuthenticator
.getIBinder();
50 public static class AccountAuthenticator
extends AbstractAccountAuthenticator
{
52 public static final String KEY_AUTH_TOKEN_TYPE
= "authTokenType";
53 public static final String KEY_REQUIRED_FEATURES
= "requiredFeatures";
54 public static final String KEY_LOGIN_OPTIONS
= "loginOptions";
56 public AccountAuthenticator(Context context
) {
61 public Bundle
addAccount(AccountAuthenticatorResponse response
,
62 String accountType
, String authTokenType
,
63 String
[] requiredFeatures
, Bundle options
)
64 throws NetworkErrorException
{
65 //Log.e("WORKAROUND", "Yes, WORKAROUND takes the control here");
66 final Intent intent
= new Intent("com.owncloud.android.workaround.accounts.CREATE");
67 intent
.putExtra(AccountManager
.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE
,
69 intent
.putExtra(KEY_AUTH_TOKEN_TYPE
, authTokenType
);
70 intent
.putExtra(KEY_REQUIRED_FEATURES
, requiredFeatures
);
71 intent
.putExtra(KEY_LOGIN_OPTIONS
, options
);
73 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
74 intent
.addFlags(Intent
.FLAG_ACTIVITY_MULTIPLE_TASK
);
75 intent
.addFlags(Intent
.FLAG_ACTIVITY_NO_HISTORY
);
76 intent
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
77 intent
.addFlags(Intent
.FLAG_FROM_BACKGROUND
);
79 final Bundle bundle
= new Bundle();
80 bundle
.putParcelable(AccountManager
.KEY_INTENT
, intent
);
82 //return getCommonResultBundle();
87 public Bundle
confirmCredentials(AccountAuthenticatorResponse response
,
88 Account account
, Bundle options
) throws NetworkErrorException
{
89 return getCommonResultBundle();
93 public Bundle
editProperties(AccountAuthenticatorResponse response
,
95 return getCommonResultBundle();
99 public Bundle
getAuthToken(AccountAuthenticatorResponse response
,
100 Account account
, String authTokenType
, Bundle options
)
101 throws NetworkErrorException
{
102 return getCommonResultBundle();
106 public String
getAuthTokenLabel(String authTokenType
) {
111 public Bundle
hasFeatures(AccountAuthenticatorResponse response
,
112 Account account
, String
[] features
) throws NetworkErrorException
{
113 return getCommonResultBundle();
117 public Bundle
updateCredentials(AccountAuthenticatorResponse response
,
118 Account account
, String authTokenType
, Bundle options
)
119 throws NetworkErrorException
{
120 return getCommonResultBundle();
124 public Bundle
getAccountRemovalAllowed(
125 AccountAuthenticatorResponse response
, Account account
)
126 throws NetworkErrorException
{
127 return super.getAccountRemovalAllowed(response
, account
);
130 private Bundle
getCommonResultBundle() {
131 Bundle resultBundle
= new Bundle();
132 resultBundle
.putInt(AccountManager
.KEY_ERROR_CODE
, AccountManager
.ERROR_CODE_UNSUPPORTED_OPERATION
);
133 resultBundle
.putString(AccountManager
.KEY_ERROR_MESSAGE
, "This is just a workaround, not a real account authenticator");