1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.bluetooth.pbapclient;
17 
18 import android.accounts.AbstractAccountAuthenticator;
19 import android.accounts.Account;
20 import android.accounts.AccountAuthenticatorResponse;
21 import android.accounts.AccountManager;
22 import android.accounts.NetworkErrorException;
23 import android.content.Context;
24 import android.os.Bundle;
25 import android.util.Log;
26 
27 public class Authenticator extends AbstractAccountAuthenticator {
28     private static final String TAG = "PbapAuthenticator";
29     private static final boolean DBG = Utils.DBG;
30 
Authenticator(Context context)31     public Authenticator(Context context) {
32         super(context);
33     }
34 
35     // Editing properties is not supported
36     @Override
editProperties(AccountAuthenticatorResponse r, String s)37     public Bundle editProperties(AccountAuthenticatorResponse r, String s) {
38         if (DBG) Log.d(TAG, "got call", new Exception());
39         throw new UnsupportedOperationException();
40     }
41 
42     // Don't add additional accounts
43     @Override
addAccount(AccountAuthenticatorResponse r, String s, String s2, String[] strings, Bundle bundle)44     public Bundle addAccount(AccountAuthenticatorResponse r, String s, String s2, String[] strings,
45             Bundle bundle) throws NetworkErrorException {
46         if (DBG) Log.d(TAG, "got call", new Exception());
47         // Don't allow accounts to be added.
48         throw new UnsupportedOperationException();
49     }
50 
51     // Ignore attempts to confirm credentials
52     @Override
confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle)53     public Bundle confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle)
54             throws NetworkErrorException {
55         if (DBG) Log.d(TAG, "got call", new Exception());
56         return null;
57     }
58 
59     // Getting an authentication token is not supported
60     @Override
getAuthToken(AccountAuthenticatorResponse r, Account account, String s, Bundle bundle)61     public Bundle getAuthToken(AccountAuthenticatorResponse r, Account account, String s,
62             Bundle bundle) throws NetworkErrorException {
63         if (DBG) Log.d(TAG, "got call", new Exception());
64         throw new UnsupportedOperationException();
65     }
66 
67     // Getting a label for the auth token is not supported
68     @Override
getAuthTokenLabel(String s)69     public String getAuthTokenLabel(String s) {
70         if (DBG) Log.d(TAG, "got call", new Exception());
71         return null;
72     }
73 
74     // Updating user credentials is not supported
75     @Override
updateCredentials(AccountAuthenticatorResponse r, Account account, String s, Bundle bundle)76     public Bundle updateCredentials(AccountAuthenticatorResponse r, Account account, String s,
77             Bundle bundle) throws NetworkErrorException {
78         if (DBG) Log.d(TAG, "got call", new Exception());
79         return null;
80     }
81 
82     // Checking features for the account is not supported
83     @Override
hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings)84     public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings)
85             throws NetworkErrorException {
86         if (DBG) Log.d(TAG, "got call", new Exception());
87 
88         final Bundle result = new Bundle();
89         result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
90         return result;
91     }
92 }
93