Refresh the native app ops manager's token if needed.

The app ops manager serivce keeps track of started app ops
by a process by stashing them in a binder object that is
passed to the remote process to hold on to. Hence, the data
is in the system process and is referenced by the client
process it tracks to prevent garbage collaction and limit
risk of resource leaks. It is possible that the client
process is longer lived than the system seriver, e.g. camera
server starts an app op, the system server dies for some
reason, the camera server's app ops manager ends up with
a stale token. The solution is to check the validity of the
token and refresh it if needed.

bug:27344593

Change-Id: I0abb39e777b7b66b1b5cefede7e7b41c4404c4b1
diff --git a/AppOpsManager.cpp b/AppOpsManager.cpp
index e4d8201..9a061a0 100644
--- a/AppOpsManager.cpp
+++ b/AppOpsManager.cpp
@@ -28,7 +28,7 @@
 
 static const sp<IBinder>& getToken(const sp<IAppOpsService>& service) {
     pthread_mutex_lock(&gTokenMutex);
-    if (gToken == NULL) {
+    if (gToken == NULL || gToken->pingBinder() != NO_ERROR) {
         gToken = service->getToken(new BBinder());
     }
     pthread_mutex_unlock(&gTokenMutex);