diff options
author | Felipe Leme <felipeal@google.com> | 2019-04-18 14:02:09 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-04-18 14:02:09 -0700 |
commit | ab08d1de64690bc8d3162a6d79532f7364903b25 (patch) | |
tree | daacc6fe7433c53af85bf3d2c71f91d6b90f7fe3 /services/contentcapture/java | |
parent | 91a108b91e8afcbabba0b02e0890ef96b7ef41a0 (diff) | |
parent | 11c6dfd0af11f710e4ebd6f82a59a86a1b518dc1 (diff) |
Merge "Remove ContentCaptureServerSession when app died." into qt-dev am: 094b9acb0d
am: 11c6dfd0af
Change-Id: I4963ae27992e59b801c51304a181093d2a1b9735
Diffstat (limited to 'services/contentcapture/java')
2 files changed, 23 insertions, 2 deletions
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java index 564952697250..4f14b13071b3 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java @@ -313,7 +313,7 @@ final class ContentCapturePerUserService // Make sure service is bound, just in case the initial connection failed somehow mRemoteService.ensureBoundLocked(); - final ContentCaptureServerSession newSession = new ContentCaptureServerSession( + final ContentCaptureServerSession newSession = new ContentCaptureServerSession(mLock, activityToken, this, componentName, clientReceiver, taskId, displayId, sessionId, uid, flags); if (mMaster.verbose) { diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java index 1ad66d869eae..d38dfd409439 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java @@ -65,11 +65,14 @@ final class ContentCaptureServerSession { */ private final int mUid; - ContentCaptureServerSession(@NonNull IBinder activityToken, + private final Object mLock; + + ContentCaptureServerSession(@NonNull Object lock, @NonNull IBinder activityToken, @NonNull ContentCapturePerUserService service, @NonNull ComponentName appComponentName, @NonNull IResultReceiver sessionStateReceiver, int taskId, int displayId, int sessionId, int uid, int flags) { Preconditions.checkArgument(sessionId != NO_SESSION_ID); + mLock = lock; mActivityToken = activityToken; mService = service; mId = sessionId; @@ -77,6 +80,11 @@ final class ContentCaptureServerSession { mContentCaptureContext = new ContentCaptureContext(/* clientContext= */ null, appComponentName, taskId, displayId, flags); mSessionStateReceiver = sessionStateReceiver; + try { + sessionStateReceiver.asBinder().linkToDeath(() -> onClientDeath(), 0); + } catch (Exception e) { + Slog.w(TAG, "could not register DeathRecipient for " + activityToken); + } } /** @@ -182,6 +190,19 @@ final class ContentCaptureServerSession { /* binder= */ null); } + /** + * Called when the session client binder object died - typically when its process was killed + * and the activity was not properly destroyed. + */ + private void onClientDeath() { + if (mService.isVerbose()) { + Slog.v(TAG, "onClientDeath(" + mActivityToken + "): removing session " + mId); + } + synchronized (mLock) { + removeSelfLocked(/* notifyRemoteService= */ true); + } + } + @GuardedBy("mLock") public void dumpLocked(@NonNull String prefix, @NonNull PrintWriter pw) { pw.print(prefix); pw.print("id: "); pw.print(mId); pw.println(); |