Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18f2caa2 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Clean up manager record logs for binder exceptions

- Add information about the failing target operations. Such as package
  name, user id, and manager id.
- Prevents the logging of the stacktrace. The operation name is
  sufficient.

Bug: b/360129098
Test: atest CtsMediaBetterTogetherTestCases
Test: Manually by testing output switcher on different media apps.
Flag: EXEMPT loggging only change
Change-Id: I2fbec8676390918ef49fd20e50b88289c88e996c
parent dd1ce567
Loading
Loading
Loading
Loading
+24 −25
Original line number Diff line number Diff line
@@ -1112,19 +1112,12 @@ class MediaRouter2ServiceImpl {
                continue;
            }

            Log.w(
                    TAG,
                    TextUtils.formatSimple(
                            "Revoking access to manager record id: %d, package: %s, userId:"
                                    + " %d",
                            manager.mManagerId, manager.mOwnerPackageName, userRecord.mUserId));

            Slog.w(TAG, "Revoking access for " + manager.getDebugString());
            unregisterManagerLocked(manager.mManager, /* died */ false);

            try {
                manager.mManager.invalidateInstance();
            } catch (RemoteException ex) {
                Slog.w(TAG, "Failed to notify manager= " + manager + " of permission revocation.");
                manager.logRemoteException("invalidateInstance", ex);
            }
        }
    }
@@ -2428,10 +2421,7 @@ class MediaRouter2ServiceImpl {
            try {
                mManager.notifyRequestFailed(requestId, reason);
            } catch (RemoteException ex) {
                Slog.w(
                        TAG,
                        "Failed to notify manager of the request failure. Manager probably died.",
                        ex);
                logRemoteException("notifyRequestFailed", ex);
            }
        }

@@ -2444,7 +2434,7 @@ class MediaRouter2ServiceImpl {
            try {
                mManager.notifyRoutesUpdated(routes);
            } catch (RemoteException ex) {
                Slog.w(TAG, "Failed to notify routes. Manager probably died.", ex);
                logRemoteException("notifyRoutesUpdated", ex);
            }
        }

@@ -2457,10 +2447,7 @@ class MediaRouter2ServiceImpl {
            try {
                mManager.notifySessionUpdated(sessionInfo);
            } catch (RemoteException ex) {
                Slog.w(
                        TAG,
                        "notifySessionUpdatedToManagers: Failed to notify. Manager probably died.",
                        ex);
                logRemoteException("notifySessionUpdated", ex);
            }
        }

@@ -2473,13 +2460,18 @@ class MediaRouter2ServiceImpl {
            try {
                mManager.notifySessionReleased(sessionInfo);
            } catch (RemoteException ex) {
                Slog.w(
                        TAG,
                        "notifySessionReleasedToManagers: Failed to notify. Manager probably died.",
                        ex);
                logRemoteException("notifySessionReleased", ex);
            }
        }

        private void logRemoteException(String operation, RemoteException exception) {
            String message =
                    TextUtils.formatSimple(
                            "%s failed for %s due to %s",
                            operation, getDebugString(), exception.toString());
            Slog.w(TAG, message);
        }

        private void updateScanningState(@ScanningState int scanningState) {
            if (mScanningState == scanningState) {
                return;
@@ -2492,9 +2484,16 @@ class MediaRouter2ServiceImpl {
                            UserHandler::updateDiscoveryPreferenceOnHandler, mUserRecord.mHandler));
        }

        @Override
        public String toString() {
            return "Manager " + mOwnerPackageName + " (pid " + mOwnerPid + ")";
        /** Returns a human readable representation of this manager record for logging purposes. */
        public String getDebugString() {
            return TextUtils.formatSimple(
                    "Manager %s (id=%d,pid=%d,userId=%d,uid=%d,targetPkg=%s)",
                    mOwnerPackageName,
                    mManagerId,
                    mOwnerPid,
                    mUserRecord.mUserId,
                    mOwnerUid,
                    mTargetPackageName);
        }
    }