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 android.companion.virtual.sensor; 18 19 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 23 import java.time.Duration; 24 25 /** 26 * Interface for notifying the virtual device owner about whether and how sensor events should be 27 * injected. 28 * 29 * <p>This callback can be used for controlling the sensor event injection - e.g. if the sensor is 30 * not enabled, then no events should be injected. Similarly, the rate and delay of the injected 31 * events that the registered listeners expect are specified here. 32 * 33 * <p>The callback is tied to the VirtualDevice's lifetime as the virtual sensors are created when 34 * the device is created and destroyed when the device is destroyed. 35 * 36 * @hide 37 */ 38 @SystemApi 39 public interface VirtualSensorCallback { 40 /** 41 * Called when the requested sensor event injection parameters have changed. 42 * 43 * <p>This is effectively called when the registered listeners to a virtual sensor have changed. 44 * The events for the corresponding sensor should be sent via {@link VirtualSensor#sendEvent}. 45 * 46 * @param sensor The sensor whose requested injection parameters have changed. 47 * @param enabled Whether the sensor is enabled. True if any listeners are currently registered, 48 * and false otherwise. 49 * @param samplingPeriod The requested sampling period of the sensor. 50 * @param batchReportLatency The requested maximum time interval between the delivery of two 51 * batches of sensor events. 52 */ onConfigurationChanged(@onNull VirtualSensor sensor, boolean enabled, @NonNull Duration samplingPeriod, @NonNull Duration batchReportLatency)53 void onConfigurationChanged(@NonNull VirtualSensor sensor, boolean enabled, 54 @NonNull Duration samplingPeriod, @NonNull Duration batchReportLatency); 55 } 56