blob: c1df28c387e51af5ab91b2e945f6c80777817835 [file] [log] [blame]
Alex Klyubindcdaf872015-05-13 15:57:09 -07001/*
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 Klyubin10a9f172015-04-16 13:41:19 -070017package android.security;
18
19import android.os.RemoteException;
20import android.os.ServiceManager;
21import android.os.UserHandle;
22import android.service.gatekeeper.IGateKeeperService;
23
24/**
25 * Convenience class for accessing the gatekeeper service.
26 *
27 * @hide
28 */
29public abstract class GateKeeper {
30
31 private GateKeeper() {}
32
33 public static IGateKeeperService getService() {
Alex Klyubin708fc9402015-04-28 18:58:47 -070034 IGateKeeperService service = IGateKeeperService.Stub.asInterface(
Alex Klyubin10a9f172015-04-16 13:41:19 -070035 ServiceManager.getService("android.service.gatekeeper.IGateKeeperService"));
Alex Klyubin708fc9402015-04-28 18:58:47 -070036 if (service == null) {
37 throw new IllegalStateException("Gatekeeper service not available");
38 }
39 return service;
Alex Klyubin10a9f172015-04-16 13:41:19 -070040 }
41
42 public static long getSecureUserId() throws IllegalStateException {
43 try {
Alex Klyubin708fc9402015-04-28 18:58:47 -070044 return getService().getSecureUserId(UserHandle.myUserId());
Alex Klyubin10a9f172015-04-16 13:41:19 -070045 } catch (RemoteException e) {
46 throw new IllegalStateException(
47 "Failed to obtain secure user ID from gatekeeper", e);
48 }
49 }
50}