Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame^] | 1 | /** |
| 2 | * Copyright (C) 2018 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.face; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.hardware.biometrics.face.V1_0.IBiometricsFace; |
| 21 | import android.hardware.face.FaceManager; |
| 22 | import android.hardware.face.IFaceServiceReceiver; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.RemoteException; |
| 25 | import android.util.Slog; |
| 26 | import com.android.internal.logging.MetricsLogger; |
| 27 | |
| 28 | /** |
| 29 | * A class to keep track of the remove state for a given client. |
| 30 | */ |
| 31 | public abstract class RemovalClient extends ClientMonitor { |
| 32 | |
| 33 | public RemovalClient(Context context, long halDeviceId, IBinder token, |
| 34 | IFaceServiceReceiver receiver, int userId, |
| 35 | boolean restricted, String owner) { |
| 36 | super(context, halDeviceId, token, receiver, userId, restricted, owner); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public int start() { |
| 41 | IBiometricsFace daemon = getFaceDaemon(); |
| 42 | // The face template ids will be removed when we get confirmation from the HAL |
| 43 | try { |
| 44 | final int result = daemon.remove(getTargetUserId()); |
| 45 | if (result != 0) { |
| 46 | Slog.w(TAG, "startRemove failed, result=" + result); |
| 47 | MetricsLogger.histogram(getContext(), "faced_remove_start_error", result); |
| 48 | onError(FaceManager.FACE_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */); |
| 49 | return result; |
| 50 | } |
| 51 | } catch (RemoteException e) { |
| 52 | Slog.e(TAG, "startRemove failed", e); |
| 53 | } |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int stop(boolean initiatedByClient) { |
| 59 | if (mAlreadyCancelled) { |
| 60 | Slog.w(TAG, "stopRemove: already cancelled!"); |
| 61 | return 0; |
| 62 | } |
| 63 | IBiometricsFace daemon = getFaceDaemon(); |
| 64 | if (daemon == null) { |
| 65 | Slog.w(TAG, "stopRemoval: no face HAL!"); |
| 66 | return ERROR_ESRCH; |
| 67 | } |
| 68 | try { |
| 69 | final int result = daemon.cancel(); |
| 70 | if (result != 0) { |
| 71 | Slog.w(TAG, "stopRemoval failed, result=" + result); |
| 72 | return result; |
| 73 | } |
| 74 | if (DEBUG) Slog.w(TAG, "client " + getOwnerString() + " is no longer removing"); |
| 75 | } catch (RemoteException e) { |
| 76 | Slog.e(TAG, "stopRemoval failed", e); |
| 77 | return ERROR_ESRCH; |
| 78 | } |
| 79 | mAlreadyCancelled = true; |
| 80 | return 0; // success |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * @return true if we're done. |
| 85 | */ |
| 86 | private boolean sendRemoved(int faceId, int remaining) { |
| 87 | IFaceServiceReceiver receiver = getReceiver(); |
| 88 | try { |
| 89 | if (receiver != null) { |
| 90 | receiver.onRemoved(getHalDeviceId(), faceId, remaining); |
| 91 | } |
| 92 | } catch (RemoteException e) { |
| 93 | Slog.w(TAG, "Failed to notify Removed:", e); |
| 94 | } |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean onRemoved(int faceId, int remaining) { |
| 100 | FaceUtils.getInstance().removeFaceForUser(getContext(), getTargetUserId()); |
| 101 | return sendRemoved(faceId, remaining); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean onEnrollResult(int faceId, int remaining) { |
| 106 | if (DEBUG) Slog.w(TAG, "onEnrollResult() called for remove!"); |
| 107 | return true; // Invalid for Remove |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public boolean onAuthenticated(int faceId) { |
| 112 | if (DEBUG) Slog.w(TAG, "onAuthenticated() called for remove!"); |
| 113 | return true; // Invalid for Remove. |
| 114 | } |
| 115 | } |