Merge "Reland 'Check /dev/binder access before calling defaultServiceManager()'" am: 4f42ac7989
am: d16c37d5a0

Change-Id: I624ed23839a297b652701079aab7e6c091eefb4d
diff --git a/ashmemd_client.cpp b/ashmemd_client.cpp
index 3380209..04227ba 100644
--- a/ashmemd_client.cpp
+++ b/ashmemd_client.cpp
@@ -28,6 +28,11 @@
 namespace ashmemd {
 
 sp<IAshmemDeviceService> getAshmemService() {
+    // Calls to defaultServiceManager() crash the process if it doesn't have appropriate
+    // binder permissions. Check these permissions proactively.
+    if (access("/dev/binder", R_OK | W_OK) != 0) {
+        return nullptr;
+    }
     sp<IServiceManager> sm = android::defaultServiceManager();
     sp<IBinder> binder = sm->checkService(String16("ashmem_device_service"));
     return interface_cast<IAshmemDeviceService>(binder);