summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Aaron Huang <huangaaron@google.com> 2023-02-18 00:21:26 +0800
committer Aaron Huang <huangaaron@google.com> 2023-02-17 17:05:57 +0000
commit1a2de3b43a02f1fa4ee3109a741f165cd33feb22 (patch)
tree0681348cc15838e9c4dd5905146e1367b68a3672
parent325527e28029e397abf4a88495e3ce63ee362a2e (diff)
Resolve setContentIntent to single code path
Add a private method to remove the duplicate code Test: NetworkPolicyManagerServiceTest Change-Id: I934ee762ce53b8da8797bbbfa30250eabca9a06e
-rw-r--r--services/core/java/com/android/server/net/NetworkPolicyManagerService.java51
1 files changed, 15 insertions, 36 deletions
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index e2c4cbdc829c..dcf19062834c 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -1650,15 +1650,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mContext, 0, snoozeIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
final Intent viewIntent = buildViewDataUsageIntent(res, policy.template);
- // TODO: Resolve to single code path.
- if (UserManager.isHeadlessSystemUserMode()) {
- builder.setContentIntent(PendingIntent.getActivityAsUser(
- mContext, 0, viewIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE,
- /* options= */ null, UserHandle.CURRENT));
- } else {
- builder.setContentIntent(PendingIntent.getActivity(
- mContext, 0, viewIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
- }
+ setContentIntent(builder, viewIntent);
break;
}
case TYPE_LIMIT: {
@@ -1679,15 +1671,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
builder.setSmallIcon(R.drawable.stat_notify_disabled_data);
final Intent intent = buildNetworkOverLimitIntent(res, policy.template);
- // TODO: Resolve to single code path.
- if (UserManager.isHeadlessSystemUserMode()) {
- builder.setContentIntent(PendingIntent.getActivityAsUser(
- mContext, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE,
- /* options= */ null, UserHandle.CURRENT));
- } else {
- builder.setContentIntent(PendingIntent.getActivity(
- mContext, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
- }
+ setContentIntent(builder, intent);
break;
}
case TYPE_LIMIT_SNOOZED: {
@@ -1711,15 +1695,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
builder.setChannelId(SystemNotificationChannels.NETWORK_STATUS);
final Intent intent = buildViewDataUsageIntent(res, policy.template);
- // TODO: Resolve to single code path.
- if (UserManager.isHeadlessSystemUserMode()) {
- builder.setContentIntent(PendingIntent.getActivityAsUser(
- mContext, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE,
- /* options= */ null, UserHandle.CURRENT));
- } else {
- builder.setContentIntent(PendingIntent.getActivity(
- mContext, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
- }
+ setContentIntent(builder, intent);
break;
}
case TYPE_RAPID: {
@@ -1739,15 +1715,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mContext, 0, snoozeIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
final Intent viewIntent = buildViewDataUsageIntent(res, policy.template);
- // TODO: Resolve to single code path.
- if (UserManager.isHeadlessSystemUserMode()) {
- builder.setContentIntent(PendingIntent.getActivityAsUser(
- mContext, 0, viewIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE,
- /* options= */ null, UserHandle.CURRENT));
- } else {
- builder.setContentIntent(PendingIntent.getActivity(
- mContext, 0, viewIntent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
- }
+ setContentIntent(builder, viewIntent);
break;
}
default: {
@@ -1765,6 +1733,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mActiveNotifs.add(notificationId);
}
+ private void setContentIntent(Notification.Builder builder, Intent intent) {
+ if (UserManager.isHeadlessSystemUserMode()) {
+ builder.setContentIntent(PendingIntent.getActivityAsUser(
+ mContext, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE,
+ /* options= */ null, UserHandle.CURRENT));
+ } else {
+ builder.setContentIntent(PendingIntent.getActivity(
+ mContext, 0, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE));
+ }
+ }
+
private void cancelNotification(NotificationId notificationId) {
mContext.getSystemService(NotificationManager.class).cancel(notificationId.getTag(),
notificationId.getId());