zenfone6: lights: Fix charging leds and swith to Android.bp

Change-Id: I05af48b0d156d0b40a466406c84622b1538433ee
diff --git a/lights/Android.bp b/lights/Android.bp
new file mode 100644
index 0000000..34491a6
--- /dev/null
+++ b/lights/Android.bp
@@ -0,0 +1,37 @@
+// Copyright (C) 2018 The LineageOS 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.
+
+cc_binary {
+    name: "android.hardware.light@2.0-service.asus_msmnile",
+    defaults: ["hidl_defaults"],
+    stem: "android.hardware.light@2.0-service",
+    init_rc: ["android.hardware.light@2.0-service.rc"],
+    vendor: false,
+    product_overlay_specific: true,
+    relative_install_path: "hw",
+    srcs: ["service.cpp", "Light.cpp"],
+    shared_libs: [
+        "android.hardware.light@2.0",
+        "libbase",
+        "libhardware",
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "liblog",
+        "libutils",
+    ],
+    overrides: [
+        "light",
+    ],
+}
\ No newline at end of file
diff --git a/lights/Android.mk b/lights/Android.mk
deleted file mode 100644
index 98616ca..0000000
--- a/lights/Android.mk
+++ /dev/null
@@ -1,42 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := android.hardware.light@2.0-service.asus_msmnile
-LOCAL_MODULE_TAGS  := optional
-
-LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/vendor_overlay/$(PRODUCT_TARGET_VNDK_VERSION)/bin
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_MODULE_STEM := android.hardware.light@2.0-service
-
-LOCAL_SRC_FILES := \
-    service.cpp \
-    Light.cpp
-
-LOCAL_REQUIRED_MODULES := \
-    android.hardware.light@2.0-service.asus_msmnile.rc
-
-LOCAL_SHARED_LIBRARIES := \
-    libbase \
-    libhardware \
-    libhidlbase \
-    libhidltransport \
-    liblog \
-    libhwbinder \
-    libutils \
-    android.hardware.light@2.0
-
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := android.hardware.light@2.0-service.asus_msmnile.rc
-LOCAL_MODULE_TAGS  := optional
-LOCAL_MODULE_CLASS := ETC
-
-LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/vendor_overlay/$(PRODUCT_TARGET_VNDK_VERSION)/etc/init
-LOCAL_MODULE_STEM := android.hardware.light@2.0-service.rc
-
-LOCAL_SRC_FILES := android.hardware.light@2.0-service.asus_msmnile.rc
-
-include $(BUILD_PREBUILT)
\ No newline at end of file
diff --git a/lights/Light.cpp b/lights/Light.cpp
index e4178e7..2ffa6b1 100644
--- a/lights/Light.cpp
+++ b/lights/Light.cpp
@@ -83,9 +83,9 @@
 
 static uint32_t rgbToBrightness(const LightState& state) {
     uint32_t color = state.color & 0x00ffffff;
-    return ((77 * ((color >> 16) & 0xff))
-            + (150 * ((color >> 8) & 0xff))
-            + (29 * (color & 0xff))) >> 8;
+    return ((77 * ((color >> 16) & 0x00ff))
+            + (150 * ((color >> 8) & 0x00ff))
+            + (29 * (color & 0x00ff))) >> 8;
 }
 
 Light::Light() {
@@ -115,21 +115,10 @@
         }
     }
 
-    // Extract brightness from AARRGG
-    uint32_t alpha = (stateToUse.color >> 24) & 0xff;
-
     std::map<std::string, int> colorValues;
     colorValues["red"] = (stateToUse.color >> 16) & 0xff;
     colorValues["green"] = (stateToUse.color >> 8) & 0xff;
 
-    // Scale RG colors if a brightness has been applied by the user
-    if (alpha != 0xff) {
-        for (auto& entry : colorValues) {
-            // For more exact scaling divide by half
-            entry.second = ((entry.second * alpha) / 0xff) / 2;
-        }
-    }
-
     auto makeLedPath = [](const std::string& led, const char op[]) -> std::string {
         return "/sys/class/leds/" + led + "/" + op;
     };
diff --git a/lights/android.hardware.light@2.0-service.asus_msmnile.rc b/lights/android.hardware.light@2.0-service.rc
similarity index 100%
rename from lights/android.hardware.light@2.0-service.asus_msmnile.rc
rename to lights/android.hardware.light@2.0-service.rc