2015-04-16 13:41:19 -07:00
|
|
|
package android.security;
|
|
|
|
|
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.os.ServiceManager;
|
|
|
|
import android.os.UserHandle;
|
|
|
|
import android.service.gatekeeper.IGateKeeperService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience class for accessing the gatekeeper service.
|
|
|
|
*
|
|
|
|
* @hide
|
|
|
|
*/
|
|
|
|
public abstract class GateKeeper {
|
|
|
|
|
|
|
|
private GateKeeper() {}
|
|
|
|
|
|
|
|
public static IGateKeeperService getService() {
|
2015-04-28 18:58:47 -07:00
|
|
|
IGateKeeperService service = IGateKeeperService.Stub.asInterface(
|
2015-04-16 13:41:19 -07:00
|
|
|
ServiceManager.getService("android.service.gatekeeper.IGateKeeperService"));
|
2015-04-28 18:58:47 -07:00
|
|
|
if (service == null) {
|
|
|
|
throw new IllegalStateException("Gatekeeper service not available");
|
|
|
|
}
|
|
|
|
return service;
|
2015-04-16 13:41:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static long getSecureUserId() throws IllegalStateException {
|
|
|
|
try {
|
2015-04-28 18:58:47 -07:00
|
|
|
return getService().getSecureUserId(UserHandle.myUserId());
|
2015-04-16 13:41:19 -07:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Failed to obtain secure user ID from gatekeeper", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|