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 as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.workaround
.accounts
;
22 import android
.accounts
.AbstractAccountAuthenticator
;
23 import android
.accounts
.Account
;
24 import android
.accounts
.AccountAuthenticatorResponse
;
25 import android
.accounts
.AccountManager
;
26 import android
.accounts
.NetworkErrorException
;
27 import android
.app
.Service
;
28 import android
.content
.Context
;
29 import android
.content
.Intent
;
30 import android
.os
.Bundle
;
31 import android
.os
.IBinder
;
32 //import android.util.Log;
34 public class AccountAuthenticatorService
extends Service
{
36 private AccountAuthenticator mAuthenticator
;
37 static final public String ACCOUNT_TYPE
= "owncloud";
40 public void onCreate() {
42 mAuthenticator
= new AccountAuthenticator(this);
46 public IBinder
onBind(Intent intent
) {
47 return mAuthenticator
.getIBinder();
51 public static class AccountAuthenticator
extends AbstractAccountAuthenticator
{
53 public static final String KEY_AUTH_TOKEN_TYPE
= "authTokenType";
54 public static final String KEY_REQUIRED_FEATURES
= "requiredFeatures";
55 public static final String KEY_LOGIN_OPTIONS
= "loginOptions";
57 public AccountAuthenticator(Context context
) {
62 public Bundle
addAccount(AccountAuthenticatorResponse response
,
63 String accountType
, String authTokenType
,
64 String
[] requiredFeatures
, Bundle options
)
65 throws NetworkErrorException
{
66 //Log.e("WORKAROUND", "Yes, WORKAROUND takes the control here");
67 final Intent intent
= new Intent("com.owncloud.android.workaround.accounts.CREATE");
68 intent
.putExtra(AccountManager
.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE
,
70 intent
.putExtra(KEY_AUTH_TOKEN_TYPE
, authTokenType
);
71 intent
.putExtra(KEY_REQUIRED_FEATURES
, requiredFeatures
);
72 intent
.putExtra(KEY_LOGIN_OPTIONS
, options
);
74 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
75 intent
.addFlags(Intent
.FLAG_ACTIVITY_MULTIPLE_TASK
);
76 intent
.addFlags(Intent
.FLAG_ACTIVITY_NO_HISTORY
);
77 intent
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
78 intent
.addFlags(Intent
.FLAG_FROM_BACKGROUND
);
80 final Bundle bundle
= new Bundle();
81 bundle
.putParcelable(AccountManager
.KEY_INTENT
, intent
);
83 //return getCommonResultBundle();
88 public Bundle
confirmCredentials(AccountAuthenticatorResponse response
,
89 Account account
, Bundle options
) throws NetworkErrorException
{
90 return getCommonResultBundle();
94 public Bundle
editProperties(AccountAuthenticatorResponse response
,
96 return getCommonResultBundle();
100 public Bundle
getAuthToken(AccountAuthenticatorResponse response
,
101 Account account
, String authTokenType
, Bundle options
)
102 throws NetworkErrorException
{
103 return getCommonResultBundle();
107 public String
getAuthTokenLabel(String authTokenType
) {
112 public Bundle
hasFeatures(AccountAuthenticatorResponse response
,
113 Account account
, String
[] features
) throws NetworkErrorException
{
114 return getCommonResultBundle();
118 public Bundle
updateCredentials(AccountAuthenticatorResponse response
,
119 Account account
, String authTokenType
, Bundle options
)
120 throws NetworkErrorException
{
121 return getCommonResultBundle();
125 public Bundle
getAccountRemovalAllowed(
126 AccountAuthenticatorResponse response
, Account account
)
127 throws NetworkErrorException
{
128 return super.getAccountRemovalAllowed(response
, account
);
131 private Bundle
getCommonResultBundle() {
132 Bundle resultBundle
= new Bundle();
133 resultBundle
.putInt(AccountManager
.KEY_ERROR_CODE
, AccountManager
.ERROR_CODE_UNSUPPORTED_OPERATION
);
134 resultBundle
.putString(AccountManager
.KEY_ERROR_MESSAGE
, "This is just a workaround, not a real account authenticator");