summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryoungtaecha <youngtaecha@google.com>2023-03-20 12:08:21 +0000
committeryoungtaecha <youngtaecha@google.com>2023-03-28 01:49:08 +0000
commit539c95d378f57404b170c6697746570ead97e36b (patch)
treee3194afa83ef4261c727ac24ff8add2964e1e8f8
parent013a6b15b43cd28c90521281b1b598cf915fe2ad (diff)
downloadCellBroadcastReceiver-539c95d378f57404b170c6697746570ead97e36b.tar.gz
Support no title on alert dialog and notification
Bug: 273321099 Test: Manual - Verify not showing the title of alert dilaog. Test: atest CellBroadcastReceiverOemUnitTests Change-Id: Ifb75758c797c6e68028ae667284189e3c3d11b50
-rw-r--r--res/values-mcc334/config.xml2
-rw-r--r--res/values/config.xml3
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java24
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java15
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java7
-rw-r--r--tests/compliancetests/assets/emergency_alert_channels.json54
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java53
-rw-r--r--tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListActivityTest.java41
8 files changed, 137 insertions, 62 deletions
diff --git a/res/values-mcc334/config.xml b/res/values-mcc334/config.xml
index d7b405190..b0075ae0a 100644
--- a/res/values-mcc334/config.xml
+++ b/res/values-mcc334/config.xml
@@ -107,5 +107,7 @@
<!-- always overriding dnd settings: Play alert sound in full volume regardless DND is on. Applied to all channels -->
<bool name="override_dnd">true</bool>
+ <!-- Whether to show the alert dialog title -->
+ <bool name="show_alert_title">false</bool>
</resources>
diff --git a/res/values/config.xml b/res/values/config.xml
index a4e0a00bc..f778e37f0 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -293,6 +293,9 @@
<!-- Whether enabling capture message screen -->
<bool name="disable_capture_alert_dialog">false</bool>
+ <!-- Whether to show the alert dialog title -->
+ <bool name="show_alert_title">true</bool>
+
<!-- Pulsation pattern to be used as the default for the alert.
The 1st parameter is the color to be changed.
The 2nd parameter indicates how long the pulsation to last in ms. It must be positive.
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
index dc2db5fce..d3e7227f7 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
@@ -588,7 +588,7 @@ public class CellBroadcastAlertDialog extends Activity {
}
}
- if (getResources().getBoolean(R.bool.disable_capture_alert_dialog)) {
+ if (res.getBoolean(R.bool.disable_capture_alert_dialog)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
startPulsatingAsNeeded(channelManager
@@ -882,17 +882,21 @@ public class CellBroadcastAlertDialog extends Activity {
languageCode = message.getLanguageCode();
}
- String title = overrideTranslation(titleId, res, languageCode);
- TextView titleTextView = findViewById(R.id.alertTitle);
+ if (CellBroadcastSettings.getResourcesForDefaultSubId(context).getBoolean(
+ R.bool.show_alert_title)) {
+ String title = overrideTranslation(titleId, res, languageCode);
+ TextView titleTextView = findViewById(R.id.alertTitle);
- if (titleTextView != null) {
- String timeFormat = res.getString(R.string.date_time_format);
- if (!TextUtils.isEmpty(timeFormat)) {
- titleTextView.setSingleLine(false);
- title += "\n" + new SimpleDateFormat(timeFormat).format(message.getReceivedTime());
+ if (titleTextView != null) {
+ String timeFormat = res.getString(R.string.date_time_format);
+ if (!TextUtils.isEmpty(timeFormat)) {
+ titleTextView.setSingleLine(false);
+ title += "\n" + new SimpleDateFormat(timeFormat).format(
+ message.getReceivedTime());
+ }
+ setTitle(title);
+ titleTextView.setText(title);
}
- setTitle(title);
- titleTextView.setText(title);
}
TextView textView = findViewById(R.id.message);
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index 526c43c2a..833ab0b09 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -845,15 +845,18 @@ public class CellBroadcastAlertService extends Service {
// increment unread alert count (decremented when user dismisses alert dialog)
int unreadCount = messageList.size();
- if (unreadCount > 1) {
+ if (unreadCount > 1 || res.getBoolean(R.bool.disable_capture_alert_dialog)) {
// use generic count of unread broadcasts if more than one unread
- builder.setContentTitle(context.getString(R.string.notification_multiple_title));
+ if (res.getBoolean(R.bool.show_alert_title)) {
+ builder.setContentTitle(context.getString(R.string.notification_multiple_title));
+ }
builder.setContentText(context.getString(R.string.notification_multiple, unreadCount));
} else {
- builder.setContentTitle(channelName)
- .setContentText(messageBody)
- .setStyle(new Notification.BigTextStyle()
- .bigText(messageBody));
+ if (res.getBoolean(R.bool.show_alert_title)) {
+ builder.setContentTitle(channelName);
+ }
+ builder.setContentText(messageBody)
+ .setStyle(new Notification.BigTextStyle().bigText(messageBody));
}
notificationManager.notify(NOTIFICATION_ID, builder.build());
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
index 938daf752..7fc0b0be8 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
@@ -32,14 +32,12 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.Loader;
-import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.Telephony;
import android.telephony.SmsCbMessage;
-import android.telephony.SubscriptionManager;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
@@ -98,9 +96,8 @@ public class CellBroadcastListActivity extends CollapsingToolbarBaseActivity {
mListFragment).commit();
}
- Resources res = CellBroadcastSettings.getResources(getApplicationContext(),
- SubscriptionManager.getDefaultSubscriptionId());
- if (res.getBoolean(R.bool.disable_capture_alert_dialog)) {
+ if (CellBroadcastSettings.getResourcesForDefaultSubId(getApplicationContext()).getBoolean(
+ R.bool.disable_capture_alert_dialog)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
diff --git a/tests/compliancetests/assets/emergency_alert_channels.json b/tests/compliancetests/assets/emergency_alert_channels.json
index 0355b094d..87d99e0a0 100644
--- a/tests/compliancetests/assets/emergency_alert_channels.json
+++ b/tests/compliancetests/assets/emergency_alert_channels.json
@@ -1882,77 +1882,77 @@
},
"mexico_telefonica": {
"50": {
- "title": "Operator warning",
+ "title": "",
"default_value": "false",
"toggle_avail": "true",
"alert_type":"notification"
},
"4370": {
- "title": "Alert Messages Level 1",
+ "title": "",
"default_value": "true",
"toggle_avail": "false"
},
"4383": {
- "title": "Alert Messages Level 1",
+ "title": "",
"default_value": "true",
"toggle_avail": "false"
},
"919": {
- "title": "Alert Messages Level 1",
+ "title": "",
"default_value": "true",
"toggle_avail": "false"
},
"4371": {
- "title": "Alert Messages Level 2",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4372"
},
"4384": {
- "title": "Alert Messages Level 2",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4385"
},
"4373": {
- "title": "Alert Messages Level 3",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4378"
},
"4386": {
- "title": "Alert Messages Level 3",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4391"
},
"4379": {
- "title": "Amber Alert Messages in Spanish",
+ "title": "",
"default_value": "true",
"toggle_avail": "true"
},
"4380": {
- "title": "Test Alert Messages in Spanish",
+ "title": "",
"default_value": "false",
"toggle_avail": "false"
},
"519": {
- "title": "Test Alert Messages in Spanish",
+ "title": "",
"default_value": "false",
"toggle_avail": "false"
},
"4381": {
- "title": "Exercise Alert Messages in Spanish",
+ "title": "",
"default_value": "true",
"toggle_avail": "true"
},
"6400": {
- "title": "Information Messages in Spanish",
+ "title": "",
"default_value": "true",
"toggle_avail": "true"
},
"4396": {
- "title": "Reserved for future deployments",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4399"
@@ -4736,71 +4736,71 @@
},
"mexico": {
"4370": {
- "title": "Alert Messages Level 1",
+ "title": "",
"default_value": "true",
"toggle_avail": "false"
},
"4383": {
- "title": "Alert Messages Level 1",
+ "title": "",
"default_value": "true",
"toggle_avail": "false"
},
"919": {
- "title": "Alert Messages Level 1",
+ "title": "",
"default_value": "true",
"toggle_avail": "false"
},
"4371": {
- "title": "Alert Messages Level 2",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4372"
},
"4384": {
- "title": "Alert Messages Level 2",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4385"
},
"4373": {
- "title": "Alert Messages Level 3",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4378"
},
"4386": {
- "title": "Alert Messages Level 3",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4391"
},
"4379": {
- "title": "Amber Alert Messages in Spanish",
+ "title": "",
"default_value": "true",
"toggle_avail": "true"
},
"4380": {
- "title": "Test Alert Messages in Spanish",
+ "title": "",
"default_value": "false",
"toggle_avail": "false"
},
"519": {
- "title": "Test Alert Messages in Spanish",
+ "title": "",
"default_value": "false",
"toggle_avail": "false"
},
"4381": {
- "title": "Exercise Alert Messages in Spanish",
+ "title": "",
"default_value": "true",
"toggle_avail": "true"
},
"6400": {
- "title": "Information Messages in Spanish",
+ "title": "",
"default_value": "true",
"toggle_avail": "true"
},
"4396": {
- "title": "Reserved for future deployments",
+ "title": "",
"default_value": "true",
"toggle_avail": "true",
"end_channel": "4399"
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
index 57df4c83b..e11acdbb2 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java
@@ -47,11 +47,13 @@ import android.os.PowerManager;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import android.text.TextUtils;
import android.util.Singleton;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -185,6 +187,8 @@ public class CellBroadcastAlertDialogTest extends
}
public void testTitleAndMessageText() throws Throwable {
+ doReturn(true).when(mContext.getResources()).getBoolean(R.bool.show_alert_title);
+
startActivity();
waitForMs(100);
@@ -204,6 +208,14 @@ public class CellBroadcastAlertDialogTest extends
stopActivity();
}
+ public void testNoTitle() throws Throwable {
+ doReturn(false).when(mContext.getResources()).getBoolean(R.bool.show_alert_title);
+ startActivity();
+ waitForMs(100);
+ assertTrue(TextUtils.isEmpty(((TextView) getActivity().findViewById(
+ com.android.cellbroadcastreceiver.R.id.alertTitle)).getText()));
+ stopActivity();
+ }
public void waitUntilAssertPasses(Runnable r, long maxWaitMs) {
long waitTime = 0;
@@ -222,6 +234,10 @@ public class CellBroadcastAlertDialogTest extends
}
public void testAddToNotification() throws Throwable {
+ doReturn(true).when(mContext.getResources()).getBoolean(R.bool.show_alert_title);
+ doReturn(false).when(mContext.getResources()).getBoolean(
+ R.bool.disable_capture_alert_dialog);
+
startActivity();
waitForMs(100);
leaveActivity();
@@ -251,6 +267,25 @@ public class CellBroadcastAlertDialogTest extends
field.set(null, null);
}
+ public void testAddToNotificationWithDifferentConfiguration() throws Throwable {
+ doReturn(false).when(mContext.getResources()).getBoolean(R.bool.show_alert_title);
+ doReturn(true).when(mContext.getResources()).getBoolean(
+ R.bool.disable_capture_alert_dialog);
+
+ startActivity();
+ waitForMs(100);
+ leaveActivity();
+ waitForMs(100);
+ verify(mMockedNotificationManager, times(1)).notify(mInt.capture(),
+ mNotification.capture());
+ Bundle b = mNotification.getValue().extras;
+
+ assertEquals(1, (int) mInt.getValue());
+ assertTrue(TextUtils.isEmpty(b.getCharSequence(Notification.EXTRA_TITLE)));
+ verify(mContext.getResources(), times(1)).getString(mInt.capture(), anyInt());
+ assertEquals(R.string.notification_multiple, (int) mInt.getValue());
+ }
+
public void testDoNotAddToNotificationOnStop() throws Throwable {
startActivity();
waitForMs(100);
@@ -655,4 +690,22 @@ public class CellBroadcastAlertDialogTest extends
assertNull(activity.findViewById(R.id.pictogramImage));
}
+ public void testOnCreate() throws Throwable {
+ doReturn(false).when(mContext.getResources()).getBoolean(
+ R.bool.disable_capture_alert_dialog);
+ CellBroadcastAlertDialog activity = startActivity();
+ int flags = activity.getWindow().getAttributes().flags;
+ assertEquals((flags & WindowManager.LayoutParams.FLAG_SECURE), 0);
+ stopActivity();
+ }
+
+ public void testOnCreateWithCaptureRestriction() throws Throwable {
+ doReturn(true).when(mContext.getResources()).getBoolean(
+ R.bool.disable_capture_alert_dialog);
+ CellBroadcastAlertDialog activity = startActivity();
+ int flags = activity.getWindow().getAttributes().flags;
+ assertEquals((flags & WindowManager.LayoutParams.FLAG_SECURE),
+ WindowManager.LayoutParams.FLAG_SECURE);
+ stopActivity();
+ }
}
diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListActivityTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListActivityTest.java
index 4a06e5aee..d6d3032d8 100644
--- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListActivityTest.java
+++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastListActivityTest.java
@@ -50,6 +50,7 @@ import static org.mockito.Mockito.verify;
import android.app.Fragment;
import android.app.NotificationManager;
import android.content.Context;
+import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.os.Bundle;
@@ -58,6 +59,7 @@ import android.os.Looper;
import android.os.UserManager;
import android.provider.Telephony;
import android.telephony.SmsCbMessage;
+import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.view.ActionMode;
import android.view.Menu;
@@ -105,6 +107,11 @@ public class CellBroadcastListActivityTest extends
injectSystemService(UserManager.class, mMockUserManager);
doReturn(true).when(mMockUserManager).isAdminUser();
+
+ SubscriptionManager mockSubscriptionManager = mock(SubscriptionManager.class);
+ injectSystemService(SubscriptionManager.class, mockSubscriptionManager);
+ SubscriptionInfo mockSubInfo = mock(SubscriptionInfo.class);
+ doReturn(mockSubInfo).when(mockSubscriptionManager).getActiveSubscriptionInfo(anyInt());
}
@After
@@ -117,7 +124,21 @@ public class CellBroadcastListActivityTest extends
}
public void testOnCreate() throws Throwable {
- startActivity();
+ Resources spyRes = mContext.getResources();
+ doReturn(false).when(spyRes).getBoolean(R.bool.disable_capture_alert_dialog);
+ CellBroadcastListActivity activity = startActivity();
+ int flags = activity.getWindow().getAttributes().flags;
+ assertEquals((flags & WindowManager.LayoutParams.FLAG_SECURE), 0);
+ stopActivity();
+ }
+
+ public void testOnCreateWithCaptureRestriction() throws Throwable {
+ Resources spyRes = mContext.getResources();
+ doReturn(true).when(spyRes).getBoolean(R.bool.disable_capture_alert_dialog);
+ CellBroadcastListActivity activity = startActivity();
+ int flags = activity.getWindow().getAttributes().flags;
+ assertEquals((flags & WindowManager.LayoutParams.FLAG_SECURE),
+ WindowManager.LayoutParams.FLAG_SECURE);
stopActivity();
}
@@ -635,18 +656,14 @@ public class CellBroadcastListActivityTest extends
// Watch layout misses checkbox.
// mockListItemView.findViewById(R.id.checkBox) returns null as default setting up this
// usecase.
- SubscriptionManager mockSubscriptionManager = mock(SubscriptionManager.class);
- Context mockContext = mock(Context.class);
- doReturn(mockSubscriptionManager).when(mockContext)
- .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
CellBroadcastListItem mockListItemView = mock(CellBroadcastListItem.class);
ListView mockListView = mock(ListView.class);
MatrixCursor data = makeTestCursor();
data.moveToFirst();
- CellBroadcastCursorAdapter adapter = new CellBroadcastCursorAdapter(mockContext,
+ CellBroadcastCursorAdapter adapter = new CellBroadcastCursorAdapter(mContext,
mockListView);
- adapter.bindView(mockListItemView, mockContext, data);
+ adapter.bindView(mockListItemView, mContext, data);
ArgumentCaptor<SmsCbMessage> messageCaptor = ArgumentCaptor.forClass(SmsCbMessage.class);
verify(mockListItemView).bind(messageCaptor.capture());
@@ -654,25 +671,21 @@ public class CellBroadcastListActivityTest extends
}
public void testCursorAdaptorBindView() {
- SubscriptionManager mockSubscriptionManager = mock(SubscriptionManager.class);
- Context mockContext = mock(Context.class);
- doReturn(mockSubscriptionManager).when(mockContext)
- .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
CellBroadcastListItem mockListItemView = mock(CellBroadcastListItem.class);
ListView mockListView = mock(ListView.class);
CheckedTextView mockCheckbox = mock(CheckedTextView.class);
doReturn(mockCheckbox).when(mockListItemView).findViewById(R.id.checkBox);
MatrixCursor data = makeTestCursor();
data.moveToFirst();
- CellBroadcastCursorAdapter adapter = new CellBroadcastCursorAdapter(mockContext,
+ CellBroadcastCursorAdapter adapter = new CellBroadcastCursorAdapter(mContext,
mockListView);
adapter.setIsActionMode(true);
- adapter.bindView(mockListItemView, mockContext, data);
+ adapter.bindView(mockListItemView, mContext, data);
verify(mockCheckbox).setVisibility(View.VISIBLE);
adapter.setIsActionMode(false);
- adapter.bindView(mockListItemView, mockContext, data);
+ adapter.bindView(mockListItemView, mContext, data);
verify(mockCheckbox).setVisibility(View.GONE);
}
}