blob: 561783627ebdcd3a7f480c6c8c179a56c0607be8 [file] [log] [blame]
Alex Klyubin10a9f172015-04-16 13:41:19 -07001package android.security;
2
3import android.os.RemoteException;
4import android.os.ServiceManager;
5import android.os.UserHandle;
6import android.service.gatekeeper.IGateKeeperService;
7
8/**
9 * Convenience class for accessing the gatekeeper service.
10 *
11 * @hide
12 */
13public abstract class GateKeeper {
14
15 private GateKeeper() {}
16
17 public static IGateKeeperService getService() {
Alex Klyubin708fc9402015-04-28 18:58:47 -070018 IGateKeeperService service = IGateKeeperService.Stub.asInterface(
Alex Klyubin10a9f172015-04-16 13:41:19 -070019 ServiceManager.getService("android.service.gatekeeper.IGateKeeperService"));
Alex Klyubin708fc9402015-04-28 18:58:47 -070020 if (service == null) {
21 throw new IllegalStateException("Gatekeeper service not available");
22 }
23 return service;
Alex Klyubin10a9f172015-04-16 13:41:19 -070024 }
25
26 public static long getSecureUserId() throws IllegalStateException {
27 try {
Alex Klyubin708fc9402015-04-28 18:58:47 -070028 return getService().getSecureUserId(UserHandle.myUserId());
Alex Klyubin10a9f172015-04-16 13:41:19 -070029 } catch (RemoteException e) {
30 throw new IllegalStateException(
31 "Failed to obtain secure user ID from gatekeeper", e);
32 }
33 }
34}