1 /* ownCloud Jelly Bean Workaround for lost credentials
3 * Copyright (C) 2013 ownCloud Inc.
6 package com
.owncloud
.android
.workaround
.accounts
;
8 import android
.accounts
.AbstractAccountAuthenticator
;
9 import android
.accounts
.Account
;
10 import android
.accounts
.AccountAuthenticatorResponse
;
11 import android
.accounts
.AccountManager
;
12 import android
.accounts
.NetworkErrorException
;
13 import android
.app
.Service
;
14 import android
.content
.Context
;
15 import android
.content
.Intent
;
16 import android
.os
.Bundle
;
17 import android
.os
.IBinder
;
18 //import android.util.Log;
20 public class AccountAuthenticatorService
extends Service
{
22 private AccountAuthenticator mAuthenticator
;
23 static final public String ACCOUNT_TYPE
= "owncloud";
26 public void onCreate() {
28 mAuthenticator
= new AccountAuthenticator(this);
32 public IBinder
onBind(Intent intent
) {
33 return mAuthenticator
.getIBinder();
37 public static class AccountAuthenticator
extends AbstractAccountAuthenticator
{
39 public static final String KEY_AUTH_TOKEN_TYPE
= "authTokenType";
40 public static final String KEY_REQUIRED_FEATURES
= "requiredFeatures";
41 public static final String KEY_LOGIN_OPTIONS
= "loginOptions";
43 public AccountAuthenticator(Context context
) {
48 public Bundle
addAccount(AccountAuthenticatorResponse response
,
49 String accountType
, String authTokenType
,
50 String
[] requiredFeatures
, Bundle options
)
51 throws NetworkErrorException
{
52 //Log.e("WORKAROUND", "Yes, WORKAROUND takes the control here");
53 final Intent intent
= new Intent("com.owncloud.android.workaround.accounts.CREATE");
54 intent
.putExtra(AccountManager
.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE
,
56 intent
.putExtra(KEY_AUTH_TOKEN_TYPE
, authTokenType
);
57 intent
.putExtra(KEY_REQUIRED_FEATURES
, requiredFeatures
);
58 intent
.putExtra(KEY_LOGIN_OPTIONS
, options
);
60 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
61 intent
.addFlags(Intent
.FLAG_ACTIVITY_MULTIPLE_TASK
);
62 intent
.addFlags(Intent
.FLAG_ACTIVITY_NO_HISTORY
);
63 intent
.addFlags(Intent
.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
);
64 intent
.addFlags(Intent
.FLAG_FROM_BACKGROUND
);
66 final Bundle bundle
= new Bundle();
67 bundle
.putParcelable(AccountManager
.KEY_INTENT
, intent
);
69 //return getCommonResultBundle();
74 public Bundle
confirmCredentials(AccountAuthenticatorResponse response
,
75 Account account
, Bundle options
) throws NetworkErrorException
{
76 return getCommonResultBundle();
80 public Bundle
editProperties(AccountAuthenticatorResponse response
,
82 return getCommonResultBundle();
86 public Bundle
getAuthToken(AccountAuthenticatorResponse response
,
87 Account account
, String authTokenType
, Bundle options
)
88 throws NetworkErrorException
{
89 return getCommonResultBundle();
93 public String
getAuthTokenLabel(String authTokenType
) {
98 public Bundle
hasFeatures(AccountAuthenticatorResponse response
,
99 Account account
, String
[] features
) throws NetworkErrorException
{
100 return getCommonResultBundle();
104 public Bundle
updateCredentials(AccountAuthenticatorResponse response
,
105 Account account
, String authTokenType
, Bundle options
)
106 throws NetworkErrorException
{
107 return getCommonResultBundle();
111 public Bundle
getAccountRemovalAllowed(
112 AccountAuthenticatorResponse response
, Account account
)
113 throws NetworkErrorException
{
114 return super.getAccountRemovalAllowed(response
, account
);
117 private Bundle
getCommonResultBundle() {
118 Bundle resultBundle
= new Bundle();
119 resultBundle
.putInt(AccountManager
.KEY_ERROR_CODE
, AccountManager
.ERROR_CODE_UNSUPPORTED_OPERATION
);
120 resultBundle
.putString(AccountManager
.KEY_ERROR_MESSAGE
, "This is just a workaround, not a real account authenticator");