| Alex Klyubin | dcdaf87 | 2015-05-13 15:57:09 -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 | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 17 | package android.security; |
| 18 | |
| 19 | import android.os.RemoteException; |
| 20 | import android.os.ServiceManager; |
| 21 | import android.os.UserHandle; |
| 22 | import android.service.gatekeeper.IGateKeeperService; |
| 23 | |
| 24 | /** |
| 25 | * Convenience class for accessing the gatekeeper service. |
| 26 | * |
| 27 | * @hide |
| 28 | */ |
| 29 | public abstract class GateKeeper { |
| 30 | |
| 31 | private GateKeeper() {} |
| 32 | |
| 33 | public static IGateKeeperService getService() { |
| Alex Klyubin | 708fc940 | 2015-04-28 18:58:47 -0700 | [diff] [blame] | 34 | IGateKeeperService service = IGateKeeperService.Stub.asInterface( |
| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 35 | ServiceManager.getService("android.service.gatekeeper.IGateKeeperService")); |
| Alex Klyubin | 708fc940 | 2015-04-28 18:58:47 -0700 | [diff] [blame] | 36 | if (service == null) { |
| 37 | throw new IllegalStateException("Gatekeeper service not available"); |
| 38 | } |
| 39 | return service; |
| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public static long getSecureUserId() throws IllegalStateException { |
| 43 | try { |
| Alex Klyubin | 708fc940 | 2015-04-28 18:58:47 -0700 | [diff] [blame] | 44 | return getService().getSecureUserId(UserHandle.myUserId()); |
| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 45 | } catch (RemoteException e) { |
| 46 | throw new IllegalStateException( |
| 47 | "Failed to obtain secure user ID from gatekeeper", e); |
| 48 | } |
| 49 | } |
| 50 | } |