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

View file

@ -1,20 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 The CyanogenMod Project
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 DerpFest
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.
-->
<resources>
<bool name="call_recording_enabled">true</bool>
<integer name="call_recording_audio_source">4</integer>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="maintainer_name">Soo Hwan Na (Royna)</string>
</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
$(call inherit-product, $(LOCAL_PATH)/fingerprint.mk)
# Derp
DERP_BUILDTYPE := Official
# Allow Copying of apks.
PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true
@ -171,7 +174,7 @@ PRODUCT_COPY_FILES += \
# Overlays
DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay
# DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay-lineage
DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay-derp
# Permissions
PRODUCT_COPY_FILES += \