Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 17 | package com.android.server.contentcapture; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 18 | |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 19 | import static android.service.contentcapture.ContentCaptureService.setClientState; |
| 20 | |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 21 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 22 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 23 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
| 24 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 25 | import android.Manifest; |
| 26 | import android.annotation.NonNull; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 27 | import android.annotation.UserIdInt; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 28 | import android.app.AppGlobals; |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 29 | import android.app.assist.AssistContent; |
| 30 | import android.app.assist.AssistStructure; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.pm.PackageManager.NameNotFoundException; |
| 34 | import android.content.pm.ServiceInfo; |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 36 | import android.os.IBinder; |
| 37 | import android.os.RemoteException; |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 38 | import android.service.contentcapture.ContentCaptureService; |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 39 | import android.service.contentcapture.SnapshotData; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 40 | import android.util.ArrayMap; |
| 41 | import android.util.Slog; |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 42 | import android.view.contentcapture.ContentCaptureSession; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 43 | |
| 44 | import com.android.internal.annotations.GuardedBy; |
| 45 | import com.android.internal.os.IResultReceiver; |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 46 | import com.android.server.contentcapture.RemoteContentCaptureService.ContentCaptureServiceCallbacks; |
Felipe Leme | 1e3de57 | 2018-12-05 15:44:17 -0800 | [diff] [blame] | 47 | import com.android.server.infra.AbstractPerUserSystemService; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 48 | |
| 49 | import java.io.PrintWriter; |
Felipe Leme | 5933efb | 2018-11-29 16:08:49 -0800 | [diff] [blame] | 50 | import java.util.ArrayList; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 53 | * Per-user instance of {@link ContentCaptureManagerService}. |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 54 | */ |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 55 | final class ContentCapturePerUserService |
| 56 | extends |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 57 | AbstractPerUserSystemService<ContentCapturePerUserService, ContentCaptureManagerService> |
| 58 | implements ContentCaptureServiceCallbacks { |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 59 | |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 60 | private static final String TAG = ContentCaptureManagerService.class.getSimpleName(); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 61 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 62 | @GuardedBy("mLock") |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 63 | private final ArrayMap<String, ContentCaptureServerSession> mSessions = |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 64 | new ArrayMap<>(); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 65 | |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 66 | /** |
| 67 | * Reference to the remote service. |
| 68 | * |
| 69 | * <p>It's set in the constructor, but it's also updated when the service's updated in the |
| 70 | * master's cache (for example, because a temporary service was set). |
| 71 | */ |
| 72 | @GuardedBy("mLock") |
| 73 | private RemoteContentCaptureService mRemoteService; |
| 74 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 75 | // TODO(b/111276913): add mechanism to prune stale sessions, similar to Autofill's |
| 76 | |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 77 | ContentCapturePerUserService(@NonNull ContentCaptureManagerService master, |
| 78 | @NonNull Object lock, boolean disabled, @UserIdInt int userId) { |
Felipe Leme | c28711c | 2018-12-20 11:17:02 -0800 | [diff] [blame] | 79 | super(master, lock, userId); |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 80 | |
| 81 | updateRemoteServiceLocked(disabled); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Updates the reference to the remote service. |
| 86 | */ |
| 87 | private void updateRemoteServiceLocked(boolean disabled) { |
| 88 | if (mRemoteService != null) { |
| 89 | if (mMaster.debug) Slog.d(TAG, "updateRemoteService(): destroying old remote service"); |
| 90 | mRemoteService.destroy(); |
| 91 | mRemoteService = null; |
| 92 | } |
| 93 | |
| 94 | // Updates the component name |
| 95 | final ComponentName serviceComponentName = updateServiceInfoLocked(); |
| 96 | |
| 97 | if (serviceComponentName == null) { |
| 98 | Slog.w(TAG, "updateRemoteService(): no service componennt name"); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | if (!disabled) { |
| 103 | mRemoteService = new RemoteContentCaptureService( |
| 104 | mMaster.getContext(), |
| 105 | ContentCaptureService.SERVICE_INTERFACE, serviceComponentName, mUserId, this, |
| 106 | mMaster.isBindInstantServiceAllowed(), mMaster.verbose); |
| 107 | } |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override // from PerUserSystemService |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 111 | protected ServiceInfo newServiceInfoLocked(@NonNull ComponentName serviceComponent) |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 112 | throws NameNotFoundException { |
| 113 | |
Felipe Leme | 658c8e4 | 2018-11-30 12:49:45 -0800 | [diff] [blame] | 114 | int flags = PackageManager.GET_META_DATA; |
| 115 | final boolean isTemp = isTemporaryServiceSetLocked(); |
| 116 | if (!isTemp) { |
| 117 | flags |= PackageManager.MATCH_SYSTEM_ONLY; |
| 118 | } |
| 119 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 120 | ServiceInfo si; |
| 121 | try { |
Felipe Leme | 658c8e4 | 2018-11-30 12:49:45 -0800 | [diff] [blame] | 122 | si = AppGlobals.getPackageManager().getServiceInfo(serviceComponent, flags, mUserId); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 123 | } catch (RemoteException e) { |
| 124 | Slog.w(TAG, "Could not get service for " + serviceComponent + ": " + e); |
| 125 | return null; |
| 126 | } |
Felipe Leme | 658c8e4 | 2018-11-30 12:49:45 -0800 | [diff] [blame] | 127 | if (si == null) { |
| 128 | Slog.w(TAG, "Could not get serviceInfo for " + (isTemp ? " (temp)" : "(default system)") |
| 129 | + " " + serviceComponent.flattenToShortString()); |
| 130 | return null; |
| 131 | } |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 132 | if (!Manifest.permission.BIND_CONTENT_CAPTURE_SERVICE.equals(si.permission)) { |
| 133 | Slog.w(TAG, "ContentCaptureService from '" + si.packageName |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 134 | + "' does not require permission " |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 135 | + Manifest.permission.BIND_CONTENT_CAPTURE_SERVICE); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 136 | throw new SecurityException("Service does not require permission " |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 137 | + Manifest.permission.BIND_CONTENT_CAPTURE_SERVICE); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 138 | } |
| 139 | return si; |
| 140 | } |
| 141 | |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 142 | @Override // from PerUserSystemService |
| 143 | @GuardedBy("mLock") |
| 144 | protected boolean updateLocked(boolean disabled) { |
| 145 | destroyLocked(); |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 146 | final boolean disabledStateChanged = super.updateLocked(disabled); |
| 147 | updateRemoteServiceLocked(disabled); |
| 148 | return disabledStateChanged; |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 151 | @Override // from ContentCaptureServiceCallbacks |
| 152 | public void onServiceDied(@NonNull RemoteContentCaptureService service) { |
| 153 | if (mMaster.debug) Slog.d(TAG, "remote service died: " + service); |
| 154 | synchronized (mLock) { |
| 155 | removeSelfFromCacheLocked(); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // TODO(b/119613670): log metrics |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 160 | @GuardedBy("mLock") |
| 161 | public void startSessionLocked(@NonNull IBinder activityToken, |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 162 | @NonNull ComponentName componentName, int taskId, int displayId, |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 163 | @NonNull String sessionId, int uid, int flags, |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 164 | @NonNull IResultReceiver clientReceiver) { |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 165 | if (!isEnabledLocked()) { |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 166 | setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED, /* binder=*/ null); |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 167 | return; |
| 168 | } |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 169 | final ComponentName serviceComponentName = getServiceComponentName(); |
| 170 | if (serviceComponentName == null) { |
| 171 | // TODO(b/111276913): this happens when the system service is starting, we should |
| 172 | // probably handle it in a more elegant way (like waiting for boot_complete or |
| 173 | // something like that |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 174 | if (mMaster.debug) { |
| 175 | Slog.d(TAG, "startSession(" + activityToken + "): hold your horses"); |
| 176 | } |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 177 | return; |
| 178 | } |
| 179 | |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 180 | final ContentCaptureServerSession existingSession = mSessions.get(sessionId); |
| 181 | if (existingSession != null) { |
| 182 | Slog.w(TAG, "startSession(id=" + existingSession + ", token=" + activityToken |
| 183 | + ": ignoring because it already exists for " + existingSession.mActivityToken); |
| 184 | setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED_DUPLICATED_ID, |
| 185 | /* binder=*/ null); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 189 | if (mRemoteService == null) { |
| 190 | updateRemoteServiceLocked(/* disabled= */ false); // already checked for isEnabled |
| 191 | } |
| 192 | |
| 193 | if (mRemoteService == null) { |
| 194 | // TODO(b/119613670): log metrics |
| 195 | Slog.w(TAG, "startSession(id=" + existingSession + ", token=" + activityToken |
| 196 | + ": ignoring because service is not set"); |
| 197 | // TODO(b/111276913): use a new disabled state? |
| 198 | setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED, |
| 199 | /* binder=*/ null); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | final ContentCaptureServerSession newSession = new ContentCaptureServerSession( |
| 204 | activityToken, this, mRemoteService, componentName, taskId, |
| 205 | displayId, sessionId, uid, flags); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 206 | if (mMaster.verbose) { |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 207 | Slog.v(TAG, "startSession(): new session for " |
| 208 | + ComponentName.flattenToShortString(componentName) + " and id " + sessionId); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 209 | } |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 210 | mSessions.put(sessionId, newSession); |
| 211 | newSession.notifySessionStartedLocked(clientReceiver); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 214 | // TODO(b/119613670): log metrics |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 215 | @GuardedBy("mLock") |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 216 | public void finishSessionLocked(@NonNull String sessionId) { |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 217 | if (!isEnabledLocked()) { |
| 218 | return; |
| 219 | } |
| 220 | |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 221 | final ContentCaptureServerSession session = mSessions.get(sessionId); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 222 | if (session == null) { |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 223 | if (mMaster.debug) { |
| 224 | Slog.d(TAG, "finishSession(): no session with id" + sessionId); |
| 225 | } |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 226 | return; |
| 227 | } |
Felipe Leme | b9687849 | 2018-12-17 12:22:29 -0800 | [diff] [blame] | 228 | if (mMaster.verbose) Slog.v(TAG, "finishSession(): id=" + sessionId); |
| 229 | session.removeSelfLocked(/* notifyRemoteService= */ true); |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @GuardedBy("mLock") |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 233 | public boolean sendActivityAssistDataLocked(@NonNull IBinder activityToken, |
| 234 | @NonNull Bundle data) { |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 235 | final String id = getSessionId(activityToken); |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 236 | if (id != null) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 237 | final ContentCaptureServerSession session = mSessions.get(id); |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 238 | final Bundle assistData = data.getBundle(ASSIST_KEY_DATA); |
| 239 | final AssistStructure assistStructure = data.getParcelable(ASSIST_KEY_STRUCTURE); |
| 240 | final AssistContent assistContent = data.getParcelable(ASSIST_KEY_CONTENT); |
| 241 | final SnapshotData snapshotData = new SnapshotData(assistData, |
| 242 | assistStructure, assistContent); |
| 243 | session.sendActivitySnapshotLocked(snapshotData); |
| 244 | return true; |
| 245 | } else { |
| 246 | Slog.e(TAG, "Failed to notify activity assist data for activity: " + activityToken); |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | @GuardedBy("mLock") |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 252 | public void removeSessionLocked(@NonNull String sessionId) { |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 253 | mSessions.remove(sessionId); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Felipe Leme | 927fbf0 | 2018-11-12 17:27:23 -0800 | [diff] [blame] | 256 | @GuardedBy("mLock") |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 257 | public boolean isContentCaptureServiceForUserLocked(int uid) { |
Felipe Leme | 927fbf0 | 2018-11-12 17:27:23 -0800 | [diff] [blame] | 258 | return uid == getServiceUidLocked(); |
| 259 | } |
| 260 | |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 261 | @GuardedBy("mLock") |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 262 | private ContentCaptureServerSession getSession(@NonNull IBinder activityToken) { |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 263 | for (int i = 0; i < mSessions.size(); i++) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 264 | final ContentCaptureServerSession session = mSessions.valueAt(i); |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 265 | if (session.mActivityToken.equals(activityToken)) { |
| 266 | return session; |
| 267 | } |
| 268 | } |
| 269 | return null; |
| 270 | } |
| 271 | |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 272 | /** |
| 273 | * Destroys the service and all state associated with it. |
| 274 | * |
| 275 | * <p>Called when the service was disabled (for example, if the settings change). |
| 276 | */ |
| 277 | @GuardedBy("mLock") |
| 278 | public void destroyLocked() { |
| 279 | if (mMaster.debug) Slog.d(TAG, "destroyLocked()"); |
Felipe Leme | 5933efb | 2018-11-29 16:08:49 -0800 | [diff] [blame] | 280 | destroySessionsLocked(); |
| 281 | } |
| 282 | |
| 283 | @GuardedBy("mLock") |
| 284 | void destroySessionsLocked() { |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 285 | final int numSessions = mSessions.size(); |
| 286 | for (int i = 0; i < numSessions; i++) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 287 | final ContentCaptureServerSession session = mSessions.valueAt(i); |
Felipe Leme | 8e2e341 | 2018-11-14 10:39:29 -0800 | [diff] [blame] | 288 | session.destroyLocked(true); |
| 289 | } |
| 290 | mSessions.clear(); |
| 291 | } |
| 292 | |
Felipe Leme | 5933efb | 2018-11-29 16:08:49 -0800 | [diff] [blame] | 293 | @GuardedBy("mLock") |
| 294 | void listSessionsLocked(ArrayList<String> output) { |
| 295 | final int numSessions = mSessions.size(); |
| 296 | for (int i = 0; i < numSessions; i++) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 297 | final ContentCaptureServerSession session = mSessions.valueAt(i); |
Felipe Leme | 5933efb | 2018-11-29 16:08:49 -0800 | [diff] [blame] | 298 | output.add(session.toShortString()); |
| 299 | } |
| 300 | } |
| 301 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 302 | @Override |
| 303 | protected void dumpLocked(String prefix, PrintWriter pw) { |
| 304 | super.dumpLocked(prefix, pw); |
Felipe Leme | 50b33dc | 2018-12-20 16:01:39 -0800 | [diff] [blame^] | 305 | |
| 306 | final String prefix2 = prefix + " "; |
| 307 | if (mRemoteService != null) { |
| 308 | pw.print(prefix); pw.println("remote service:"); |
| 309 | mRemoteService.dump(prefix2, pw); |
| 310 | } |
| 311 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 312 | if (mSessions.isEmpty()) { |
| 313 | pw.print(prefix); pw.println("no sessions"); |
| 314 | } else { |
| 315 | final int size = mSessions.size(); |
| 316 | pw.print(prefix); pw.print("number sessions: "); pw.println(size); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 317 | for (int i = 0; i < size; i++) { |
| 318 | pw.print(prefix); pw.print("session@"); pw.println(i); |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 319 | final ContentCaptureServerSession session = mSessions.valueAt(i); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 320 | session.dumpLocked(prefix2, pw); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 325 | /** |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 326 | * Returns the session id associated with the given activity. |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 327 | */ |
| 328 | @GuardedBy("mLock") |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 329 | private String getSessionId(@NonNull IBinder activityToken) { |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 330 | for (int i = 0; i < mSessions.size(); i++) { |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 331 | ContentCaptureServerSession session = mSessions.valueAt(i); |
Winson Chung | fbbb158 | 2018-11-13 16:09:01 -0800 | [diff] [blame] | 332 | if (session.isActivitySession(activityToken)) { |
| 333 | return mSessions.keyAt(i); |
| 334 | } |
| 335 | } |
| 336 | return null; |
| 337 | } |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 338 | } |