Program: 80584
Project: 80584
Buggy source:
static void updateAppWidget(Context context,AppWidgetManager appWidgetManager,int appWidgetId,Bundle options){
  Tools.HangarLog("String_Node_Str");
  prefs=new PrefsGet(context.getSharedPreferences("String_Node_Str",Context.MODE_PRIVATE));
  SharedPreferences mPrefs=prefs.prefsGet();
  int rowLayout=R.layout.apps_widget_row;
  int itemLayout=R.layout.apps_widget_item;
  int itemHeight=ICON_MEDIUM_HEIGHT;
  int itemWidth=ICON_MEDIUM_WIDTH;
  int iconSize=Integer.parseInt(mPrefs.getString(Settings.ICON_SIZE_PREFERENCE,Integer.toString(Settings.ICON_SIZE_DEFAULT)));
switch (iconSize) {
case SMALL_ICONS:
    rowLayout=R.layout.apps_widget_row_small;
  itemHeight=ICON_SMALL_HEIGHT;
itemWidth=ICON_SMALL_WIDTH;
break;
case LARGE_ICONS:
rowLayout=R.layout.apps_widget_row_large;
itemHeight=ICON_LARGE_HEIGHT;
itemWidth=ICON_LARGE_WIDTH;
break;
}
boolean appsNoByWidgetSize=mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE,Settings.APPS_BY_WIDGET_SIZE_DEFAULT);
int appsNoH;
int appsNoW;
boolean autoHeight=true;
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH));
appsNoH=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT) - ICON_ROW_BUFFER) / itemHeight);
appsNoW=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) - ICON_ROW_BUFFER) / itemWidth);
Tools.HangarLog("String_Node_Str" + appsNoH + "String_Node_Str"+ appsNoW);
if (appsNoH == 0) {
appsNoH=1;
autoHeight=false;
}
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
appsNoH=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) - ICON_ROW_BUFFER) / itemHeight);
float widgetHeight=(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) - ICON_ROW_BUFFER);
if (appsNoH == 0) {
if (widgetHeight > 0) {
Tools.HangarLog("String_Node_Str");
rowLayout=R.layout.apps_widget_row_small;
itemWidth=ICON_SMALL_WIDTH;
}
appsNoH=1;
autoHeight=false;
}
appsNoW=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH) - ICON_ROW_BUFFER) / itemWidth);
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoW);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE,Integer.toString(Settings.STATS_WIDGET_APPSNO_LS_DEFAULT)));
}
Tools.HangarLog("String_Node_Str");
}
 else {
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoH);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_PREFERENCE,Integer.toString(Settings.STATS_WIDGET_APPSNO_DEFAULT)));
}
}
int getBackgroundColor=mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE,Settings.BACKGROUND_COLOR_DEFAULT);
int getColor=mPrefs.getInt(Settings.ICON_COLOR_PREFERENCE,Settings.ICON_COLOR_DEFAULT);
RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.apps_widget);
views.removeAllViews(R.id.viewCont);
PackageManager pkgm=context.getPackageManager();
if (db == null) {
db=new TasksDataSource(context);
db.open();
}
ArrayList<Tools.TaskInfo> appList=new ArrayList<Tools.TaskInfo>();
int gridSize=(appsNoH * appsNoW);
int numOfIcons=(appsNoH * appsNoW);
int lookUpNum=numOfIcons + 3;
if (autoHeight && !appsNoByWidgetSize) {
numOfIcons=appsNoW;
lookUpNum=appsNoW + 3;
}
List<TasksModel> tasks=db.getAllTasks((lookUpNum < MAX_DB_LOOKUPS) ? MAX_DB_LOOKUPS : lookUpNum);
for (TasksModel taskM : tasks) {
String taskPackage=taskM.getPackageName();
if (isBlacklisted(taskPackage)) continue;
Tools.TaskInfo dbTask=new Tools.TaskInfo();
dbTask.appName=taskM.getName();
dbTask.packageName=taskPackage;
dbTask.className=taskM.getClassName();
dbTask.launches=taskM.getLaunches();
dbTask.totalseconds=taskM.getSeconds();
try {
pkgm.getApplicationInfo(dbTask.packageName,0);
}
 catch (PackageManager.NameNotFoundException e) {
db.deleteTask(taskM);
continue;
}
try {
Intent intent=pkgm.getLaunchIntentForPackage(taskPackage);
if (intent == null) throw new PackageManager.NameNotFoundException();
}
 catch (PackageManager.NameNotFoundException e) {
db.deleteTask(taskM);
}
appList.add(dbTask);
}
String taskPackage=context.getPackageName();
boolean isColorized=mPrefs.getBoolean(Settings.COLORIZE_PREFERENCE,Settings.COLORIZE_DEFAULT);
boolean weightedRecents=mPrefs.getBoolean(Settings.WEIGHTED_RECENTS_PREFERENCE,Settings.WEIGHTED_RECENTS_DEFAULT);
int weightPriority=Integer.parseInt(mPrefs.getString(Settings.WEIGHT_PRIORITY_PREFERENCE,Integer.toString(Settings.WEIGHT_PRIORITY_DEFAULT)));
if (weightedRecents) {
Tools.HangarLog("String_Node_Str" + weightPriority);
appList=Tools.reorderTasks(appList,db,weightPriority);
}
RemoteViews row=new RemoteViews(context.getPackageName(),rowLayout);
row.setInt(R.id.viewRow,"String_Node_Str",getBackgroundColor);
if (autoHeight && !appsNoByWidgetSize) {
appsNoW=(int)Math.ceil((double)appsNoW / appsNoH);
Tools.HangarLog("String_Node_Str" + appsNoW);
}
int filledConts=0;
int filledRows=1;
Tools.HangarLog("String_Node_Str" + appsNoW + "String_Node_Str"+ appList.size()+ "String_Node_Str"+ numOfIcons);
for (int i=0; i <= gridSize; i++) {
RemoteViews item=new RemoteViews(context.getPackageName(),itemLayout);
if (filledConts == appsNoW || i == (gridSize)) {
Tools.HangarLog("String_Node_Str" + i + "String_Node_Str"+ filledConts);
views.addView(R.id.viewCont,row);
if (filledRows < appsNoH && (filledConts < numOfIcons && appList.size() > i)) {
row=new RemoteViews(context.getPackageName(),rowLayout);
row.setInt(R.id.viewRow,"String_Node_Str",getBackgroundColor);
filledConts=0;
filledRows++;
}
 else {
break;
}
}
filledConts+=1;
int resID=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
int contID=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
if (i >= numOfIcons || i >= appList.size()) {
item.setViewVisibility(contID,View.INVISIBLE);
row.addView(R.id.viewRow,item);
continue;
}
Tools.HangarLog("String_Node_Str" + filledConts + "String_Node_Str"+ appList.get(i).appName+ "String_Node_Str");
Drawable taskIcon, d;
try {
ApplicationInfo appInfo=pkgm.getApplicationInfo(appList.get(i).packageName,0);
taskIcon=appInfo.loadIcon(pkgm);
}
 catch (Exception e) {
Tools.HangarLog("String_Node_Str" + e);
continue;
}
if (isColorized) {
d=new BitmapDrawable(ColorHelper.getColoredBitmap(taskIcon,getColor));
}
 else {
d=taskIcon;
}
Bitmap bmpIcon=((BitmapDrawable)d).getBitmap();
item.setImageViewBitmap(resID,bmpIcon);
Intent intent;
PackageManager manager=context.getPackageManager();
try {
intent=manager.getLaunchIntentForPackage(appList.get(i).packageName);
if (intent == null) {
Tools.HangarLog("String_Node_Str" + appList.get(i).packageName + "String_Node_Str"+ appList.get(i).className);
filledConts--;
item.setViewVisibility(contID,View.GONE);
row.addView(R.id.viewRow,item);
throw new PackageManager.NameNotFoundException();
}
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction("String_Node_Str" + (i));
PendingIntent activity=PendingIntent.getActivity(context,appWidgetId,intent,PendingIntent.FLAG_CANCEL_CURRENT);
item.setOnClickPendingIntent(contID,activity);
}
 catch (PackageManager.NameNotFoundException e) {
numOfIcons++;
}
row.addView(R.id.viewRow,item);
}
appWidgetManager.updateAppWidget(appWidgetId,views);
}

