OSDN Git Service

Adding a little more verbose logging.
authorJeremy Joslin <jjoslin@google.com>
Mon, 13 Feb 2017 19:35:03 +0000 (11:35 -0800)
committerJeremy Joslin <jjoslin@google.com>
Mon, 13 Feb 2017 19:35:03 +0000 (11:35 -0800)
Log statements to help track the request call path.

Test: manual
Change-Id: I68cfdf68cf8adcece45de2a60bec94e6f06be761

core/java/android/net/NetworkRecommendationProvider.java
services/core/java/com/android/server/NetworkScoreService.java

index 5739c79..8395864 100644 (file)
@@ -1,6 +1,7 @@
 package android.net;
 
 import android.annotation.SystemApi;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -20,6 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 @SystemApi
 public abstract class NetworkRecommendationProvider {
     private static final String TAG = "NetworkRecProvider";
+    private static final boolean VERBOSE = Build.IS_DEBUGGABLE && Log.isLoggable(TAG, Log.VERBOSE);
     /** The key into the callback Bundle where the RecommendationResult will be found. */
     public static final String EXTRA_RECOMMENDATION_RESULT =
             "android.net.extra.RECOMMENDATION_RESULT";
@@ -91,8 +93,10 @@ public abstract class NetworkRecommendationProvider {
          * @param result a {@link RecommendationResult} instance.
          */
         public void onResult(RecommendationResult result) {
+            if (VERBOSE) Log.v(TAG, "onResult(seq=" + mSequence + ")");
             if (!mCallbackRun.compareAndSet(false, true)) {
-                throw new IllegalStateException("The callback cannot be run more than once.");
+                throw new IllegalStateException("The callback cannot be run more than once. "
+                        + "seq=" + mSequence);
             }
             final Bundle data = new Bundle();
             data.putInt(EXTRA_SEQUENCE, mSequence);
@@ -102,6 +106,7 @@ public abstract class NetworkRecommendationProvider {
             } catch (RemoteException e) {
                 Log.w(TAG, "Callback failed for seq: " + mSequence, e);
             }
+            if (VERBOSE) Log.v(TAG, "onResult() complete. seq=" + mSequence);
         }
 
         @Override
@@ -134,9 +139,13 @@ public abstract class NetworkRecommendationProvider {
         @Override
         public void requestRecommendation(final RecommendationRequest request,
                 final IRemoteCallback callback, final int sequence) throws RemoteException {
+            if (VERBOSE) Log.v(TAG, "requestRecommendation(seq=" + sequence + ")");
             mHandler.post(new Runnable() {
                 @Override
                 public void run() {
+                    if (VERBOSE) {
+                        Log.v(TAG, "requestRecommendation(seq=" + sequence + ") running...");
+                    }
                     ResultCallback resultCallback = new ResultCallback(callback, sequence);
                     onRequestRecommendation(request, resultCallback);
                 }
index f9b5db6..3e89852 100644 (file)
@@ -917,6 +917,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
                 return;
             }
             writer.println("Current scorer: " + currentScorer);
+            writer.println("RecommendationRequestTimeoutMs: " + mRecommendationRequestTimeoutMs);
 
             sendCacheUpdateCallback(new BiConsumer<INetworkScoreCache, Object>() {
                 @Override
@@ -1086,6 +1087,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
                     final RecommendationResult result =
                             data.getParcelable(EXTRA_RECOMMENDATION_RESULT);
                     final int sequence = data.getInt(EXTRA_SEQUENCE, -1);
+                    if (VERBOSE) Log.v(TAG, "callback received for sequence " + sequence);
                     onRemoteMethodResult(result, sequence);
                 }
             };
@@ -1105,6 +1107,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
         RecommendationResult getRecommendationResult(INetworkRecommendationProvider target,
                 RecommendationRequest request) throws RemoteException, TimeoutException {
             final int sequence = onBeforeRemoteCall();
+            if (VERBOSE) Log.v(TAG, "getRecommendationResult() seq=" + sequence);
             target.requestRecommendation(request, mCallback, sequence);
             return getResultTimed(sequence);
         }