| Alex Klyubin | cc21bb3 | 2015-03-31 16:50:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| Alex Klyubin | d23a1f7 | 2015-03-27 14:39:28 -0700 | [diff] [blame] | 17 | package android.security; |
| 18 | |
| Alex Klyubin | acc835f | 2015-03-31 15:26:56 -0700 | [diff] [blame] | 19 | import android.security.keymaster.KeyCharacteristics; |
| Alex Klyubin | d23a1f7 | 2015-03-27 14:39:28 -0700 | [diff] [blame] | 20 | |
| Alex Klyubin | acc835f | 2015-03-31 15:26:56 -0700 | [diff] [blame] | 21 | import java.util.ArrayList; |
| 22 | import java.util.Date; |
| 23 | import java.util.List; |
| 24 | |
| Alex Klyubin | d23a1f7 | 2015-03-27 14:39:28 -0700 | [diff] [blame] | 25 | /** |
| 26 | * @hide |
| 27 | */ |
| 28 | public abstract class KeymasterUtils { |
| 29 | private KeymasterUtils() {} |
| 30 | |
| Alex Klyubin | acc835f | 2015-03-31 15:26:56 -0700 | [diff] [blame] | 31 | public static Integer getInt(KeyCharacteristics keyCharacteristics, int tag) { |
| 32 | if (keyCharacteristics.hwEnforced.containsTag(tag)) { |
| 33 | return keyCharacteristics.hwEnforced.getInt(tag, -1); |
| 34 | } else if (keyCharacteristics.swEnforced.containsTag(tag)) { |
| 35 | return keyCharacteristics.swEnforced.getInt(tag, -1); |
| 36 | } else { |
| 37 | return null; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public static List<Integer> getInts(KeyCharacteristics keyCharacteristics, int tag) { |
| 42 | List<Integer> result = new ArrayList<Integer>(); |
| 43 | result.addAll(keyCharacteristics.hwEnforced.getInts(tag)); |
| 44 | result.addAll(keyCharacteristics.swEnforced.getInts(tag)); |
| 45 | return result; |
| 46 | } |
| 47 | |
| 48 | public static Date getDate(KeyCharacteristics keyCharacteristics, int tag) { |
| 49 | Date result = keyCharacteristics.hwEnforced.getDate(tag, null); |
| 50 | if (result == null) { |
| 51 | result = keyCharacteristics.swEnforced.getDate(tag, null); |
| 52 | } |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | public static boolean getBoolean(KeyCharacteristics keyCharacteristics, int tag) { |
| 57 | if (keyCharacteristics.hwEnforced.containsTag(tag)) { |
| 58 | return keyCharacteristics.hwEnforced.getBoolean(tag, false); |
| 59 | } else { |
| 60 | return keyCharacteristics.swEnforced.getBoolean(tag, false); |
| 61 | } |
| 62 | } |
| Alex Klyubin | d23a1f7 | 2015-03-27 14:39:28 -0700 | [diff] [blame] | 63 | } |