Messaging: We don't need to check for verbose logging everywhere

We can just do this in the actual method

Change-Id: I80e89b0ab97926749851628b1bd34e8cd9dc82f2
This commit is contained in:
Michael W
2025-05-18 09:18:48 +00:00
parent 8613b6bcc8
commit c4bbba9441
39 changed files with 293 additions and 547 deletions
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,9 +67,7 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
mAppWidgetId = intent.getIntExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
mAppWidgetManager = AppWidgetManager.getInstance(context);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetFactory intent: " + intent + "widget id: " + mAppWidgetId);
}
LogUtil.v(TAG, "BaseWidgetFactory intent: " + intent + "widget id: " + mAppWidgetId);
mIconSize = (int) context.getResources()
.getDimension(R.dimen.contact_icon_view_normal_size);
@@ -77,16 +75,12 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
@Override
public void onCreate() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onCreate");
}
LogUtil.v(TAG, "onCreate");
}
@Override
public void onDestroy() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onDestroy");
}
LogUtil.v(TAG, "onDestroy");
synchronized (sWidgetLock) {
if (mCursor != null && !mCursor.isClosed()) {
mCursor.close();
@@ -97,9 +91,7 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
@Override
public void onDataSetChanged() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onDataSetChanged");
}
LogUtil.v(TAG, "onDataSetChanged");
synchronized (sWidgetLock) {
if (mCursor != null) {
mCursor.close();
@@ -126,15 +118,11 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
public int getCount() {
synchronized (sWidgetLock) {
if (mCursor == null) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getCount: 0");
}
LogUtil.v(TAG, "getCount: 0");
return 0;
}
final int count = getItemCount();
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getCount: " + count);
}
LogUtil.v(TAG, "getCount: " + count);
mShouldShowViewMore = count < mCursor.getCount();
return count + (mShouldShowViewMore ? 1 : 0);
}
@@ -146,9 +134,7 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
* in the list.
*/
protected int getItemCount() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getItemCount: " + mCursor.getCount());
}
LogUtil.v(TAG, "getItemCount: " + mCursor.getCount());
return Math.min(mCursor.getCount(), MAX_ITEMS_TO_SHOW);
}
@@ -205,9 +191,7 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
}
private void onLoadComplete() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onLoadComplete");
}
LogUtil.v(TAG, "onLoadComplete");
final RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(),
getMainLayoutId());
mAppWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, remoteViews);
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,9 +52,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onReceive intent: " + intent + " for " + this.getClass());
}
LogUtil.v(TAG, "onReceive intent: " + intent + " for " + this.getClass());
final String action = intent.getAction();
// The base class AppWidgetProvider's onReceive handles the normal widget intents. Here
@@ -68,10 +66,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
if (appWidgetIds.length > 0) {
// We need to update all Bugle app widgets on the home screen.
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onReceive notifyAppWidgetViewDataChanged listId: " +
getListId() + " first widgetId: " + appWidgetIds[0]);
}
LogUtil.v(TAG, "onReceive notifyAppWidgetViewDataChanged listId: " +
getListId() + " first widgetId: " + appWidgetIds[0]);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, getListId());
}
} else {
@@ -95,9 +91,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
protected abstract void updateWidget(Context context, int appWidgetId);
private int getWidgetSize(AppWidgetManager appWidgetManager, int appWidgetId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize");
}
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize");
// Get the dimensions
final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
@@ -110,10 +104,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
final int rows = getCellsForSize(minHeight);
final int columns = getCellsForSize(minWidth);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize row: " + rows
+ " columns: " + columns);
}
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize row: " + rows
+ " columns: " + columns);
int size = SIZE_MEDIUM;
if (rows == 1) {
@@ -132,10 +124,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
// The size changed. We have to force the widget to rebuild the list.
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, getListId());
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize old size: " + savedSize
+ " new size saved: " + size);
}
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize old size: " + savedSize
+ " new size saved: " + size);
}
return size;
@@ -159,11 +149,8 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
int appWidgetId, Bundle newOptions) {
final int widgetSize = getWidgetSize(appWidgetManager, appWidgetId);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.onAppWidgetOptionsChanged new size: " +
widgetSize);
}
LogUtil.v(TAG, "BaseWidgetProvider.onAppWidgetOptionsChanged new size: " +
widgetSize);
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
}
@@ -177,10 +164,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.onDeleted");
}
LogUtil.v(TAG, "BaseWidgetProvider.onDeleted");
for (final int widgetId : appWidgetIds) {
deletePreferences(widgetId);
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,9 +62,7 @@ public class BugleWidgetProvider extends BaseWidgetProvider {
}
public static void rebuildWidget(final Context context, final int appWidgetId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BugleWidgetProvider.rebuildWidget appWidgetId: " + appWidgetId);
}
LogUtil.v(TAG, "BugleWidgetProvider.rebuildWidget appWidgetId: " + appWidgetId);
final RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_conversation_list);
PendingIntent clickIntent;
@@ -102,9 +100,7 @@ public class BugleWidgetProvider extends BaseWidgetProvider {
* update and reflect the changes
*/
public static void notifyConversationListChanged(final Context context) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "notifyConversationListChanged");
}
LogUtil.v(TAG, "notifyConversationListChanged");
final Intent intent = new Intent(ACTION_NOTIFY_CONVERSATIONS_CHANGED);
context.sendBroadcast(intent);
}
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,9 +51,7 @@ public class WidgetConversationListService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onGetViewFactory intent: " + intent);
}
LogUtil.v(TAG, "onGetViewFactory intent: " + intent);
return new WidgetConversationListFactory(getApplicationContext(), intent);
}
@@ -80,9 +78,7 @@ public class WidgetConversationListService extends RemoteViewsService {
*/
@Override
public RemoteViews getViewAt(int position) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getViewAt position: " + position);
}
LogUtil.v(TAG, "getViewAt position: " + position);
synchronized (sWidgetLock) {
// "View more conversations" view.
if (mCursor == null
@@ -129,10 +125,8 @@ public class WidgetConversationListService extends RemoteViewsService {
// Avatar
boolean includeAvatar;
final Bundle options = mAppWidgetManager.getAppWidgetOptions(mAppWidgetId);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getViewAt BugleWidgetProvider.WIDGET_SIZE_KEY: " +
options.getInt(BugleWidgetProvider.WIDGET_SIZE_KEY));
}
LogUtil.v(TAG, "getViewAt BugleWidgetProvider.WIDGET_SIZE_KEY: " +
options.getInt(BugleWidgetProvider.WIDGET_SIZE_KEY));
includeAvatar = options.getInt(BugleWidgetProvider.WIDGET_SIZE_KEY) ==
BugleWidgetProvider.SIZE_LARGE;
@@ -231,9 +225,7 @@ public class WidgetConversationListService extends RemoteViewsService {
*/
@Override
protected RemoteViews getViewMoreItemsView() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getViewMoreItemsView");
}
LogUtil.v(TAG, "getViewMoreItemsView");
final RemoteViews view = new RemoteViews(mContext.getPackageName(),
R.layout.widget_loading);
view.setTextViewText(
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,9 +56,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
*/
@Override
protected void updateWidget(final Context context, final int appWidgetId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
}
LogUtil.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
if (OsUtil.hasRequiredPermissions()) {
rebuildWidget(context, appWidgetId);
} else {
@@ -78,9 +76,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
}
public static void rebuildWidget(final Context context, final int appWidgetId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "WidgetConversationProvider.rebuildWidget appWidgetId: " + appWidgetId);
}
LogUtil.v(TAG, "WidgetConversationProvider.rebuildWidget appWidgetId: " + appWidgetId);
final RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_conversation);
PendingIntent clickIntent;
@@ -100,10 +96,8 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
clickIntent = uiIntents.getWidgetPendingIntentForConversationListActivity(context);
remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "WidgetConversationProvider.rebuildWidget appWidgetId: " +
appWidgetId + " going into configure state");
}
LogUtil.v(TAG, "WidgetConversationProvider.rebuildWidget appWidgetId: " +
appWidgetId + " going into configure state");
} else {
remoteViews.setViewVisibility(R.id.widget_label, View.VISIBLE);
remoteViews.setViewVisibility(R.id.message_list, View.VISIBLE);
@@ -164,9 +158,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
* update and reflect the changes
*/
public static void notifyMessagesChanged(final Context context, final String conversationId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "notifyMessagesChanged");
}
LogUtil.v(TAG, "notifyMessagesChanged");
final Intent intent = new Intent(ACTION_NOTIFY_MESSAGES_CHANGED);
intent.putExtra(UIIntents.UI_INTENT_EXTRA_CONVERSATION_ID, conversationId);
context.sendBroadcast(intent);
@@ -179,9 +171,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
*/
public static void notifyConversationDeleted(final Context context,
final String conversationId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "notifyConversationDeleted convId: " + conversationId);
}
LogUtil.v(TAG, "notifyConversationDeleted convId: " + conversationId);
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
for (final int appWidgetId : appWidgetManager.getAppWidgetIds(new ComponentName(context,
@@ -205,9 +195,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
*/
public static void notifyConversationRenamed(final Context context,
final String conversationId) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "notifyConversationRenamed convId: " + conversationId);
}
LogUtil.v(TAG, "notifyConversationRenamed convId: " + conversationId);
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
for (final int appWidgetId : appWidgetManager.getAppWidgetIds(new ComponentName(context,
@@ -224,9 +212,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
@Override
public void onReceive(final Context context, final Intent intent) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "WidgetConversationProvider onReceive intent: " + intent);
}
LogUtil.v(TAG, "WidgetConversationProvider onReceive intent: " + intent);
final String action = intent.getAction();
// The base class AppWidgetProvider's onReceive handles the normal widget intents. Here
@@ -239,9 +225,7 @@ public class WidgetConversationProvider extends BaseWidgetProvider {
this.getClass()));
if (appWidgetIds.length == 0) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "WidgetConversationProvider onReceive no widget ids");
}
LogUtil.v(TAG, "WidgetConversationProvider onReceive no widget ids");
return;
}
// Normally the conversation id points to a specific conversation and we only update
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
* Copyright (C) 2024-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,9 +61,7 @@ public class WidgetConversationService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onGetViewFactory intent: " + intent);
}
LogUtil.v(TAG, "onGetViewFactory intent: " + intent);
return new WidgetConversationFactory(getApplicationContext(), intent);
}
@@ -78,18 +76,14 @@ public class WidgetConversationService extends RemoteViewsService {
super(context, intent);
mConversationId = intent.getStringExtra(UIIntents.UI_INTENT_EXTRA_CONVERSATION_ID);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BugleFactory intent: " + intent + "widget id: " + mAppWidgetId);
}
LogUtil.v(TAG, "BugleFactory intent: " + intent + "widget id: " + mAppWidgetId);
mIconSize = (int) context.getResources()
.getDimension(R.dimen.contact_icon_view_normal_size);
}
@Override
public void onCreate() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onCreate");
}
LogUtil.v(TAG, "onCreate");
super.onCreate();
// If the conversation for this widget has been removed, we want to update the widget to
@@ -167,13 +161,11 @@ public class WidgetConversationService extends RemoteViewsService {
if (cursorCount > MAX_ITEMS_TO_SHOW) {
scrollToPosition += cursorCount - MAX_ITEMS_TO_SHOW;
}
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getViewAt position: " + originalPosition +
" computed position: " + position +
" scrollToPosition: " + scrollToPosition +
" cursorCount: " + cursorCount +
" MAX_ITEMS_TO_SHOW: " + MAX_ITEMS_TO_SHOW);
}
LogUtil.v(TAG, "getViewAt position: " + originalPosition +
" computed position: " + position +
" scrollToPosition: " + scrollToPosition +
" cursorCount: " + cursorCount +
" MAX_ITEMS_TO_SHOW: " + MAX_ITEMS_TO_SHOW);
intent.putExtra(UIIntents.UI_INTENT_EXTRA_MESSAGE_POSITION, scrollToPosition);
if (message.hasAttachments()) {
@@ -214,10 +206,8 @@ public class WidgetConversationService extends RemoteViewsService {
// Avatar
final Bundle options = mAppWidgetManager.getAppWidgetOptions(mAppWidgetId);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getViewAt BugleWidgetProvider.WIDGET_SIZE_KEY: " +
options.getInt(BugleWidgetProvider.WIDGET_SIZE_KEY));
}
LogUtil.v(TAG, "getViewAt BugleWidgetProvider.WIDGET_SIZE_KEY: " +
options.getInt(BugleWidgetProvider.WIDGET_SIZE_KEY));
boolean includeAvatar = options.getInt(BugleWidgetProvider.WIDGET_SIZE_KEY)
== BugleWidgetProvider.SIZE_LARGE;
@@ -460,9 +450,7 @@ public class WidgetConversationService extends RemoteViewsService {
*/
@Override
protected RemoteViews getViewMoreItemsView() {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "getViewMoreConversationsView");
}
LogUtil.v(TAG, "getViewMoreConversationsView");
final RemoteViews view = new RemoteViews(mContext.getPackageName(),
R.layout.widget_loading);
view.setTextViewText(