- 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
This commit is contained in:
David van Tonder 2011-11-05 14:43:30 -04:00 committed by atinm
parent 815eaec4de
commit fbfb2b8389
16 changed files with 606 additions and 22 deletions

13
C1Parts/Android.mk Normal file
View File

@ -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))

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyanogenmod.C1Parts" android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="@string/app_name">
<activity android:name=".C1Parts"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.cyanogenmod.action.LAUNCH_DEVICE_SETTINGS" />
</intent-filter>
</activity>
<receiver android:name=".Startup">
<intent-filter android:priority="100">
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@ -0,0 +1,91 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string-array name="mdnie_ui_entries">
<item>UI (Default)</item>
<item>Video</item>
<item>Video Warm</item>
<item>Video Cold</item>
<item>Camera</item>
<item>Navigation</item>
<item>Gallery</item>
</string-array>
<string-array name="mdnie_ui_entries_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
</string-array>
<string-array name="mdnie_user_entries">
<item>Standard (Default)</item>
<item>Dynamic</item>
<item>Movie</item>
</string-array>
<string-array name="mdnie_user_entries_values" translatable="false">
<item>1</item>
<item>0</item>
<item>2</item>
</string-array>
<string-array name="backlight_timeout_entries">
<item>Always On</item>
<item>5 seconds</item>
<item>10 seconds</item>
<item>15 seconds</item>
<item>Always Off</item>
</string-array>
<string-array name="backlight_timeout_entries_values" translatable="false">
<item>-1</item>
<item>5000</item>
<item>10000</item>
<item>15000</item>
<item>-2</item>
</string-array>
<string-array name="notification_timeout_entries">
<item>Never</item>
<item>5 minutes</item>
<item>10 minutes</item>
<item>15 minutes</item>
<item>30 minutes</item>
<item>60 minutes</item>
</string-array>
<string-array name="notification_timeout_entries_values" translatable="false">
<item>-1</item>
<item>300000</item>
<item>600000</item>
<item>900000</item>
<item>1800000</item>
<item>3600000</item>
</string-array>
<string-array name="notification_enabled_entries">
<item>Enabled</item>
<item>Disabled</item>
</string-array>
<string-array name="notification_enabled_entries_values" translatable="false">
<item>1</item>
<item>-1</item>
</string-array>
<string-array name="hspa_entries">
<item>UMTS Only</item>
<item>HSDPA Only</item>
<item>HSDPA + HSUPA</item>
</string-array>
<string-array name="hspa_entries_values" translatable="false">
<item>21</item>
<item>22</item>
<item>23</item>
</string-array>
</resources>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Galaxy SII Settings</string>
<string name="category_mdnie_title">Screen Settings</string>
<string name="mdnie_ui_title_head">Color</string>
<string name="mdnie_ui_summary_head">Set the mDNIe color mode</string>
<string name="mdnie_user_title_head">Sharpness</string>
<string name="mdnie_user_summary_head">Set the mDNIe sharpness mode</string>
<string name="category_touchkey_title">Touchkey</string>
<string name="backlight_timeout_title_head">Backlight Timeout</string>
<string name="backlight_timeout_summary_head">How long the touchkey backlight should stay on before turning off</string>
<string name="category_notify_title">LED Notifications</string>
<string name="notification_enabled_title_head">Notifications</string>
<string name="notification_enabled_summary_head">Enable kernel support for LED Notifications. Note: An active notification will prevent the phone from entering deep sleep</string>
<string name="notification_timeout_title_head">Notification Timeout</string>
<string name="notification_timeout_summary_head">How long the notification indicator should stay on before turning off</string>
<string name="category_radio_title">Radio</string>
<string name="hspa_title_head">HSPA</string>
<string name="hspa_summary_head">Enable HSDPA/HSUPA</string>
</resources>

68
C1Parts/res/xml/main.xml Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/category_mdnie_title">
<!-- mDNIe Color Modes -->
<ListPreference
android:key="mdnie_ui"
android:title="@string/mdnie_ui_title_head"
android:summary="@string/mdnie_ui_summary_head"
android:entries="@array/mdnie_ui_entries"
android:entryValues="@array/mdnie_ui_entries_values"
android:defaultValue="0" />
<!-- mDNIe Sharpness Modes -->
<ListPreference
android:key="mdnie_user"
android:title="@string/mdnie_user_title_head"
android:summary="@string/mdnie_user_summary_head"
android:entries="@array/mdnie_user_entries"
android:entryValues="@array/mdnie_user_entries_values"
android:defaultValue="1" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/category_touchkey_title">
<!-- Touchkey backlight timeout -->
<ListPreference
android:key="backlight_timeout"
android:title="@string/backlight_timeout_title_head"
android:summary="@string/backlight_timeout_summary_head"
android:entries="@array/backlight_timeout_entries"
android:entryValues="@array/backlight_timeout_entries_values"
android:defaultValue="-1" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/category_notify_title">
<!-- LED Notification enable -->
<ListPreference
android:key="notification_enabled"
android:title="@string/notification_enabled_title_head"
android:summary="@string/notification_enabled_summary_head"
android:entries="@array/notification_enabled_entries"
android:entryValues="@array/notification_enabled_entries_values"
android:defaultValue="-1" />
<!-- LED Notification timeout -->
<ListPreference
android:key="notification_timeout"
android:title="@string/notification_timeout_title_head"
android:summary="@string/notification_timeout_summary_head"
android:entries="@array/notification_timeout_entries"
android:entryValues="@array/notification_timeout_entries_values"
android:defaultValue="-1" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/category_radio_title">
<!-- UMTS/HSDPA/HSUPA settings -->
<ListPreference
android:key="hspa"
android:title="@string/hspa_title_head"
android:summary="@string/hspa_summary_head"
android:entries="@array/hspa_entries"
android:entryValues="@array/hspa_entries_values"
android:defaultValue="23" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,5 +1,8 @@
/*
* Copyright (C) 2011 Kolja Dummann <k.dummann@gmail.com>
* Copyright (C) 2011 Marco Hillenbrand <marco.hillenbrand@googlemail.com>
* Copyright (C) 2011 Daniel Hillenbrand <daniel.hillenbrand@codeworkx.de>
* Copyright (C) 2011 David van Tonder <david.vantonder@gmail.com>
*
* 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 <cutils/log.h>
@ -28,11 +30,15 @@
#include <sys/types.h>
#include <hardware/lights.h>
/* 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);

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="has_led_flash">true</bool>
<bool name="has_led_flash">true</bool>
<!-- Notification LED has single color only -->
<bool name="has_single_notification_led">true</bool>
</resources>