1 /* 2 * Copyright (C) 2021 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.systemui.statusbar.policy; 18 19 import static com.android.systemui.statusbar.policy.DevicePostureController.Callback; 20 21 import android.annotation.IntDef; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** 27 * Listener for device posture changes. This can be used to query the current posture, or register 28 * for events when it changes. 29 */ 30 public interface DevicePostureController extends CallbackController<Callback> { 31 @IntDef(prefix = {"DEVICE_POSTURE_"}, value = { 32 DEVICE_POSTURE_UNKNOWN, 33 DEVICE_POSTURE_CLOSED, 34 DEVICE_POSTURE_HALF_OPENED, 35 DEVICE_POSTURE_OPENED, 36 DEVICE_POSTURE_FLIPPED 37 }) 38 @Retention(RetentionPolicy.SOURCE) 39 @interface DevicePostureInt {} 40 41 // NOTE: These constants **must** match those defined for Jetpack Sidecar. This is because we 42 // use the Device State -> Jetpack Posture map in DevicePostureControllerImpl to translate 43 // between the two. 44 int DEVICE_POSTURE_UNKNOWN = 0; 45 int DEVICE_POSTURE_CLOSED = 1; 46 int DEVICE_POSTURE_HALF_OPENED = 2; 47 int DEVICE_POSTURE_OPENED = 3; 48 int DEVICE_POSTURE_FLIPPED = 4; 49 int SUPPORTED_POSTURES_SIZE = DEVICE_POSTURE_FLIPPED + 1; 50 51 /** Return the current device posture. */ getDevicePosture()52 @DevicePostureInt int getDevicePosture(); 53 54 /** 55 * String representation of DevicePostureInt. 56 */ devicePostureToString(@evicePostureInt int posture)57 static String devicePostureToString(@DevicePostureInt int posture) { 58 switch (posture) { 59 case DEVICE_POSTURE_CLOSED: 60 return "DEVICE_POSTURE_CLOSED"; 61 case DEVICE_POSTURE_HALF_OPENED: 62 return "DEVICE_POSTURE_HALF_OPENED"; 63 case DEVICE_POSTURE_OPENED: 64 return "DEVICE_POSTURE_OPENED"; 65 case DEVICE_POSTURE_FLIPPED: 66 return "DEVICE_POSTURE_FLIPPED"; 67 case DEVICE_POSTURE_UNKNOWN: 68 return "DEVICE_POSTURE_UNKNOWN"; 69 default: 70 return "UNSUPPORTED POSTURE posture=" + posture; 71 } 72 } 73 74 /** Callback to be notified about device posture changes. */ 75 interface Callback { 76 /** 77 * Called when the posture changes. If there are multiple active displays ("concurrent"), 78 * this will report the physical posture of the device (also known as the base device 79 * state). 80 */ onPostureChanged(@evicePostureInt int posture)81 void onPostureChanged(@DevicePostureInt int posture); 82 } 83 } 84