| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 1 | package android.security; |
| 2 | |
| 3 | import android.os.RemoteException; |
| 4 | import android.os.ServiceManager; |
| 5 | import android.os.UserHandle; |
| 6 | import android.service.gatekeeper.IGateKeeperService; |
| 7 | |
| 8 | /** |
| 9 | * Convenience class for accessing the gatekeeper service. |
| 10 | * |
| 11 | * @hide |
| 12 | */ |
| 13 | public abstract class GateKeeper { |
| 14 | |
| 15 | private GateKeeper() {} |
| 16 | |
| 17 | public static IGateKeeperService getService() { |
| Alex Klyubin | 708fc940 | 2015-04-28 18:58:47 -0700 | [diff] [blame^] | 18 | IGateKeeperService service = IGateKeeperService.Stub.asInterface( |
| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 19 | ServiceManager.getService("android.service.gatekeeper.IGateKeeperService")); |
| Alex Klyubin | 708fc940 | 2015-04-28 18:58:47 -0700 | [diff] [blame^] | 20 | if (service == null) { |
| 21 | throw new IllegalStateException("Gatekeeper service not available"); |
| 22 | } |
| 23 | return service; |
| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | public static long getSecureUserId() throws IllegalStateException { |
| 27 | try { |
| Alex Klyubin | 708fc940 | 2015-04-28 18:58:47 -0700 | [diff] [blame^] | 28 | return getService().getSecureUserId(UserHandle.myUserId()); |
| Alex Klyubin | 10a9f17 | 2015-04-16 13:41:19 -0700 | [diff] [blame] | 29 | } catch (RemoteException e) { |
| 30 | throw new IllegalStateException( |
| 31 | "Failed to obtain secure user ID from gatekeeper", e); |
| 32 | } |
| 33 | } |
| 34 | } |