Merge "Load RTC offset on Qualcomm Krait chips, fixes the broken time & date" into android-4.4
diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp
index 0f8d903..b7804fd 100644
--- a/gui/fileselector.cpp
+++ b/gui/fileselector.cpp
@@ -659,7 +659,7 @@
 
 int GUIFileSelector::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-	static int lastY = 0, last2Y = 0;
+	static int lastY = 0, last2Y = 0, fastScroll = 0;
 	int selection = 0;
 
 	switch (state)
@@ -674,6 +674,9 @@
 			mUpdate = 1;
 		startY = lastY = last2Y = y;
 		scrollingSpeed = 0;
+
+		if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW)
+			fastScroll = 1;
 		break;
 	case TOUCH_DRAG:
 		// Check if we dragged out of the selection window
@@ -687,7 +690,7 @@
 		}
 
 		// Fast scroll
-		if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW)
+		if(fastScroll)
 		{
 			int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH);
 			int totalSize = (mShowFolders ? mFolderList.size() : 0) + (mShowFiles ? mFileList.size() : 0);
@@ -761,6 +764,7 @@
 
 	case TOUCH_RELEASE:
 		isHighlighted = false;
+		fastScroll = 0;
 		if (startSelection >= 0)
 		{
 			// We've selected an item!
diff --git a/gui/listbox.cpp b/gui/listbox.cpp
index a4976f4..6709664 100644
--- a/gui/listbox.cpp
+++ b/gui/listbox.cpp
@@ -602,7 +602,7 @@
 
 int GUIListBox::NotifyTouch(TOUCH_STATE state, int x, int y)
 {
-	static int lastY = 0, last2Y = 0;
+	static int lastY = 0, last2Y = 0, fastScroll = 0;
 	int selection = 0;
 
 	switch (state)
@@ -617,6 +617,9 @@
 			mUpdate = 1;
 		startY = lastY = last2Y = y;
 		scrollingSpeed = 0;
+
+		if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW)
+			fastScroll = 1;
 		break;
 
 	case TOUCH_DRAG:
@@ -631,7 +634,7 @@
 		}
 
 		// Fast scroll
-		if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW)
+		if(fastScroll)
 		{
 			int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH);
 			int totalSize = mList.size();
@@ -705,6 +708,7 @@
 
 	case TOUCH_RELEASE:
 		isHighlighted = false;
