Home | History | Annotate | Download | only in accounts
      1 /*
      2  * Copyright (C) 2017 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.server.accounts;
     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.content.Intent;
     25 import android.os.Bundle;
     26 
     27 import com.android.frameworks.servicestests.R;
     28 
     29 import java.util.concurrent.atomic.AtomicInteger;
     30 
     31 /**
     32  * This authenticator is to mock account authenticator to test AccountManagerService.
     33  */
     34 public class TestAccountType2Authenticator extends AbstractAccountAuthenticator {
     35     private final AtomicInteger mTokenCounter  = new AtomicInteger(0);
     36 
     37     private final String mAccountType;
     38     private final Context mContext;
     39 
     40     public TestAccountType2Authenticator(Context context, String accountType) {
     41         super(context);
     42         mAccountType = accountType;
     43         mContext = context;
     44     }
     45 
     46     @Override
     47     public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
     48         throw new UnsupportedOperationException(
     49                 "editProperties is not supported by the TestAccountType2Authenticator");
     50     }
     51 
     52     @Override
     53     public Bundle addAccount(
     54             AccountAuthenticatorResponse response,
     55             String accountType,
     56             String authTokenType,
     57             String[] requiredFeatures,
     58             Bundle options) throws NetworkErrorException {
     59         throw new UnsupportedOperationException(
     60                 "addAccount is not supported by the TestAccountType2Authenticator");
     61     }
     62 
     63     @Override
     64     public Bundle confirmCredentials(
     65             AccountAuthenticatorResponse response,
     66             Account account,
     67             Bundle options) throws NetworkErrorException {
     68         throw new UnsupportedOperationException(
     69                 "confirmCredentials is not supported by the TestAccountType2Authenticator");
     70     }
     71 
     72     @Override
     73     public Bundle getAuthToken(
     74             AccountAuthenticatorResponse response,
     75             Account account,
     76             String authTokenType,
     77             Bundle options) throws NetworkErrorException {
     78         throw new UnsupportedOperationException(
     79                 "getAuthToken is not supported by the TestAccountType2Authenticator");
     80     }
     81 
     82     @Override
     83     public String getAuthTokenLabel(String authTokenType) {
     84         throw new UnsupportedOperationException(
     85                 "getAuthTokenLabel is not supported by the TestAccountType2Authenticator");
     86     }
     87 
     88     @Override
     89     public Bundle updateCredentials(
     90             AccountAuthenticatorResponse response,
     91             Account account,
     92             String authTokenType,
     93             Bundle options) throws NetworkErrorException {
     94         throw new UnsupportedOperationException(
     95                 "updateCredentials is not supported by the TestAccountType2Authenticator");
     96     }
     97 
     98     @Override
     99     public Bundle hasFeatures(
    100             AccountAuthenticatorResponse response,
    101             Account account,
    102             String[] features) throws NetworkErrorException {
    103         throw new UnsupportedOperationException(
    104                 "hasFeatures is not supported by the TestAccountType2Authenticator");
    105     }
    106 
    107     @Override
    108     public Bundle startAddAccountSession(
    109             AccountAuthenticatorResponse response,
    110             String accountType,
    111             String authTokenType,
    112             String[] requiredFeatures,
    113             Bundle options) throws NetworkErrorException {
    114         throw new UnsupportedOperationException(
    115                 "startAddAccountSession is not supported by the TestAccountType2Authenticator");
    116     }
    117 
    118     @Override
    119     public Bundle startUpdateCredentialsSession(
    120             AccountAuthenticatorResponse response,
    121             Account account,
    122             String authTokenType,
    123             Bundle options)
    124             throws NetworkErrorException {
    125         throw new UnsupportedOperationException(
    126                 "startUpdateCredentialsSession is not supported " +
    127                 "by the TestAccountType2Authenticator");
    128     }
    129 
    130     @Override
    131     public Bundle finishSession(AccountAuthenticatorResponse response,
    132             String accountType,
    133             Bundle sessionBundle) throws NetworkErrorException {
    134         throw new UnsupportedOperationException(
    135                 "finishSession is not supported by the TestAccountType2Authenticator");
    136     }
    137 
    138     @Override
    139     public Bundle isCredentialsUpdateSuggested(
    140             final AccountAuthenticatorResponse response,
    141             Account account,
    142             String statusToken) throws NetworkErrorException {
    143         throw new UnsupportedOperationException(
    144                 "isCredentialsUpdateSuggested is not supported " +
    145                 "by the TestAccountType2Authenticator");
    146     }
    147 }