1 /* 2 * Copyright (C) 2023 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 17 package com.android.server.contentprotection; 18 19 import android.annotation.NonNull; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.ParceledListSlice; 24 import android.service.contentcapture.ContentCaptureService; 25 import android.service.contentcapture.IContentProtectionAllowlistCallback; 26 import android.service.contentcapture.IContentProtectionService; 27 import android.util.Slog; 28 import android.view.contentcapture.ContentCaptureEvent; 29 30 import com.android.internal.infra.ServiceConnector; 31 32 /** 33 * Connector for the remote content protection service. 34 * 35 * @hide 36 */ 37 public class RemoteContentProtectionService 38 extends ServiceConnector.Impl<IContentProtectionService> { 39 40 private static final String TAG = RemoteContentProtectionService.class.getSimpleName(); 41 42 @NonNull private final ComponentName mComponentName; 43 44 private final long mAutoDisconnectTimeoutMs; 45 RemoteContentProtectionService( @onNull Context context, @NonNull ComponentName componentName, int userId, boolean bindAllowInstant, long autoDisconnectTimeoutMs)46 public RemoteContentProtectionService( 47 @NonNull Context context, 48 @NonNull ComponentName componentName, 49 int userId, 50 boolean bindAllowInstant, 51 long autoDisconnectTimeoutMs) { 52 super( 53 context, 54 new Intent(ContentCaptureService.PROTECTION_SERVICE_INTERFACE) 55 .setComponent(componentName), 56 bindAllowInstant ? Context.BIND_ALLOW_INSTANT : 0, 57 userId, 58 IContentProtectionService.Stub::asInterface); 59 mComponentName = componentName; 60 mAutoDisconnectTimeoutMs = autoDisconnectTimeoutMs; 61 } 62 63 @Override // from ServiceConnector.Impl getAutoDisconnectTimeoutMs()64 protected long getAutoDisconnectTimeoutMs() { 65 return mAutoDisconnectTimeoutMs; 66 } 67 68 @Override // from ServiceConnector.Impl onServiceConnectionStatusChanged( @onNull IContentProtectionService service, boolean isConnected)69 protected void onServiceConnectionStatusChanged( 70 @NonNull IContentProtectionService service, boolean isConnected) { 71 Slog.i( 72 TAG, 73 "Connection status for: " 74 + mComponentName 75 + " changed to: " 76 + (isConnected ? "connected" : "disconnected")); 77 } 78 79 /** Calls the remote service when login is detected. */ onLoginDetected(@onNull ParceledListSlice<ContentCaptureEvent> events)80 public void onLoginDetected(@NonNull ParceledListSlice<ContentCaptureEvent> events) { 81 run(service -> service.onLoginDetected(events)); 82 } 83 84 /** Calls the remote service with a request to update allowlist. */ onUpdateAllowlistRequest(@onNull IContentProtectionAllowlistCallback callback)85 public void onUpdateAllowlistRequest(@NonNull IContentProtectionAllowlistCallback callback) { 86 run(service -> service.onUpdateAllowlistRequest(callback.asBinder())); 87 } 88 } 89