Add default brightness control

This lets user set the default brightness so user doesn't cook
their phone on first boot or loss of settings file, while
still maintaining the ability to turn brightness to max if
desired.

Change-Id: Ia801fba46014335148ec573a0b0bbdf0a3ca60ae
diff --git a/Android.mk b/Android.mk
index c57e8dc..0598796 100644
--- a/Android.mk
+++ b/Android.mk
@@ -299,6 +299,9 @@
 ifneq ($(TW_MAX_BRIGHTNESS),)
 	LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=$(TW_MAX_BRIGHTNESS)
 endif
+ifneq ($(TW_DEFAULT_BRIGHTNESS),)
+	LOCAL_CFLAGS += -DTW_DEFAULT_BRIGHTNESS=$(TW_DEFAULT_BRIGHTNESS)
+endif
 ifneq ($(TW_CUSTOM_BATTERY_PATH),)
 	LOCAL_CFLAGS += -DTW_CUSTOM_BATTERY_PATH=$(TW_CUSTOM_BATTERY_PATH)
 endif
diff --git a/data.cpp b/data.cpp
index 629b4c8..5cca3a1 100644
--- a/data.cpp
+++ b/data.cpp
@@ -865,8 +865,24 @@
 			LOGINFO("Specified secondary brightness file '%s' not found.\n", secondfindbright.c_str());
 		}
 #endif
-		string max_bright = maxVal.str();
-		TWFunc::Set_Brightness(max_bright);
+#ifdef TW_DEFAULT_BRIGHTNESS
+		int defValInt = TW_DEFAULT_BRIGHTNESS;
+		int maxValInt = TW_MAX_BRIGHTNESS;
+		// Deliberately int so the % is always a whole number
+		int defPctInt = ( ( (double)defValInt / maxValInt ) * 100 );
+		ostringstream defPct;
+		defPct << defPctInt;
+		mValues.erase("tw_brightness_pct");
+		mValues.insert(make_pair("tw_brightness_pct", make_pair(defPct.str(), 1)));
+
+		ostringstream defVal;
+		defVal << TW_DEFAULT_BRIGHTNESS;
+		mValues.erase("tw_brightness");
+		mValues.insert(make_pair("tw_brightness", make_pair(defVal.str(), 1)));
+		TWFunc::Set_Brightness(defVal.str());	
+#else
+		TWFunc::Set_Brightness(maxVal.str());
+#endif
 	}
 #endif
 	mValues.insert(make_pair(TW_MILITARY_TIME, make_pair("0", 1)));