Store flashlight status and broadcast it needed for flashlight slice.
Test: manual
Bug: 74913192
Change-Id: I54ead1727d08b113dec13e3f7c128895770e68f1
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightControllerImpl.java
index f0cfa2c..11fc408 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightControllerImpl.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.policy;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
@@ -24,6 +25,8 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
+import android.provider.Settings;
+import android.provider.Settings.Secure;
import android.text.TextUtils;
import android.util.Log;
@@ -46,6 +49,9 @@
private static final int DISPATCH_CHANGED = 1;
private static final int DISPATCH_AVAILABILITY_CHANGED = 2;
+ private static final String ACTION_FLASHLIGHT_CHANGED =
+ "com.android.settings.flashlight.action.FLASHLIGHT_CHANGED";
+
private final CameraManager mCameraManager;
private final Context mContext;
/** Call {@link #ensureHandler()} before using */
@@ -206,6 +212,9 @@
public void onTorchModeUnavailable(String cameraId) {
if (TextUtils.equals(cameraId, mCameraId)) {
setCameraAvailable(false);
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), Settings.Secure.FLASHLIGHT_AVAILABLE, 0);
+
}
}
@@ -214,6 +223,11 @@
if (TextUtils.equals(cameraId, mCameraId)) {
setCameraAvailable(true);
setTorchMode(enabled);
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), Settings.Secure.FLASHLIGHT_AVAILABLE, 1);
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), Secure.FLASHLIGHT_ENABLED, enabled ? 1 : 0);
+ mContext.sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED));
}
}