EnumerateClient.java revision 8f2aca0ee4ff0eff6226df05d1531d2f2fa2f3c1
1/** 2 * Copyright (C) 2016 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 17package com.android.server.fingerprint; 18 19import android.content.Context; 20import android.hardware.fingerprint.FingerprintManager; 21import android.hardware.fingerprint.IFingerprintDaemon; 22import android.hardware.fingerprint.IFingerprintServiceReceiver; 23import android.os.IBinder; 24import android.os.RemoteException; 25import android.util.Slog; 26 27/** 28 * A class to keep track of the enumeration state for a given client. 29 */ 30public abstract class EnumerateClient extends ClientMonitor { 31 public EnumerateClient(Context context, long halDeviceId, IBinder token, 32 IFingerprintServiceReceiver receiver, int userId, int groupId, 33 boolean restricted, String owner) { 34 super(context, halDeviceId, token, receiver, userId, groupId, restricted, owner); 35 } 36 37 @Override 38 public int start() { 39 IFingerprintDaemon daemon = getFingerprintDaemon(); 40 // The fingerprint template ids will be removed when we get confirmation from the HAL 41 try { 42 final int result = daemon.enumerate(); 43 if (result != 0) { 44 Slog.w(TAG, "start enumerate for user " + getTargetUserId() 45 + " failed, result=" + result); 46 onError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE); 47 return result; 48 } 49 } catch (RemoteException e) { 50 Slog.e(TAG, "startRemove failed", e); 51 } 52 return 0; 53 } 54 55 @Override 56 public int stop(boolean initiatedByClient) { 57 IFingerprintDaemon daemon = getFingerprintDaemon(); 58 if (daemon == null) { 59 Slog.w(TAG, "stopAuthentication: no fingeprintd!"); 60 return ERROR_ESRCH; 61 } 62 try { 63 final int result = daemon.cancelEnumeration(); 64 if (result != 0) { 65 Slog.w(TAG, "stop enumeration failed, result=" + result); 66 return result; 67 } 68 } catch (RemoteException e) { 69 Slog.e(TAG, "stop enumeration failed", e); 70 return ERROR_ESRCH; 71 } 72 // We don't actually stop enumerate, but inform the client that the cancel operation 73 // succeeded so we can start the next operation. 74 if (initiatedByClient) { 75 onError(FingerprintManager.FINGERPRINT_ERROR_CANCELED); 76 } 77 return 0; // success 78 } 79 80 @Override 81 public boolean onEnumerationResult(int fingerId, int groupId) { 82 IFingerprintServiceReceiver receiver = getReceiver(); 83 if (receiver == null) 84 return true; // client not listening 85 try { 86 receiver.onRemoved(getHalDeviceId(), fingerId, groupId); 87 } catch (RemoteException e) { 88 Slog.w(TAG, "Failed to notify enumerated:", e); 89 } 90 return fingerId == 0; // done when id hits 0 91 } 92} 93