diff --git a/universal7885-common/apps/CameraLightSensor/Android.bp b/universal7885-common/apps/CameraLightSensor/Android.bp
new file mode 100644
index 0000000..fc3d95b
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/Android.bp
@@ -0,0 +1,9 @@
+android_app {
+ name: "CameraLightSensor",
+ srcs: [
+ "src/**/*.java",
+ ],
+ platform_apis: true,
+ privileged: true,
+ certificate: "platform",
+}
diff --git a/universal7885-common/apps/CameraLightSensor/AndroidManifest.xml b/universal7885-common/apps/CameraLightSensor/AndroidManifest.xml
new file mode 100644
index 0000000..fb3892b
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/AndroidManifest.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/universal7885-common/apps/CameraLightSensor/res/drawable/ic_brightness.xml b/universal7885-common/apps/CameraLightSensor/res/drawable/ic_brightness.xml
new file mode 100644
index 0000000..d3180f3
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/res/drawable/ic_brightness.xml
@@ -0,0 +1,9 @@
+
+
+
\ No newline at end of file
diff --git a/universal7885-common/apps/CameraLightSensor/res/values/strings.xml b/universal7885-common/apps/CameraLightSensor/res/values/strings.xml
new file mode 100644
index 0000000..a2a4d20
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ CameraLightSensor
+
\ No newline at end of file
diff --git a/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/BootReceiver.java b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/BootReceiver.java
new file mode 100644
index 0000000..33b33fc
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/BootReceiver.java
@@ -0,0 +1,20 @@
+package com.eurekateam.cameralightsensor;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class BootReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
+ if (context != null) {
+ final Intent i = new Intent();
+ i.setClassName("com.eurekateam.cameralightsensor",
+ "com.eurekateam.cameralightsensor.CameraLightSensorService");
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(i);
+ }
+ }
+ }
+}
diff --git a/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/Camera2Service.java b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/Camera2Service.java
new file mode 100644
index 0000000..7a54b61
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/Camera2Service.java
@@ -0,0 +1,271 @@
+package com.eurekateam.cameralightsensor;
+
+import static com.eurekateam.cameralightsensor.CameraLightSensorService.DEBUG;
+
+import android.Manifest;
+import android.annotation.NonNull;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.ImageFormat;
+import android.hardware.camera2.CameraAccessException;
+import android.hardware.camera2.CameraCaptureSession;
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraDevice;
+import android.hardware.camera2.CameraManager;
+import android.hardware.camera2.CaptureRequest;
+import android.media.Image;
+import android.media.ImageReader;
+import android.os.IBinder;
+import android.provider.Settings;
+import android.util.Log;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+
+public class Camera2Service extends Service {
+ protected static final String TAG = Camera2Service.class.getSimpleName();
+ protected static final int CAMERACHOICE = CameraCharacteristics.LENS_FACING_FRONT;
+ protected static long cameraCaptureStartTime;
+ boolean destroy;
+ protected CameraDevice cameraDevice;
+ protected CameraCaptureSession session;
+ boolean isavail = true;
+ protected ImageReader imageReader;
+ private Context mContext;
+
+ protected CameraDevice.StateCallback cameraStateCallback = new CameraDevice.StateCallback() {
+ @Override
+ public void onOpened(@NonNull CameraDevice camera) {
+ Log.d(TAG, "CameraDevice.StateCallback onOpened");
+ cameraDevice = camera;
+ actOnReadyCameraDevice();
+ }
+
+ @Override
+ public void onDisconnected(@NonNull CameraDevice camera) {
+ Log.w(TAG, "CameraDevice.StateCallback onDisconnected");
+ }
+
+ @Override
+ public void onError(@NonNull CameraDevice camera, int error) {
+ Log.e(TAG, "CameraDevice.StateCallback onError " + error);
+ }
+ };
+
+ protected CameraCaptureSession.StateCallback sessionStateCallback = new CameraCaptureSession.StateCallback() {
+
+ @Override
+ public void onReady(CameraCaptureSession session) {
+ if (!destroy && isavail) {
+ Camera2Service.this.session = session;
+ isavail = false;
+ try {
+ session.capture(createCaptureRequest(), null, null);
+ } catch (Exception e){
+ Log.e(TAG, "Camera is in use");
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ @Override
+ public void onConfigured(CameraCaptureSession session) {
+
+ }
+
+ @Override
+ public void onConfigureFailed(@NonNull CameraCaptureSession session) {
+ }
+ };
+
+ protected ImageReader.OnImageAvailableListener onImageAvailableListener = new ImageReader.OnImageAvailableListener() {
+ @Override
+ public void onImageAvailable(ImageReader reader) {
+ if (DEBUG) Log.d(TAG, "onImageAvailable: Capturing");
+ Image img = reader.acquireLatestImage();
+ cameraCaptureStartTime = System.currentTimeMillis();
+ if (img != null) {
+ try {
+ processImage(img);
+ } catch (Settings.SettingNotFoundException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ img.close();
+ }
+ try {
+ session.stopRepeating();
+ session.close();
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ }
+
+ }
+ };
+
+ public void readyCamera() {
+ CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE);
+ try {
+ String pickedCamera = getCamera(manager);
+ if (this.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ manager.openCamera(pickedCamera, cameraStateCallback, null);
+ imageReader = ImageReader.newInstance(720, 720, ImageFormat.JPEG, 2 /* images buffered */);
+ imageReader.setOnImageAvailableListener(onImageAvailableListener, null);
+ if (DEBUG) Log.d(TAG, "imageReader created");
+ } catch (CameraAccessException e) {
+ Log.e(TAG, e.getMessage());
+ }
+ }
+
+ public String getCamera(CameraManager manager) {
+ try {
+ for (String cameraId : manager.getCameraIdList()) {
+ CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
+ int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
+ if (cOrientation == CAMERACHOICE) {
+ return cameraId;
+ }
+ }
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if(DEBUG) Log.d(TAG, "onStartCommand flags " + flags + " startId " + startId);
+ readyCamera();
+ destroy = false;
+ isavail = true;
+ cameraCaptureStartTime = System.currentTimeMillis();
+ startForeground(50, PushNotification());
+ return START_STICKY;
+ }
+
+ public Notification PushNotification()
+ {
+ NotificationManager nm = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
+ NotificationChannel channel = new NotificationChannel(
+ mContext.getPackageName(), "CameraLightSensor",
+ NotificationManager.IMPORTANCE_LOW
+ );
+ nm.createNotificationChannel(channel);
+ Notification.Builder builder = new Notification.Builder(mContext);
+ Intent notificationIntent = new Intent(mContext, Camera2Service.class);
+ PendingIntent contentIntent = PendingIntent.getActivity(mContext,50,notificationIntent,PendingIntent.FLAG_IMMUTABLE);
+
+ //set
+ builder.setContentIntent(contentIntent);
+ builder.setSmallIcon(R.drawable.ic_brightness);
+ builder.setContentText("Camera Light Sensor is running");
+ builder.setContentTitle("Camera Light Sensor");
+ builder.setChannelId(mContext.getPackageName());
+ builder.setAutoCancel(true);
+
+ return builder.build();
+ }
+ @Override
+ public void onCreate() {
+ if(DEBUG) Log.d(TAG, "onCreate service");
+ mContext = getApplicationContext();
+ startForeground(0, PushNotification());
+ super.onCreate();
+ }
+
+ public void actOnReadyCameraDevice() {
+ try {
+ cameraDevice.createCaptureSession(Collections.singletonList(imageReader.getSurface()), sessionStateCallback, null);
+ } catch (CameraAccessException e) {
+ Log.e(TAG, e.getMessage());
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ if (session != null && isavail) {
+ try {
+ session.abortCaptures();
+ session.close();
+ } catch (CameraAccessException e) {
+ Log.e(TAG, e.getMessage());
+ }
+
+ }
+ destroy = true;
+ Log.i(TAG, "onDestory: Destory");
+ stopForeground(true);
+ }
+
+ private void processImage(Image image) throws Settings.SettingNotFoundException, InterruptedException {
+ ByteBuffer buffer = image.getPlanes()[0].getBuffer();
+ byte[] bytes = new byte[buffer.capacity()];
+ buffer.get(bytes);
+ Bitmap bitmapImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
+ int brightness = calculateBrightnessEstimate(bitmapImage,10);
+ Log.i(TAG, "brightness: " + brightness);
+ AdjustBrightness(brightness);
+ }
+
+ protected CaptureRequest createCaptureRequest() {
+ try {
+ CaptureRequest.Builder builder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
+ builder.addTarget(imageReader.getSurface());
+ return builder.build();
+ } catch (CameraAccessException e) {
+ Log.e(TAG, e.getMessage());
+ return null;
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+ public int calculateBrightnessEstimate(android.graphics.Bitmap bitmap, int pixelSpacing) {
+ int R = 0; int G = 0; int B = 0;
+ int height = bitmap.getHeight();
+ int width = bitmap.getWidth();
+ int n = 0;
+ int[] pixels = new int[width * height];
+ bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
+ for (int i = 0; i < pixels.length; i += pixelSpacing) {
+ int color = pixels[i];
+ R += Color.red(color);
+ G += Color.green(color);
+ B += Color.blue(color);
+ n++;
+ }
+ return (R + B + G) / (n * 3);
+ }
+ private void AdjustBrightness(int brightness) throws Settings.SettingNotFoundException, InterruptedException {
+ if(DEBUG) Log.i(TAG, "AdjustBrightness: Received Brightness Value " + brightness);
+ int oldbrightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
+ if (DEBUG) Log.i(TAG, "AdjustBrightness: Oldval = " + oldbrightness + " Newval = " +
+ brightness + " Adjusting..");
+ if(oldbrightness > brightness){
+ while (oldbrightness > brightness){
+ Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
+ brightness -= 5;
+ Thread.sleep(500);
+ }
+ }else{
+ while (oldbrightness < brightness){
+ Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
+ brightness += 5;
+ Thread.sleep(500);
+ }
+ }
+ }
+}
diff --git a/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/CameraLightSensorService.java b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/CameraLightSensorService.java
new file mode 100644
index 0000000..6f9d719
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/CameraLightSensorService.java
@@ -0,0 +1,102 @@
+package com.eurekateam.cameralightsensor;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.PowerManager;
+import android.provider.Settings;
+import android.util.Log;
+
+
+public class CameraLightSensorService extends Activity {
+ private static final String TAG = "CameraLightSensor";
+ static final boolean DEBUG = true;
+ Intent i;
+ private boolean stop;
+ private Context mContext;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ moveTaskToBack(true);
+ mContext = getApplicationContext();
+ i = new Intent(mContext, Camera2Service.class);
+ IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+ screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ BatteryOptimization(mContext);
+ registerReceiver(mScreenStateReceiver, screenStateFilter);
+ if (this.checkSelfPermission(Manifest.permission.CAMERA) ==
+ PackageManager.PERMISSION_GRANTED) {
+ Log.d(TAG, "Permission Granted");
+ } else {
+ // You can directly ask for the permission.
+ this.requestPermissions(new String[] { Manifest.permission.CAMERA },
+ 1);
+ }
+ }
+ @Override
+ public void onDestroy() {
+ if (DEBUG) Log.d(TAG, "Destroying service");
+ super.onDestroy();
+ this.unregisterReceiver(mScreenStateReceiver);
+ }
+ private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ stop = false;
+ try {
+ onDisplayOn();
+ } catch (Settings.SettingNotFoundException e) {
+ e.printStackTrace();
+ }
+ } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+ stop = true;
+ onDisplayOff();
+
+ }
+ }
+ };
+ private void onDisplayOn() throws Settings.SettingNotFoundException {
+ if(Settings.System.getInt(getContentResolver(),
+ Settings.System.SCREEN_BRIGHTNESS_MODE ) == 1){
+ if(DEBUG) Log.d(TAG, "AutoBrightness Mode Enabled. Starting...");
+ i = new Intent(mContext, Camera2Service.class);
+ Thread th = new Thread(() -> {
+ do {
+ mContext.startForegroundService(i);
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ } while (!stop);
+ });
+ th.start();
+ }else{
+ Log.d(TAG, "AutoBrightness Mode Disabled, Not Starting Service...");
+ }
+ }
+ private void onDisplayOff(){
+ if(DEBUG) Log.d(TAG, "Screen is off. Stopping Service...");
+ i = new Intent(mContext, Camera2Service.class);
+ mContext.stopService(i);
+ }
+ public static void BatteryOptimization(Context context){
+ Intent intent = new Intent();
+ String packageName = context.getPackageName();
+ PowerManager pm = (PowerManager) context.getSystemService(POWER_SERVICE);
+ if (!pm.isIgnoringBatteryOptimizations(packageName)) {
+ intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ intent.setData(Uri.parse("package:" + packageName));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(intent);
+ }
+ }
+}
diff --git a/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/CameraLightSensorTile.java b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/CameraLightSensorTile.java
new file mode 100644
index 0000000..6134084
--- /dev/null
+++ b/universal7885-common/apps/CameraLightSensor/src/com/eurekateam/cameralightsensor/CameraLightSensorTile.java
@@ -0,0 +1,17 @@
+package com.eurekateam.cameralightsensor;
+
+import android.content.Intent;
+import android.service.quicksettings.TileService;
+
+public class CameraLightSensorTile extends TileService {
+ @Override
+ public void onClick() {
+ try {
+ Intent intent = new Intent(this, CameraLightSensorService.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/universal7885-common/apps/SamsungParts/Android.bp b/universal7885-common/apps/SamsungParts/Android.bp
index 2e80168..d08311c 100644
--- a/universal7885-common/apps/SamsungParts/Android.bp
+++ b/universal7885-common/apps/SamsungParts/Android.bp
@@ -1,8 +1,7 @@
android_app {
name: "SamsungParts",
srcs: [
- "src/*/*/*/*/*.java",
- "src/*/*/*/*.java",
+ "src/**/*.java",
],
platform_apis: true,
privileged: true,