+		fastScroll = 0;
 		if (startSelection >= 0)
 		{
 			// We've selected an item!
diff --git a/minui/Android.mk b/minui/Android.mk
index d889587..704e541 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -31,8 +31,16 @@
   LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0
 endif
 
-ifneq ($(TARGET_RECOVERY_LCD_BACKLIGHT_PATH),)
-  LOCAL_CFLAGS += -DRECOVERY_LCD_BACKLIGHT_PATH=$(TARGET_RECOVERY_LCD_BACKLIGHT_PATH)
+ifneq ($(TW_BRIGHTNESS_PATH),)
+  LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=\"$(TW_BRIGHTNESS_PATH)\"
+endif
+ifneq ($(TW_MAX_BRIGHTNESS),)
+  LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=$(TW_MAX_BRIGHTNESS)
+else
+  LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=255
+endif
+ifneq ($(TW_NO_SCREEN_BLANK),)
+  LOCAL_CFLAGS += -DTW_NO_SCREEN_BLANK
 endif
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/minui/graphics.c b/minui/graphics.c
index ff39674..00fbb1e 100644
--- a/minui/graphics.c
+++ b/minui/graphics.c
@@ -437,15 +437,17 @@
 
 void gr_fb_blank(bool blank)
 {
-#ifdef RECOVERY_LCD_BACKLIGHT_PATH
+#if defined(TW_NO_SCREEN_BLANK) && defined(TW_BRIGHTNESS_PATH) && defined(TW_MAX_BRIGHTNESS)
     int fd;
+    char brightness[4];
+    snprintf(brightness, 4, "%03d", TW_MAX_BRIGHTNESS/2);
 
-    fd = open(RECOVERY_LCD_BACKLIGHT_PATH, O_RDWR);
+    fd = open(TW_BRIGHTNESS_PATH, O_RDWR);
     if (fd < 0) {
         perror("cannot open LCD backlight");
         return;
     }
-    write(fd, blank ? "000" : "127", 3);
+    write(fd, blank ? "000" : brightness, 3);
     close(fd);
 #else
     int ret;
diff --git a/minuitwrp/graphics.c b/minuitwrp/graphics.c
index fc34b6b..99f5841 100644
--- a/minuitwrp/graphics.c
+++ b/minuitwrp/graphics.c
@@ -69,6 +69,7 @@
 static GGLSurface gr_mem_surface;
 static unsigned gr_active_fb = 0;
 static unsigned double_buffering = 0;
+static int gr_is_curr_clr_opaque = 0;
 
 static int gr_fb_fd = -1;
 static int gr_vt_fd = -1;
@@ -288,6 +289,8 @@
     color[2] = ((b << 8) | b) + 1;
     color[3] = ((a << 8) | a) + 1;
     gl->color4xv(gl, color);
+
+    gr_is_curr_clr_opaque = (a == 255);
 }
 
 int gr_measureEx(const char *s, void* font)
@@ -463,8 +466,15 @@
 void gr_fill(int x, int y, int w, int h)
 {
     GGLContext *gl = gr_context;
+
+    if(gr_is_curr_clr_opaque)
+        gl->disable(gl, GGL_BLEND);
+
     gl->disable(gl, GGL_TEXTURE_2D);
     gl->recti(gl, x, y, x + w, y + h);
+
+    if(gr_is_curr_clr_opaque)
+        gl->enable(gl, GGL_BLEND);
 }
 
 void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) {
diff --git a/partition.cpp b/partition.cpp
index 541289a..95f6bca 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -361,10 +361,6 @@
 			Is_Storage = true;
 			Removable = true;
 			Wipe_Available_in_GUI = true;
-#ifndef RECOVERY_SDCARD_ON_DATA
-			Setup_AndSec();
-			Mount_Storage_Retry();
-#endif
 #endif
 		}
 #ifdef TW_INTERNAL_STORAGE_PATH
@@ -373,20 +369,12 @@
 			Is_Settings_Storage = true;
 			Storage_Path = EXPAND(TW_INTERNAL_STORAGE_PATH);
 			Wipe_Available_in_GUI = true;
-#ifndef RECOVERY_SDCARD_ON_DATA
-			Setup_AndSec();
-			Mount_Storage_Retry();
-#endif
 		}
 #else
 		if (Mount_Point == "/emmc" || Mount_Point == "/internal_sd" || Mount_Point == "/internal_sdcard") {
 			Is_Storage = true;
 			Is_Settings_Storage = true;
 			Wipe_Available_in_GUI = true;
-#ifndef RECOVERY_SDCARD_ON_DATA
-			Setup_AndSec();
-			Mount_Storage_Retry();
-#endif
 		}
 #endif
 	} else if (Is_Image(Fstab_File_System)) {
@@ -663,6 +651,7 @@
 	Backup_Path = Symlink_Mount_Point;
 	Make_Dir("/and-sec", true);
 	Recreate_AndSec_Folder();
+	Mount_Storage_Retry();
 }
 
 void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) {
@@ -1602,12 +1591,6 @@
 	tar.setsize(Backup_Size);
 	if (tar.createTarFork() != 0)
 		return false;
-	if (use_encryption)
-		Full_FileName += "000";
-	if (TWFunc::Get_File_Size(Full_FileName) == 0) {
-		LOGERR("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str());
-		return false;
-	}
 	return true;
 }
 
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 091ae32..04dbee9 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -96,6 +96,9 @@
 		for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
 			if ((*iter)->Is_Storage) {
 				(*iter)->Is_Settings_Storage = true;
+#ifndef RECOVERY_SDCARD_ON_DATA
+				(*iter)->Setup_AndSec();
+#endif
 				Found_Settings_Storage = true;
 				DataManager::SetValue("tw_settings_path", (*iter)->Storage_Path);
 				DataManager::SetValue("tw_storage_path", (*iter)->Storage_Path);