universal7885: CameraLightSensor: Set notification to low priority

Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
roynatech2544 2021-12-01 17:16:29 +09:00
commit 4584ec21f2
No known key found for this signature in database
GPG key ID: 9675C32163D88D30
4 changed files with 34 additions and 53 deletions

View file

@ -26,7 +26,7 @@ import androidx.core.content.ContextCompat
open class CameraLightSensorService : Service() { open class CameraLightSensorService : Service() {
var screenStateFilter: IntentFilter? = null var screenStateFilter: IntentFilter? = null
private var mContext: Context? = null lateinit var mContext: Context
private var mRegistered = false private var mRegistered = false
var destroy = false var destroy = false
private var cameraDevice: CameraDevice? = null private var cameraDevice: CameraDevice? = null
@ -41,15 +41,15 @@ open class CameraLightSensorService : Service() {
@Volatile @Volatile
private var mLock = false private var mLock = false
private var mThreadRunning = false private var mThreadRunning = false
private fun PushNotification(): Notification { private fun pushNotification(): Notification {
val nm = mContext!!.getSystemService(NOTIFICATION_SERVICE) as NotificationManager val nm = mContext.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val channel = NotificationChannel( val channel = NotificationChannel(
mContext!!.basePackageName, "CameraLightSensor", mContext.basePackageName, "Useless Notification",
NotificationManager.IMPORTANCE_LOW NotificationManager.IMPORTANCE_NONE
) )
channel.isBlockable = true channel.isBlockable = true
nm.createNotificationChannel(channel) nm.createNotificationChannel(channel)
val builder = NotificationCompat.Builder(mContext!!, mContext!!.basePackageName) val builder = NotificationCompat.Builder(mContext, mContext.basePackageName)
val notificationIntent = Intent(mContext, CameraLightSensorService::class.java) val notificationIntent = Intent(mContext, CameraLightSensorService::class.java)
val contentIntent = PendingIntent.getActivity( val contentIntent = PendingIntent.getActivity(
mContext, 50, mContext, 50,
@ -59,7 +59,7 @@ open class CameraLightSensorService : Service() {
builder.setContentIntent(contentIntent) builder.setContentIntent(contentIntent)
builder.setSmallIcon(R.drawable.ic_brightness) builder.setSmallIcon(R.drawable.ic_brightness)
builder.setContentTitle("Camera Light Sensor Service") builder.setContentTitle("Camera Light Sensor Service")
builder.setChannelId(mContext!!.basePackageName) builder.setChannelId(mContext.basePackageName)
return builder.build() return builder.build()
} }
@ -245,8 +245,9 @@ open class CameraLightSensorService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
mContext = applicationContext mContext = applicationContext
startForeground(50, PushNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA) @Suppress("SameParameterValue")
BatteryOptimization(mContext) startForeground(50, pushNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA)
batteryOptimization(mContext)
mRegistered = false mRegistered = false
screenStateFilter = IntentFilter(Intent.ACTION_SCREEN_ON) screenStateFilter = IntentFilter(Intent.ACTION_SCREEN_ON)
screenStateFilter!!.addAction(Intent.ACTION_SCREEN_OFF) screenStateFilter!!.addAction(Intent.ACTION_SCREEN_OFF)
@ -265,14 +266,14 @@ open class CameraLightSensorService : Service() {
if (DEBUG) Log.d(TAG, "onStartCommand flags $flags startId $startId") if (DEBUG) Log.d(TAG, "onStartCommand flags $flags startId $startId")
destroy = false destroy = false
avail = true avail = true
startForeground(50, PushNotification()) startForeground(50, pushNotification())
return START_STICKY return START_STICKY
} }
override fun onCreate() { override fun onCreate() {
if (DEBUG) Log.d(TAG, "onCreate service") if (DEBUG) Log.d(TAG, "onCreate service")
mContext = applicationContext mContext = applicationContext
startForeground(50, PushNotification()) startForeground(50, pushNotification())
super.onCreate() super.onCreate()
} }
@ -296,7 +297,7 @@ open class CameraLightSensorService : Service() {
buffer[bytes] buffer[bytes]
val bitmapImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.size, null) val bitmapImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.size, null)
val brightness = calculateBrightnessEstimate(bitmapImage, 2) val brightness = calculateBrightnessEstimate(bitmapImage, 2)
AdjustBrightness(brightness) adjustBrightness(brightness)
} }
protected fun createCaptureRequest(): CaptureRequest? { protected fun createCaptureRequest(): CaptureRequest? {
@ -319,7 +320,7 @@ open class CameraLightSensorService : Service() {
+ " Opened by Package " + packageId + " Opened by Package " + packageId
) )
mLock = true mLock = true
if (packageId == mContext!!.basePackageName) return if (packageId == mContext.basePackageName) return
avail = false avail = false
} }
@ -355,9 +356,9 @@ open class CameraLightSensorService : Service() {
} }
private fun calculateBrightnessEstimate(bitmap: Bitmap, pixelSpacing: Int): Int { private fun calculateBrightnessEstimate(bitmap: Bitmap, pixelSpacing: Int): Int {
var R = 0 var r = 0
var G = 0 var g = 0
var B = 0 var b = 0
val height = bitmap.height val height = bitmap.height
val width = bitmap.width val width = bitmap.width
var n = 0 var n = 0
@ -366,17 +367,17 @@ open class CameraLightSensorService : Service() {
var i = 0 var i = 0
while (i < pixels.size) { while (i < pixels.size) {
val color = pixels[i] val color = pixels[i]
R += Color.red(color) r += Color.red(color)
G += Color.green(color) g += Color.green(color)
B += Color.blue(color) b += Color.blue(color)
n++ n++
i += pixelSpacing i += pixelSpacing
} }
return (R + B + G) / (n * 3) return (r + g + b) / (n * 3)
} }
@Throws(SettingNotFoundException::class) @Throws(SettingNotFoundException::class)
private fun AdjustBrightness(brightness: Int) { private fun adjustBrightness(brightness: Int) {
if (DEBUG) Log.i(TAG, "AdjustBrightness: Received Brightness Value $brightness") if (DEBUG) Log.i(TAG, "AdjustBrightness: Received Brightness Value $brightness")
val oldbrightness = val oldbrightness =
Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS) Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS)
@ -401,7 +402,7 @@ open class CameraLightSensorService : Service() {
while (!Thread.currentThread().isInterrupted) { while (!Thread.currentThread().isInterrupted) {
if (avail && !mLock) { if (avail && !mLock) {
SystemClock.sleep(DELAY.toLong()) SystemClock.sleep(DELAY.toLong())
ContextCompat.getMainExecutor(mContext!!).execute { if (avail) readyCamera() } ContextCompat.getMainExecutor(mContext).execute { if (avail) readyCamera() }
}else{ }else{
SystemClock.sleep(DELAY.toLong() / 10) // For Fast Detection SystemClock.sleep(DELAY.toLong() / 10) // For Fast Detection
} }
@ -413,7 +414,7 @@ open class CameraLightSensorService : Service() {
const val DEBUG = false const val DEBUG = false
protected const val CAMERA_CHOICE = CameraCharacteristics.LENS_FACING_FRONT protected const val CAMERA_CHOICE = CameraCharacteristics.LENS_FACING_FRONT
private const val DELAY = 5 * 1000 // 5 Seconds private const val DELAY = 5 * 1000 // 5 Seconds
fun BatteryOptimization(context: Context?) { fun batteryOptimization(context: Context?) {
val intent = Intent() val intent = Intent()
val packageName = context!!.packageName val packageName = context!!.packageName
val pm = context.getSystemService(POWER_SERVICE) as PowerManager val pm = context.getSystemService(POWER_SERVICE) as PowerManager

View file

@ -1,20 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!-- Copyright (C) 2020 DerpFest
Copyright (C) 2016 The CyanogenMod Project
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<resources> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<bool name="call_recording_enabled">true</bool>
<integer name="call_recording_audio_source">4</integer> <string name="maintainer_name">Soo Hwan Na (Royna)</string>
</resources> </resources>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* Copyright (C) 2018 The LineageOS Project
* SPDX-License-Identifier: Apache-2.0
-->
<resources>
<bool name="config_haveHigherAspectRatioScreen">true</bool>
<!-- Defines the actions shown in advanced reboot submenu -->
<string-array name="config_restartActionsList">
<item>restart</item>
<item>restart_recovery</item>
<item>restart_download</item>
<item>restart_fastboot</item>
</string-array>
<!-- Whether device has a notch -->
<bool name="config_haveNotch">true</bool>
</resources>

View file

@ -7,6 +7,9 @@ $(call inherit-product, frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk)
# Build Fingerprints # Build Fingerprints
$(call inherit-product, $(LOCAL_PATH)/fingerprint.mk) $(call inherit-product, $(LOCAL_PATH)/fingerprint.mk)
# Derp
DERP_BUILDTYPE := Official
# Allow Copying of apks. # Allow Copying of apks.
PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true
@ -171,7 +174,7 @@ PRODUCT_COPY_FILES += \
# Overlays # Overlays
DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay
# DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay-lineage DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay-derp
# Permissions # Permissions
PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \