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 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 GateKeeper()31 private GateKeeper() {} 32 getService()33 public static IGateKeeperService getService() { 34 IGateKeeperService service = IGateKeeperService.Stub.asInterface( 35 ServiceManager.getService("android.service.gatekeeper.IGateKeeperService")); 36 if (service == null) { 37 throw new IllegalStateException("Gatekeeper service not available"); 38 } 39 return service; 40 } 41 getSecureUserId()42 public static long getSecureUserId() throws IllegalStateException { 43 try { 44 return getService().getSecureUserId(UserHandle.myUserId()); 45 } catch (RemoteException e) { 46 throw new IllegalStateException( 47 "Failed to obtain secure user ID from gatekeeper", e); 48 } 49 } 50 } 51