From fdcffa46bc4a186c3a2830077adc6aefea4de99f Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Wed, 9 Jun 2021 10:10:05 -0700 Subject: [PATCH] Add more logging around extra attribution tags Bug: 190073375 Test: manual Change-Id: I9557524957f5b4d43d953a11f56aae229d9c6b1f --- .../provider/AbstractLocationProvider.java | 4 ++++ .../provider/MockableLocationProvider.java | 5 +++++ .../provider/proxy/ProxyLocationProvider.java | 7 +++++++ .../servicewatcher/ServiceWatcherImpl.java | 19 ++++++++++--------- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java b/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java index ba7f44f2818b4..1da45bd497678 100644 --- a/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java +++ b/services/core/java/com/android/server/location/provider/AbstractLocationProvider.java @@ -305,6 +305,10 @@ public abstract class AbstractLocationProvider { setState(state -> state.withIdentity(identity)); } + public final Set getExtraAttributionTags() { + return mInternalState.get().state.extraAttributionTags; + } + /** * Call this method to report a change in the provider's extra attribution tags. */ diff --git a/services/core/java/com/android/server/location/provider/MockableLocationProvider.java b/services/core/java/com/android/server/location/provider/MockableLocationProvider.java index 81936440f6a73..021e8dbdb44e3 100644 --- a/services/core/java/com/android/server/location/provider/MockableLocationProvider.java +++ b/services/core/java/com/android/server/location/provider/MockableLocationProvider.java @@ -32,6 +32,7 @@ import com.android.internal.util.Preconditions; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.Collections; +import java.util.Set; /** * Represents a location provider that may switch between a mock implementation and a real @@ -296,6 +297,10 @@ public class MockableLocationProvider extends AbstractLocationProvider { if (identity != null) { pw.println("identity=" + identity); } + Set extraAttributionTags = getExtraAttributionTags(); + if (!extraAttributionTags.isEmpty()) { + pw.println("extra attribution tags=" + extraAttributionTags); + } ProviderProperties properties = getProperties(); if (properties != null) { pw.println("properties=" + properties); diff --git a/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java b/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java index 5df78704d002c..a9641f0f1c1b2 100644 --- a/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java +++ b/services/core/java/com/android/server/location/provider/proxy/ProxyLocationProvider.java @@ -17,6 +17,7 @@ package com.android.server.location.provider.proxy; import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR; +import static com.android.server.location.LocationManagerService.TAG; import android.annotation.Nullable; import android.content.Context; @@ -32,6 +33,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.text.TextUtils; import android.util.ArraySet; +import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.server.FgThread; @@ -44,6 +46,7 @@ import com.android.server.servicewatcher.ServiceWatcher.ServiceListener; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -78,6 +81,7 @@ public class ProxyLocationProvider extends AbstractLocationProvider implements final Context mContext; final ServiceWatcher mServiceWatcher; + final String mName; @GuardedBy("mLock") final ArrayList mFlushListeners = new ArrayList<>(0); @@ -101,6 +105,7 @@ public class ProxyLocationProvider extends AbstractLocationProvider implements mServiceWatcher = ServiceWatcher.create(context, provider, new CurrentUserServiceSupplier(context, action, enableOverlayResId, nonOverlayPackageResId), this); + mName = provider; mProxy = null; mRequest = ProviderRequest.EMPTY_REQUEST; @@ -249,6 +254,8 @@ public class ProxyLocationProvider extends AbstractLocationProvider implements String tagsStr = mBoundServiceInfo.getMetadata().getString(EXTRA_LOCATION_TAGS); if (!TextUtils.isEmpty(tagsStr)) { attributionTags = tagsStr.split(LOCATION_TAGS_SEPARATOR); + Log.i(TAG, mName + " provider loaded extra attribution tags: " + + Arrays.toString(attributionTags)); } } ArraySet extraAttributionTags = new ArraySet<>(attributionTags); diff --git a/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java b/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java index e718ba3b17cf1..631be380e2ebc 100644 --- a/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java +++ b/services/core/java/com/android/server/servicewatcher/ServiceWatcherImpl.java @@ -135,6 +135,7 @@ class ServiceWatcherImpl implements if (forceRebind || !Objects.equals(mServiceConnection.getBoundServiceInfo(), newBoundServiceInfo)) { + Log.i(TAG, "[" + mTag + "] chose new implementation " + newBoundServiceInfo); MyServiceConnection oldServiceConnection = mServiceConnection; MyServiceConnection newServiceConnection = new MyServiceConnection(newBoundServiceInfo); mServiceConnection = newServiceConnection; @@ -196,7 +197,9 @@ class ServiceWatcherImpl implements return; } - Log.i(TAG, "[" + mTag + "] binding to " + mBoundServiceInfo); + if (D) { + Log.d(TAG, "[" + mTag + "] binding to " + mBoundServiceInfo); + } Intent bindIntent = new Intent(mBoundServiceInfo.getAction()).setComponent( mBoundServiceInfo.getComponentName()); @@ -255,9 +258,7 @@ class ServiceWatcherImpl implements Preconditions.checkState(Looper.myLooper() == mHandler.getLooper()); Preconditions.checkState(mBinder == null); - if (D) { - Log.d(TAG, "[" + mTag + "] connected to " + component.toShortString()); - } + Log.i(TAG, "[" + mTag + "] connected to " + component.toShortString()); mBinder = binder; @@ -280,9 +281,7 @@ class ServiceWatcherImpl implements return; } - if (D) { - Log.d(TAG, "[" + mTag + "] disconnected from " + mBoundServiceInfo); - } + Log.i(TAG, "[" + mTag + "] disconnected from " + mBoundServiceInfo); mBinder = null; if (mServiceListener != null) { @@ -294,9 +293,11 @@ class ServiceWatcherImpl implements public final void onBindingDied(ComponentName component) { Preconditions.checkState(Looper.myLooper() == mHandler.getLooper()); - Log.i(TAG, "[" + mTag + "] " + mBoundServiceInfo + " died"); + Log.w(TAG, "[" + mTag + "] " + mBoundServiceInfo + " died"); - onServiceChanged(true); + // introduce a small delay to prevent spamming binding over and over, since the likely + // cause of a binding dying is some package event that may take time to recover from + mHandler.postDelayed(() -> onServiceChanged(true), 500); } @Override