1 /*
2  * Copyright 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 com.example.android.sampletvinput.syncadapter;
18 
19 import android.accounts.AbstractAccountAuthenticator;
20 import android.accounts.Account;
21 import android.accounts.AccountAuthenticatorResponse;
22 import android.accounts.NetworkErrorException;
23 import android.app.Service;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.os.Bundle;
27 import android.os.IBinder;
28 
29 
30 /**
31  * Stub account service for SyncAdapter. Note that this does nothing because this input uses a feed
32  * which does not require any authentication.
33  */
34 public class StubAccountService extends Service {
35     private static final String TAG = "StubAccountService";
36     private StubAuthenticator mAuthenticator;
37     public static final String ACCOUNT_NAME = "StubAccount";
38 
getAccount(String accountType)39     public static Account getAccount(String accountType) {
40         return new Account(ACCOUNT_NAME, accountType);
41     }
42 
43     @Override
onCreate()44     public void onCreate() {
45         mAuthenticator = new StubAuthenticator(this);
46     }
47 
48     @Override
onBind(Intent intent)49     public IBinder onBind(Intent intent) {
50         return mAuthenticator.getIBinder();
51     }
52 
53     /**
54      * Stub Authenticator used in {@link SyncAdapter}. This does nothing for all the operations
55      * since channel/program feed does not require any authentication.
56      */
57     public class StubAuthenticator extends AbstractAccountAuthenticator {
StubAuthenticator(Context context)58         public StubAuthenticator(Context context) {
59             super(context);
60         }
61 
62         @Override
editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse, String s)63         public Bundle editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse,
64                 String s) {
65             throw new UnsupportedOperationException();
66         }
67 
68         @Override
addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse, String s, String s2, String[] strings, Bundle bundle)69         public Bundle addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse,
70                 String s, String s2, String[] strings, Bundle bundle) throws NetworkErrorException {
71             return null;
72         }
73 
74         @Override
confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, Bundle bundle)75         public Bundle confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse,
76                 Account account, Bundle bundle) throws NetworkErrorException {
77             return null;
78         }
79 
80         @Override
getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String s, Bundle bundle)81         public Bundle getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse,
82                 Account account, String s, Bundle bundle) throws NetworkErrorException {
83             throw new UnsupportedOperationException();
84         }
85 
86         @Override
getAuthTokenLabel(String s)87         public String getAuthTokenLabel(String s) {
88             throw new UnsupportedOperationException();
89         }
90 
91         @Override
updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String s, Bundle bundle)92         public Bundle updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse,
93                 Account account, String s, Bundle bundle) throws NetworkErrorException {
94             throw new UnsupportedOperationException();
95         }
96 
97         @Override
hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String[] strings)98         public Bundle hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse,
99                 Account account, String[] strings) throws NetworkErrorException {
100             throw new UnsupportedOperationException();
101         }
102     }
103 
104 }
105 
106