diff options
| author | 2017-09-20 13:55:28 -0700 | |
|---|---|---|
| committer | 2017-09-22 09:23:04 -0700 | |
| commit | 9d41449ff4efac108268815f67dd35797319e78c (patch) | |
| tree | 5265122037d18b3a21e3c5029fbf0072e5487e7f | |
| parent | 66f2d565561cb3ac8cb9c7d5b50560856b35476a (diff) | |
Add metrics (and moar logging) for when a service disables itself.
Test: adb shell logcat -b events | grep sysui_
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases
Bug: 65376559
Bug: 65856399
Change-Id: Ieb54bb0a58ecd51da663170a12817d33188ac9f0
3 files changed, 36 insertions, 5 deletions
diff --git a/core/java/android/service/autofill/AutofillServiceInfo.java b/core/java/android/service/autofill/AutofillServiceInfo.java index e64eb0d62992..1a9afccdabe2 100644 --- a/core/java/android/service/autofill/AutofillServiceInfo.java +++ b/core/java/android/service/autofill/AutofillServiceInfo.java @@ -29,11 +29,12 @@ import android.os.RemoteException; import android.util.AttributeSet; import android.util.Log; import android.util.Xml; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; import com.android.internal.R; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; /** @@ -147,4 +148,9 @@ public final class AutofillServiceInfo { public String getSettingsActivity() { return mSettingsActivity; } + + @Override + public String toString() { + return mServiceInfo == null ? "null" : mServiceInfo.toString(); + } } diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto index f15749f61047..ccb3d595532f 100644 --- a/proto/src/metrics_constants.proto +++ b/proto/src/metrics_constants.proto @@ -4527,6 +4527,11 @@ message MetricsEvent { // Type TYPE_FAILURE: An invalid opperation was reported by the app's AutofillManager AUTOFILL_PENDING_SAVE_UI_OPERATION = 1134; + // Autofill service called API that disables itself + // Package: Package of the autofill service + // OS: O MR + AUTOFILL_SERVICE_DISABLED_SELF = 1135; + // ---- End O-MR1 Constants, all O-MR1 constants go above this line ---- // Add new aosp constants above this line. diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index e28e1c9e6a90..c9a3d73b9d64 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -35,6 +35,7 @@ import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.metrics.LogMaker; import android.os.AsyncTask; import android.os.Binder; import android.os.Bundle; @@ -63,6 +64,8 @@ import android.view.autofill.IAutoFillManagerClient; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.os.HandlerCaller; import com.android.server.autofill.ui.AutoFillUI; @@ -89,6 +92,7 @@ final class AutofillManagerServiceImpl { private final Context mContext; private final Object mLock; private final AutoFillUI mUi; + private final MetricsLogger mMetricsLogger = new MetricsLogger(); private RemoteCallbackList<IAutoFillManagerClient> mClients; private AutofillServiceInfo mInfo; @@ -218,8 +222,10 @@ final class AutofillManagerServiceImpl { if (serviceInfo != null) { mInfo = new AutofillServiceInfo(mContext.getPackageManager(), serviceComponent, mUserId); + if (sDebug) Slog.d(TAG, "Set component for user " + mUserId + " as " + mInfo); } else { mInfo = null; + if (sDebug) Slog.d(TAG, "Reset component for user " + mUserId); } final boolean isEnabled = isEnabled(); if (wasEnabled != isEnabled) { @@ -345,17 +351,31 @@ final class AutofillManagerServiceImpl { } void disableOwnedAutofillServicesLocked(int uid) { - if (mInfo == null || mInfo.getServiceInfo().applicationInfo.uid != uid) { + Slog.i(TAG, "disableOwnedServices(" + uid + "): " + mInfo); + if (mInfo == null) return; + + final ServiceInfo serviceInfo = mInfo.getServiceInfo(); + if (serviceInfo.applicationInfo.uid != uid) { + Slog.w(TAG, "disableOwnedServices(): ignored when called by UID " + uid + + " instead of " + serviceInfo.applicationInfo.uid + + " for service " + mInfo); return; } + + final long identity = Binder.clearCallingIdentity(); try { final String autoFillService = getComponentNameFromSettings(); - if (mInfo.getServiceInfo().getComponentName().equals( - ComponentName.unflattenFromString(autoFillService))) { + final ComponentName componentName = serviceInfo.getComponentName(); + if (componentName.equals(ComponentName.unflattenFromString(autoFillService))) { + mMetricsLogger.action(MetricsEvent.AUTOFILL_SERVICE_DISABLED_SELF, + componentName.getPackageName()); Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.AUTOFILL_SERVICE, null, mUserId); destroySessionsLocked(); + } else { + Slog.w(TAG, "disableOwnedServices(): ignored because current service (" + + serviceInfo + ") does not match Settings (" + autoFillService + ")"); } } finally { Binder.restoreCallingIdentity(identity); |