1 /*
2  * Copyright (C) 2015 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 
17 package android.telecom;
18 import android.accounts.AbstractAccountAuthenticator;
19 import android.accounts.Account;
20 import android.accounts.AccountAuthenticatorResponse;
21 import android.accounts.NetworkErrorException;
22 import android.app.Service;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.os.Bundle;
26 import android.os.IBinder;
27 
28 /**
29  * A generic stub account authenticator service often used for sync adapters that do not directly
30  * involve accounts.
31  *
32  * @hide
33  */
34 public class AuthenticatorService extends Service {
35     private static Authenticator mAuthenticator;
36 
37     @Override
onCreate()38     public void onCreate() {
39         mAuthenticator = new Authenticator(this);
40     }
41 
42     @Override
onBind(Intent intent)43     public IBinder onBind(Intent intent) {
44         return mAuthenticator.getIBinder();
45     }
46 
47     /**
48      * Stub account authenticator. All methods either return null or throw an exception.
49      */
50     public class Authenticator extends AbstractAccountAuthenticator {
Authenticator(Context context)51         public Authenticator(Context context) {
52             super(context);
53         }
54 
55         @Override
editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse, String s)56         public Bundle editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse,
57                                      String s) {
58             throw new UnsupportedOperationException();
59         }
60 
61         @Override
addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse, String s, String s2, String[] strings, Bundle bundle)62         public Bundle addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse,
63                                  String s, String s2, String[] strings, Bundle bundle)
64                 throws NetworkErrorException {
65             return null;
66         }
67 
68         @Override
confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, Bundle bundle)69         public Bundle confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse,
70                                          Account account, Bundle bundle)
71                 throws NetworkErrorException {
72             return null;
73         }
74 
75         @Override
getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String s, Bundle bundle)76         public Bundle getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse,
77                                    Account account, String s, Bundle bundle)
78                 throws NetworkErrorException {
79             throw new UnsupportedOperationException();
80         }
81 
82         @Override
getAuthTokenLabel(String s)83         public String getAuthTokenLabel(String s) {
84             throw new UnsupportedOperationException();
85         }
86 
87         @Override
updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String s, Bundle bundle)88         public Bundle updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse,
89                                         Account account, String s, Bundle bundle)
90                 throws NetworkErrorException {
91             throw new UnsupportedOperationException();
92         }
93 
94         @Override
hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String[] strings)95         public Bundle hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse,
96                                   Account account, String[] strings)
97                 throws NetworkErrorException {
98             throw new UnsupportedOperationException();
99         }
100     }
101 }
102