Fixed version (ground truth):
static void updateAppWidget(Context context,AppWidgetManager appWidgetManager,int appWidgetId,Bundle options){
  Tools.HangarLog("String_Node_Str");
  prefs=new PrefsGet(context.getSharedPreferences("String_Node_Str",Context.MODE_PRIVATE));
  SharedPreferences mPrefs=prefs.prefsGet();
  int rowLayout=R.layout.apps_widget_row;
  int itemLayout=R.layout.apps_widget_item;
  int itemHeight=ICON_MEDIUM_HEIGHT;
  int itemWidth=ICON_MEDIUM_WIDTH;
  int iconSize=Integer.parseInt(mPrefs.getString(Settings.ICON_SIZE_PREFERENCE,Integer.toString(Settings.ICON_SIZE_DEFAULT)));
switch (iconSize) {
case SMALL_ICONS:
    rowLayout=R.layout.apps_widget_row_small;
  itemHeight=ICON_SMALL_HEIGHT;
itemWidth=ICON_SMALL_WIDTH;
break;
case LARGE_ICONS:
rowLayout=R.layout.apps_widget_row_large;
itemHeight=ICON_LARGE_HEIGHT;
itemWidth=ICON_LARGE_WIDTH;
break;
}
boolean appsNoByWidgetSize=mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE,Settings.APPS_BY_WIDGET_SIZE_DEFAULT);
int appsNoH;
int appsNoW;
boolean autoHeight=true;
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH));
appsNoH=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT) - ICON_ROW_BUFFER) / itemHeight);
appsNoW=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) - ICON_ROW_BUFFER) / itemWidth);
Tools.HangarLog("String_Node_Str" + appsNoH + "String_Node_Str"+ appsNoW);
if (appsNoH == 0) {
appsNoH=1;
autoHeight=false;
}
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
appsNoH=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) - ICON_ROW_BUFFER) / itemHeight);
float widgetHeight=(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) - ICON_ROW_BUFFER);
if (appsNoH == 0) {
if (widgetHeight > 0) {
Tools.HangarLog("String_Node_Str");
rowLayout=R.layout.apps_widget_row_small;
itemWidth=ICON_SMALL_WIDTH;
}
appsNoH=1;
autoHeight=false;
}
appsNoW=(int)Math.floor((options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH) - ICON_ROW_BUFFER) / itemWidth);
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoW);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE,Integer.toString(Settings.STATS_WIDGET_APPSNO_LS_DEFAULT)));
}
Tools.HangarLog("String_Node_Str");
}
 else {
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoH);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_PREFERENCE,Integer.toString(Settings.STATS_WIDGET_APPSNO_DEFAULT)));
}
}
int getBackgroundColor=mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE,Settings.BACKGROUND_COLOR_DEFAULT);
int getColor=mPrefs.getInt(Settings.ICON_COLOR_PREFERENCE,Settings.ICON_COLOR_DEFAULT);
RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.apps_widget);
views.removeAllViews(R.id.viewCont);
PackageManager pkgm=context.getPackageManager();
if (db == null) {
db=new TasksDataSource(context);
db.open();
}
ArrayList<Tools.TaskInfo> appList=new ArrayList<Tools.TaskInfo>();
int gridSize=(appsNoH * appsNoW);
int numOfIcons=(appsNoH * appsNoW);
int lookUpNum=numOfIcons + 3;
if (autoHeight && !appsNoByWidgetSize) {
numOfIcons=appsNoW;
lookUpNum=appsNoW + 3;
}
List<TasksModel> tasks=db.getAllTasks((lookUpNum < MAX_DB_LOOKUPS) ? MAX_DB_LOOKUPS : lookUpNum);
for (TasksModel taskM : tasks) {
String taskPackage=taskM.getPackageName();
if (isBlacklisted(taskPackage)) continue;
Tools.TaskInfo dbTask=new Tools.TaskInfo();
dbTask.appName=taskM.getName();
dbTask.packageName=taskPackage;
dbTask.className=taskM.getClassName();
dbTask.launches=taskM.getLaunches();
dbTask.totalseconds=taskM.getSeconds();
try {
pkgm.getApplicationInfo(dbTask.packageName,0);
}
 catch (PackageManager.NameNotFoundException e) {
db.deleteTask(taskM);
continue;
}
try {
Intent intent=pkgm.getLaunchIntentForPackage(taskPackage);
if (intent == null) throw new PackageManager.NameNotFoundException();
}
 catch (PackageManager.NameNotFoundException e) {
db.deleteTask(taskM);
}
appList.add(dbTask);
}
String taskPackage=context.getPackageName();
boolean isColorized=mPrefs.getBoolean(Settings.COLORIZE_PREFERENCE,Settings.COLORIZE_DEFAULT);
boolean weightedRecents=mPrefs.getBoolean(Settings.WEIGHTED_RECENTS_PREFERENCE,Settings.WEIGHTED_RECENTS_DEFAULT);
int weightPriority=Integer.parseInt(mPrefs.getString(Settings.WEIGHT_PRIORITY_PREFERENCE,Integer.toString(Settings.WEIGHT_PRIORITY_DEFAULT)));
if (weightedRecents) {
Tools.HangarLog("String_Node_Str" + weightPriority);
appList=Tools.reorderTasks(appList,db,weightPriority);
}
RemoteViews row=new RemoteViews(context.getPackageName(),rowLayout);
row.setInt(R.id.viewRow,"String_Node_Str",getBackgroundColor);
if (autoHeight && !appsNoByWidgetSize) {
appsNoW=(int)Math.ceil((double)appsNoW / appsNoH);
Tools.HangarLog("String_Node_Str" + appsNoW);
}
int filledConts=0;
int filledRows=1;
Tools.HangarLog("String_Node_Str" + appsNoW + "String_Node_Str"+ appList.size()+ "String_Node_Str"+ numOfIcons);
for (int i=0; i <= gridSize; i++) {
RemoteViews item=new RemoteViews(context.getPackageName(),itemLayout);
if (filledConts == appsNoW || (i == gridSize)) {
Tools.HangarLog("String_Node_Str" + i + "String_Node_Str"+ filledConts);
views.addView(R.id.viewCont,row);
if (i >= numOfIcons && !appsNoByWidgetSize) break;
if (filledRows < appsNoH && (filledConts < numOfIcons && appList.size() > i)) {
row=new RemoteViews(context.getPackageName(),rowLayout);
row.setInt(R.id.viewRow,"String_Node_Str",getBackgroundColor);
filledConts=0;
filledRows++;
}
 else {
break;
}
}
filledConts+=1;
int resID=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
int contID=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
if (i >= numOfIcons || i >= appList.size()) {
item.setViewVisibility(contID,View.INVISIBLE);
row.addView(R.id.viewRow,item);
continue;
}
Tools.HangarLog("String_Node_Str" + filledConts + "String_Node_Str"+ appList.get(i).appName+ "String_Node_Str");
Drawable taskIcon, d;
try {
ApplicationInfo appInfo=pkgm.getApplicationInfo(appList.get(i).packageName,0);
taskIcon=appInfo.loadIcon(pkgm);
}
 catch (Exception e) {
Tools.HangarLog("String_Node_Str" + e);
continue;
}
if (isColorized) {
d=new BitmapDrawable(ColorHelper.getColoredBitmap(taskIcon,getColor));
}
 else {
d=taskIcon;
}
Bitmap bmpIcon=((BitmapDrawable)d).getBitmap();
item.setImageViewBitmap(resID,bmpIcon);
Intent intent;
PackageManager manager=context.getPackageManager();
try {
intent=manager.getLaunchIntentForPackage(appList.get(i).packageName);
if (intent == null) {
Tools.HangarLog("String_Node_Str" + appList.get(i).packageName + "String_Node_Str"+ appList.get(i).className);
filledConts--;
item.setViewVisibility(contID,View.GONE);
row.addView(R.id.viewRow,item);
throw new PackageManager.NameNotFoundException();
}
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction("String_Node_Str" + (i));
PendingIntent activity=PendingIntent.getActivity(context,appWidgetId,intent,PendingIntent.FLAG_CANCEL_CURRENT);
item.setOnClickPendingIntent(contID,activity);
}
 catch (PackageManager.NameNotFoundException e) {
numOfIcons++;
}
row.addView(R.id.viewRow,item);
}
appWidgetManager.updateAppWidget(appWidgetId,views);
}