summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-05-13 18:31:42 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-05-13 18:31:42 +0000
commit0d3acf62ecf5b0e8ec1f6af0321e0831ced2372e (patch)
tree7374be23bec86b2371e1838498b7a898f00e4ec7
parent5bc29e371ce138892f3bca89edaeb7b81e913872 (diff)
parent007ff07c3426dddc85ede83b68317247edbc0b7d (diff)
Merge "Clear all notification, message mute states, and unread states when the car recovers from the suspension state." into qt-dev
-rw-r--r--packages/CarSystemUI/AndroidManifest.xml4
-rw-r--r--packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java49
-rw-r--r--packages/CarSystemUI/src/com/android/systemui/statusbar/car/PowerManagerHelper.java93
3 files changed, 130 insertions, 16 deletions
diff --git a/packages/CarSystemUI/AndroidManifest.xml b/packages/CarSystemUI/AndroidManifest.xml
index 4e8a3a3885a7..195d4fee5162 100644
--- a/packages/CarSystemUI/AndroidManifest.xml
+++ b/packages/CarSystemUI/AndroidManifest.xml
@@ -19,6 +19,6 @@
package="com.android.systemui"
android:sharedUserId="android.uid.systemui"
coreApp="true">
-
-
+ <!-- This permission is required to monitor car power state. -->
+ <uses-permission android:name="android.car.permission.CAR_POWER" />
</manifest>
diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
index febf8b801726..835cedf9cdd9 100644
--- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
+++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
@@ -25,6 +25,7 @@ import android.app.ActivityTaskManager;
import android.car.Car;
import android.car.drivingstate.CarDrivingStateEvent;
import android.car.drivingstate.CarUxRestrictionsManager;
+import android.car.hardware.power.CarPowerManager.CarPowerStateListener;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Rect;
@@ -121,8 +122,11 @@ public class CarStatusBar extends StatusBar implements
private boolean mDeviceIsProvisioned = true;
private HvacController mHvacController;
private DrivingStateHelper mDrivingStateHelper;
- private static FlingAnimationUtils sFlingAnimationUtils;
+ private PowerManagerHelper mPowerManagerHelper;
+ private FlingAnimationUtils mFlingAnimationUtils;
private SwitchToGuestTimer mSwitchToGuestTimer;
+ private NotificationDataManager mNotificationDataManager;
+ private NotificationClickHandlerFactory mNotificationClickHandlerFactory;
// The container for the notifications.
private CarNotificationView mNotificationView;
@@ -156,6 +160,20 @@ public class CarStatusBar extends StatusBar implements
// If notification shade is being swiped vertically to close.
private boolean mIsSwipingVerticallyToClose;
+ private final CarPowerStateListener mCarPowerStateListener =
+ (int state) -> {
+ // When the car powers on, clear all notifications and mute/unread states.
+ Log.d(TAG, "New car power state: " + state);
+ if (state == CarPowerStateListener.ON) {
+ if (mNotificationClickHandlerFactory != null) {
+ mNotificationClickHandlerFactory.clearAllNotifications();
+ }
+ if (mNotificationDataManager != null) {
+ mNotificationDataManager.clearAll();
+ }
+ }
+ };
+
@Override
public void start() {
// get the provisioned state before calling the parent class since it's that flow that
@@ -172,7 +190,7 @@ public class CarStatusBar extends StatusBar implements
R.integer.notification_settle_open_percentage);
mSettleClosePercentage = mContext.getResources().getInteger(
R.integer.notification_settle_close_percentage);
- sFlingAnimationUtils = new FlingAnimationUtils(mContext,
+ mFlingAnimationUtils = new FlingAnimationUtils(mContext,
FLING_ANIMATION_MAX_TIME, FLING_SPEED_UP_FACTOR);
createBatteryController();
@@ -204,6 +222,9 @@ public class CarStatusBar extends StatusBar implements
mDrivingStateHelper = new DrivingStateHelper(mContext, this::onDrivingStateChanged);
mDrivingStateHelper.connectToCarService();
+ mPowerManagerHelper = new PowerManagerHelper(mContext, mCarPowerStateListener);
+ mPowerManagerHelper.connectToCarService();
+
mSwitchToGuestTimer = new SwitchToGuestTimer(mContext);
}
@@ -308,7 +329,6 @@ public class CarStatusBar extends StatusBar implements
}
}
-
@Override
protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) {
super.makeStatusBarView(result);
@@ -407,7 +427,7 @@ public class CarStatusBar extends StatusBar implements
}
);
- NotificationClickHandlerFactory clickHandlerFactory = new NotificationClickHandlerFactory(
+ mNotificationClickHandlerFactory = new NotificationClickHandlerFactory(
mBarService,
launchResult -> {
if (launchResult == ActivityManager.START_TASK_TO_FRONT
@@ -422,26 +442,27 @@ public class CarStatusBar extends StatusBar implements
CarUxRestrictionManagerWrapper carUxRestrictionManagerWrapper =
new CarUxRestrictionManagerWrapper();
carUxRestrictionManagerWrapper.setCarUxRestrictionsManager(carUxRestrictionsManager);
- NotificationDataManager notificationDataManager = new NotificationDataManager();
- notificationDataManager.setOnUnseenCountUpdateListener(
+ mNotificationDataManager = new NotificationDataManager();
+ mNotificationDataManager.setOnUnseenCountUpdateListener(
() -> {
// TODO: Update Notification Icon based on unseen count
Log.d(TAG, "unseen count: " +
- notificationDataManager.getUnseenNotificationCount());
+ mNotificationDataManager.getUnseenNotificationCount());
});
CarHeadsUpNotificationManager carHeadsUpNotificationManager =
- new CarSystemUIHeadsUpNotificationManager(mContext, clickHandlerFactory,
- notificationDataManager);
+ new CarSystemUIHeadsUpNotificationManager(mContext,
+ mNotificationClickHandlerFactory, mNotificationDataManager);
+ mNotificationClickHandlerFactory.setNotificationDataManager(mNotificationDataManager);
carNotificationListener.registerAsSystemService(mContext, carUxRestrictionManagerWrapper,
- carHeadsUpNotificationManager, notificationDataManager);
+ carHeadsUpNotificationManager, mNotificationDataManager);
mNotificationView = mStatusBarWindow.findViewById(R.id.notification_view);
View glassPane = mStatusBarWindow.findViewById(R.id.glass_pane);
- mNotificationView.setClickHandlerFactory(clickHandlerFactory);
- mNotificationView.setNotificationDataManager(notificationDataManager);
+ mNotificationView.setClickHandlerFactory(mNotificationClickHandlerFactory);
+ mNotificationView.setNotificationDataManager(mNotificationDataManager);
// The glass pane is used to view touch events before passed to the notification list.
// This allows us to initialize gesture listeners and detect when to close the notifications
@@ -528,7 +549,7 @@ public class CarStatusBar extends StatusBar implements
PreprocessingManager.getInstance(mContext),
carNotificationListener,
carUxRestrictionManagerWrapper,
- notificationDataManager);
+ mNotificationDataManager);
mNotificationViewController.enable();
}
@@ -639,7 +660,7 @@ public class CarStatusBar extends StatusBar implements
}
}
});
- sFlingAnimationUtils.apply(animator, from, to, Math.abs(velocity));
+ mFlingAnimationUtils.apply(animator, from, to, Math.abs(velocity));
animator.start();
}
diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/PowerManagerHelper.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/PowerManagerHelper.java
new file mode 100644
index 000000000000..8de1439c3306
--- /dev/null
+++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/PowerManagerHelper.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.car;
+
+import android.annotation.NonNull;
+import android.car.Car;
+import android.car.CarNotConnectedException;
+import android.car.hardware.power.CarPowerManager;
+import android.car.hardware.power.CarPowerManager.CarPowerStateListener;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.util.Log;
+
+/**
+ * Helper class for connecting to the {@link CarPowerManager} and listening for power state changes.
+ */
+public class PowerManagerHelper {
+ public static final String TAG = "PowerManagerHelper";
+
+ private final Context mContext;
+ private final CarPowerStateListener mCarPowerStateListener;
+
+ private Car mCar;
+ private CarPowerManager mCarPowerManager;
+
+ private final ServiceConnection mCarConnectionListener =
+ new ServiceConnection() {
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ Log.d(TAG, "Car Service connected");
+ try {
+ mCarPowerManager = (CarPowerManager) mCar.getCarManager(Car.POWER_SERVICE);
+ if (mCarPowerManager != null) {
+ mCarPowerManager.setListener(mCarPowerStateListener);
+ } else {
+ Log.e(TAG, "CarPowerManager service not available");
+ }
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Car not connected", e);
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ destroyCarPowerManager();
+ }
+ };
+
+ PowerManagerHelper(Context context, @NonNull CarPowerStateListener listener) {
+ mContext = context;
+ mCarPowerStateListener = listener;
+ }
+
+ /**
+ * Connect to Car service.
+ */
+ void connectToCarService() {
+ mCar = Car.createCar(mContext, mCarConnectionListener);
+ if (mCar != null) {
+ mCar.connect();
+ }
+ }
+
+ /**
+ * Disconnects from Car service.
+ */
+ void disconnectFromCarService() {
+ if (mCar != null) {
+ mCar.disconnect();
+ }
+ }
+
+ private void destroyCarPowerManager() {
+ if (mCarPowerManager != null) {
+ mCarPowerManager.clearListener();
+ }
+ }
+}