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 com.android.server.locksettings;
18 
19 import android.hardware.authsecret.IAuthSecret;
20 import android.os.IBinder;
21 import android.os.RemoteException;
22 
23 import java.util.ArrayList;
24 
25 /**
26  * Adapt the legacy HIDL interface to present the AIDL interface.
27  */
28 class AuthSecretHidlAdapter implements IAuthSecret {
29     // private final String TAG = "AuthSecretHidlAdapter";
30     private final android.hardware.authsecret.V1_0.IAuthSecret mImpl;
31 
AuthSecretHidlAdapter(android.hardware.authsecret.V1_0.IAuthSecret impl)32     AuthSecretHidlAdapter(android.hardware.authsecret.V1_0.IAuthSecret impl) {
33         mImpl = impl;
34     }
35 
36     @Override
setPrimaryUserCredential(byte[] secret)37     public void setPrimaryUserCredential(byte[] secret) throws RemoteException {
38         final ArrayList<Byte> secretAsArrayList = new ArrayList<>(secret.length);
39         for (int i = 0; i < secret.length; ++i) {
40             secretAsArrayList.add(secret[i]);
41         }
42         mImpl.primaryUserCredential(secretAsArrayList);
43     }
44 
45     @Override
getInterfaceVersion()46     public int getInterfaceVersion() throws RemoteException {
47         // Supports only V1
48         return 1;
49     }
50 
51     @Override
asBinder()52     public IBinder asBinder() {
53         throw new UnsupportedOperationException("AuthSecretHidlAdapter does not support asBinder");
54     }
55 
56     @Override
getInterfaceHash()57     public String getInterfaceHash() throws RemoteException {
58         throw new UnsupportedOperationException(
59                 "AuthSecretHidlAdapter does not support getInterfaceHash");
60     }
61 }
62