From fbfb2b8389bd8d8be32a7ea9799232af28ac2a0f Mon Sep 17 00:00:00 2001 From: David van Tonder Date: Sat, 5 Nov 2011 14:43:30 -0400 Subject: [PATCH] Added - C1Parts Settings app - CM7 LED Notifications support (liblights and overlay) Settings app supports - mDNIe settings - HSPA Config - Backlight timeout config - LED Notifications config (default off) Change-Id: Ib43ea0ca8846a358dc48b91f911a3a1899d2c7a6 --- C1Parts/Android.mk | 13 +++ C1Parts/AndroidManifest.xml | 18 ++++ C1Parts/res/values/arrays.xml | 91 +++++++++++++++++++ C1Parts/res/values/strings.xml | 24 +++++ C1Parts/res/xml/main.xml | 68 ++++++++++++++ .../src/com/cyanogenmod/C1Parts/C1Parts.java | 53 +++++++++++ C1Parts/src/com/cyanogenmod/C1Parts/Hspa.java | 48 ++++++++++ .../C1Parts/NotificationEnabled.java | 37 ++++++++ .../C1Parts/NotificationTimeout.java | 37 ++++++++ .../src/com/cyanogenmod/C1Parts/Startup.java | 19 ++++ .../C1Parts/TouchKeyBacklightTimeout.java | 37 ++++++++ .../src/com/cyanogenmod/C1Parts/Utils.java | 48 ++++++++++ .../com/cyanogenmod/C1Parts/mDNIeUIMode.java | 37 ++++++++ .../cyanogenmod/C1Parts/mDNIeUserMode.java | 37 ++++++++ liblight/lights.c | 57 +++++++----- .../apps/CMParts/res/values/config.xml | 4 +- 16 files changed, 606 insertions(+), 22 deletions(-) create mode 100644 C1Parts/Android.mk create mode 100644 C1Parts/AndroidManifest.xml create mode 100644 C1Parts/res/values/arrays.xml create mode 100644 C1Parts/res/values/strings.xml create mode 100644 C1Parts/res/xml/main.xml create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/C1Parts.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/Hspa.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/NotificationEnabled.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/NotificationTimeout.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/Startup.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/TouchKeyBacklightTimeout.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/Utils.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUIMode.java create mode 100644 C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUserMode.java diff --git a/C1Parts/Android.mk b/C1Parts/Android.mk new file mode 100644 index 0000000..43260e8 --- /dev/null +++ b/C1Parts/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := C1Parts +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/C1Parts/AndroidManifest.xml b/C1Parts/AndroidManifest.xml new file mode 100644 index 0000000..798fba8 --- /dev/null +++ b/C1Parts/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + diff --git a/C1Parts/res/values/arrays.xml b/C1Parts/res/values/arrays.xml new file mode 100644 index 0000000..42f2be8 --- /dev/null +++ b/C1Parts/res/values/arrays.xml @@ -0,0 +1,91 @@ + + + + UI (Default) + Video + Video Warm + Video Cold + Camera + Navigation + Gallery + + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + + + + Standard (Default) + Dynamic + Movie + + + + 1 + 0 + 2 + + + + Always On + 5 seconds + 10 seconds + 15 seconds + Always Off + + + + -1 + 5000 + 10000 + 15000 + -2 + + + + Never + 5 minutes + 10 minutes + 15 minutes + 30 minutes + 60 minutes + + + + -1 + 300000 + 600000 + 900000 + 1800000 + 3600000 + + + + Enabled + Disabled + + + + 1 + -1 + + + + UMTS Only + HSDPA Only + HSDPA + HSUPA + + + + 21 + 22 + 23 + + + diff --git a/C1Parts/res/values/strings.xml b/C1Parts/res/values/strings.xml new file mode 100644 index 0000000..216041f --- /dev/null +++ b/C1Parts/res/values/strings.xml @@ -0,0 +1,24 @@ + + + Galaxy SII Settings + + Screen Settings + Color + Set the mDNIe color mode + Sharpness + Set the mDNIe sharpness mode + + Touchkey + Backlight Timeout + How long the touchkey backlight should stay on before turning off + + LED Notifications + Notifications + Enable kernel support for LED Notifications. Note: An active notification will prevent the phone from entering deep sleep + Notification Timeout + How long the notification indicator should stay on before turning off + + Radio + HSPA + Enable HSDPA/HSUPA + diff --git a/C1Parts/res/xml/main.xml b/C1Parts/res/xml/main.xml new file mode 100644 index 0000000..92966c1 --- /dev/null +++ b/C1Parts/res/xml/main.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/C1Parts.java b/C1Parts/src/com/cyanogenmod/C1Parts/C1Parts.java new file mode 100644 index 0000000..a913919 --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/C1Parts.java @@ -0,0 +1,53 @@ +package com.cyanogenmod.C1Parts; + +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.PreferenceActivity; + +public class C1Parts extends PreferenceActivity { + + public static final String MDNIE_UI = "mdnie_ui"; + public static final String MDNIE_USER = "mdnie_user"; + public static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout"; + public static final String NOTIFICATION_TIMEOUT = "notification_timeout"; + public static final String NOTIFICATION_ENABLED = "notification_enabled"; + public static final String KEY_HSPA = "hspa"; + + private ListPreference mmDNIeUIMode; + private ListPreference mmDNIeUserMode; + private ListPreference mBacklightTimeout; + private ListPreference mNotificationTimeout; + private ListPreference mNotificationEnabled; + private ListPreference mHspa; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.main); + + mmDNIeUIMode = (ListPreference) findPreference(MDNIE_UI); + mmDNIeUIMode.setEnabled(NotificationEnabled.isSupported()); + mmDNIeUIMode.setOnPreferenceChangeListener(new mDNIeUIMode()); + + mmDNIeUserMode = (ListPreference) findPreference(MDNIE_USER); + mmDNIeUserMode.setEnabled(NotificationEnabled.isSupported()); + mmDNIeUserMode.setOnPreferenceChangeListener(new mDNIeUserMode()); + + mNotificationEnabled = (ListPreference) findPreference(NOTIFICATION_ENABLED); + mNotificationEnabled.setEnabled(NotificationEnabled.isSupported()); + mNotificationEnabled.setOnPreferenceChangeListener(new NotificationEnabled()); + + mNotificationTimeout = (ListPreference) findPreference(NOTIFICATION_TIMEOUT); + mNotificationTimeout.setEnabled(NotificationTimeout.isSupported()); + mNotificationTimeout.setOnPreferenceChangeListener(new NotificationTimeout()); + + mBacklightTimeout = (ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT); + mBacklightTimeout.setEnabled(TouchKeyBacklightTimeout.isSupported()); + mBacklightTimeout.setOnPreferenceChangeListener(new TouchKeyBacklightTimeout()); + + mHspa = (ListPreference) findPreference(KEY_HSPA); + mHspa.setEnabled(Hspa.isSupported()); + mHspa.setOnPreferenceChangeListener(new Hspa(this)); + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/Hspa.java b/C1Parts/src/com/cyanogenmod/C1Parts/Hspa.java new file mode 100644 index 0000000..cbf3e2d --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/Hspa.java @@ -0,0 +1,48 @@ +package com.cyanogenmod.C1Parts; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class Hspa implements OnPreferenceChangeListener { + + private static final String APK_FILE = "/system/app/SamsungServiceMode.apk"; + private Context mCtx; + + public Hspa(Context context) { + mCtx = context; + } + + public static boolean isSupported() { + return Utils.fileExists(APK_FILE); + } + + /** + * Restore HSPA setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + sendIntent(context, sharedPrefs.getString(C1Parts.KEY_HSPA, "23")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + sendIntent(mCtx, (String) newValue); + return true; + } + + private static void sendIntent(Context context, String value) { + Intent i = new Intent("com.cyanogenmod.SamsungServiceMode.EXECUTE"); + i.putExtra("sub_type", 20); // HSPA Setting + i.putExtra("data", value); + context.sendBroadcast(i); + } +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/NotificationEnabled.java b/C1Parts/src/com/cyanogenmod/C1Parts/NotificationEnabled.java new file mode 100644 index 0000000..730abe6 --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/NotificationEnabled.java @@ -0,0 +1,37 @@ +package com.cyanogenmod.C1Parts; + +import android.content.Context; + +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class NotificationEnabled implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/misc/notification/notification_enabled"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore notification enabled setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(C1Parts.NOTIFICATION_ENABLED, "-1")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/NotificationTimeout.java b/C1Parts/src/com/cyanogenmod/C1Parts/NotificationTimeout.java new file mode 100644 index 0000000..01548b5 --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/NotificationTimeout.java @@ -0,0 +1,37 @@ +package com.cyanogenmod.C1Parts; + +import android.content.Context; + +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class NotificationTimeout implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/misc/notification/notification_timeout"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore notification timeout setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(C1Parts.NOTIFICATION_TIMEOUT, "-1")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/Startup.java b/C1Parts/src/com/cyanogenmod/C1Parts/Startup.java new file mode 100644 index 0000000..86e6fa8 --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/Startup.java @@ -0,0 +1,19 @@ +package com.cyanogenmod.C1Parts; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class Startup extends BroadcastReceiver { + + @Override + public void onReceive(final Context context, final Intent bootintent) { + TouchKeyBacklightTimeout.restore(context); + NotificationTimeout.restore(context); + NotificationEnabled.restore(context); + Hspa.restore(context); + mDNIeUIMode.restore(context); + mDNIeUserMode.restore(context); + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/TouchKeyBacklightTimeout.java b/C1Parts/src/com/cyanogenmod/C1Parts/TouchKeyBacklightTimeout.java new file mode 100644 index 0000000..c88a44b --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/TouchKeyBacklightTimeout.java @@ -0,0 +1,37 @@ +package com.cyanogenmod.C1Parts; + +import android.content.Context; + +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class TouchKeyBacklightTimeout implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/misc/notification/led_timeout"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore backlight timeout setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(C1Parts.KEY_BACKLIGHT_TIMEOUT, "-1")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/Utils.java b/C1Parts/src/com/cyanogenmod/C1Parts/Utils.java new file mode 100644 index 0000000..6611e6c --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/Utils.java @@ -0,0 +1,48 @@ +package com.cyanogenmod.C1Parts; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class Utils { + + /** + * Write a string value to the specified file. + * @param filename The filename + * @param value The value + */ + public static void writeValue(String filename, String value) { + try { + FileOutputStream fos = new FileOutputStream(new File(filename)); + fos.write(value.getBytes()); + fos.flush(); + fos.getFD().sync(); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Write the "color value" to the specified file. The value is scaled from + * an integer to an unsigned integer by multiplying by 2. + * @param filename The filename + * @param value The value of max value Integer.MAX + */ + public static void writeColor(String filename, int value) { + writeValue(filename, String.valueOf((long) value * 2)); + } + + /** + * Check if the specified file exists. + * @param filename The filename + * @return Whether the file exists or not + */ + public static boolean fileExists(String filename) { + return new File(filename).exists(); + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUIMode.java b/C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUIMode.java new file mode 100644 index 0000000..162161c --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUIMode.java @@ -0,0 +1,37 @@ +package com.cyanogenmod.C1Parts; + +import android.content.Context; + +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class mDNIeUIMode implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/mdnieset_ui/switch_mdnieset_ui/mdnieset_ui_file_cmd"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore Mdnie ui setting setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(C1Parts.MDNIE_UI, "0")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUserMode.java b/C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUserMode.java new file mode 100644 index 0000000..a168ea7 --- /dev/null +++ b/C1Parts/src/com/cyanogenmod/C1Parts/mDNIeUserMode.java @@ -0,0 +1,37 @@ +package com.cyanogenmod.C1Parts; + +import android.content.Context; + +import android.content.SharedPreferences; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceManager; + +public class mDNIeUserMode implements OnPreferenceChangeListener { + + private static final String FILE = "/sys/class/mdnieset_ui/switch_mdnieset_ui/mdnieset_user_select_file_cmd"; + + public static boolean isSupported() { + return Utils.fileExists(FILE); + } + + /** + * Restore mdnie user mode setting from SharedPreferences. (Write to kernel.) + * @param context The context to read the SharedPreferences from + */ + public static void restore(Context context) { + if (!isSupported()) { + return; + } + + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + Utils.writeValue(FILE, sharedPrefs.getString(C1Parts.MDNIE_USER, "1")); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Utils.writeValue(FILE, (String) newValue); + return true; + } + +} diff --git a/liblight/lights.c b/liblight/lights.c index b3eba87..cd812b3 100644 --- a/liblight/lights.c +++ b/liblight/lights.c @@ -1,5 +1,8 @@ /* * Copyright (C) 2011 Kolja Dummann + * Copyright (C) 2011 Marco Hillenbrand + * Copyright (C) 2011 Daniel Hillenbrand + * Copyright (C) 2011 David van Tonder * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +18,6 @@ */ #define LOG_TAG "lights" - #define LOG_NDEBUG 0 #include @@ -28,11 +30,15 @@ #include #include +/* LED NOTIFICATIONS BACKLIGHT */ +#define ENABLE_BL 1 +#define DISABLE_BL 2 +char const *const NOTIFICATION_FILE = "/sys/class/misc/notification/led"; + static pthread_once_t g_init = PTHREAD_ONCE_INIT; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; char const *const LCD_FILE = "/sys/class/backlight/pwm-backlight/brightness"; -char const *const BUTTON_FILE = "/sys/devices/virtual/misc/melfas_touchkey/brightness"; static int write_int(char const *path, int value) { @@ -61,9 +67,9 @@ static int write_int(char const *path, int value) static int rgb_to_brightness(struct light_state_t const *state) { - int color = state->color & 0x00ffffff; + int color = state->color & 0x00ffffff; - return ((77*((color>>16) & 0x00ff)) + return ((77*((color>>16) & 0x00ff)) + (150*((color>>8) & 0x00ff)) + (29*(color & 0x00ff))) >> 8; } @@ -71,27 +77,37 @@ static int is_lit (struct light_state_t const* state) { return state->color & 0xffffffff; } -static int set_light_backlight(struct light_device_t *dev, - struct light_state_t const *state) +static int set_light_backlight(struct light_device_t *dev, struct light_state_t const *state) { int err = 0; int brightness = rgb_to_brightness(state); pthread_mutex_lock(&g_lock); err = write_int(LCD_FILE, brightness); - pthread_mutex_unlock(&g_lock); + return err; } -static int set_light_buttons (struct light_device_t* dev, - struct light_state_t const* state) { - int err = 0; - int on = is_lit (state); - LOGV("%s state->color = %d is_lit = %d", __func__,state->color , on); - pthread_mutex_lock (&g_lock); - err = write_int (BUTTON_FILE, on?1:0); - pthread_mutex_unlock (&g_lock); - return 0; + +static int set_light_notifications(struct light_device_t* dev, struct light_state_t const* state) +{ + int err = 0; + int brightness = rgb_to_brightness(state); + + if (brightness+state->color == 0 || brightness > 100 ) { + pthread_mutex_lock(&g_lock); + + if (state->color & 0x00ffffff) { + LOGV("[LED Notify] set_light_notifications - ENABLE_BL\n"); + err = write_int (NOTIFICATION_FILE, ENABLE_BL); + } else { + LOGV("[LED Notify] set_light_notifications - DISABLE_BL\n"); + err = write_int (NOTIFICATION_FILE, DISABLE_BL); + } + pthread_mutex_unlock(&g_lock); + } + + return 0; } static int close_lights(struct light_device_t *dev) @@ -103,8 +119,7 @@ static int close_lights(struct light_device_t *dev) return 0; } -static int open_lights(const struct hw_module_t *module, char const *name, - struct hw_device_t **device) +static int open_lights(const struct hw_module_t *module, char const *name, struct hw_device_t **device) { int (*set_light)(struct light_device_t *dev, struct light_state_t const *state); @@ -113,9 +128,9 @@ static int open_lights(const struct hw_module_t *module, char const *name, if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) set_light = set_light_backlight; - else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) - set_light = set_light_buttons; - else + else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) + set_light = set_light_notifications; + else return -EINVAL; pthread_mutex_init(&g_lock, NULL); diff --git a/overlay/packages/apps/CMParts/res/values/config.xml b/overlay/packages/apps/CMParts/res/values/config.xml index 43b53b5..58d997a 100644 --- a/overlay/packages/apps/CMParts/res/values/config.xml +++ b/overlay/packages/apps/CMParts/res/values/config.xml @@ -1,4 +1,6 @@ - true + true + + true