summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Yu <huiyu@google.com>2020-02-19 13:07:48 -0800
committerHui Yu <huiyu@google.com>2020-02-19 16:22:19 -0800
commit52debeb5b9988e9c392d20efc368b04a9131a493 (patch)
treed3ea27b81dcec05d0187483a30db861b0e5d05ca
parent8887c6da17d33e1763e2e121e7d3dcd64cc0413c (diff)
Show a notification when FGS while-in-use permission is restricted.
Change from showing a toast to a notification. Bug: 136219221 Test: atest cts/tests/app/src/android/app/cts/ActivityManagerApi29Test.java to trigger the notification. Change-Id: If22a72fb5a70b14d0b424fbcfe6d1e5c70f2a34d
-rw-r--r--proto/src/system_messages.proto3
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java50
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java3
3 files changed, 39 insertions, 17 deletions
diff --git a/proto/src/system_messages.proto b/proto/src/system_messages.proto
index eda3fb9c8698..cff55046fc2b 100644
--- a/proto/src/system_messages.proto
+++ b/proto/src/system_messages.proto
@@ -252,6 +252,9 @@ message SystemMessage {
// Package: android
NOTE_ID_WIFI_SIM_REQUIRED = 60;
+ // Inform the user a foreground service while-in-use permission is restricted.
+ NOTE_FOREGROUND_SERVICE_WHILE_IN_USE_PERMISSION = 61;
+
// ADD_NEW_IDS_ABOVE_THIS_LINE
// Legacy IDs with arbitrary values appear below
// Legacy IDs existed as stable non-conflicting constants prior to the O release
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 50f43b5c1bae..2bcb28de5d9c 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -62,7 +62,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
-import android.content.res.Resources;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -91,7 +90,6 @@ import android.util.SparseArray;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;
import android.webkit.WebViewZygote;
-import android.widget.Toast;
import com.android.internal.R;
import com.android.internal.app.procstats.ServiceState;
@@ -4687,20 +4685,35 @@ public final class ActiveServices {
}
// TODO: remove this toast after feature development is done
- private void showWhileInUsePermissionInFgsBlockedToastLocked(String callingPackage) {
- final Resources res = mAm.mContext.getResources();
- final String toastMsg = res.getString(
- R.string.allow_while_in_use_permission_in_fgs, callingPackage);
- mAm.mUiHandler.post(() -> {
- Toast.makeText(mAm.mContext, toastMsg, Toast.LENGTH_LONG).show();
- });
+ private void showWhileInUsePermissionInFgsBlockedNotificationLocked(String callingPackage,
+ String detailInfo) {
+ final Context context = mAm.mContext;
+ final String title = "Foreground Service While-in-use Permission Restricted";
+ final String content = "App affected:" + callingPackage + ", please file a bug report";
+ Notification.Builder n =
+ new Notification.Builder(context,
+ SystemNotificationChannels.ALERTS)
+ .setSmallIcon(R.drawable.stat_sys_vitals)
+ .setWhen(0)
+ .setColor(context.getColor(
+ com.android.internal.R.color.system_notification_accent_color))
+ .setTicker(title)
+ .setContentTitle(title)
+ .setContentText(content)
+ .setStyle(new Notification.BigTextStyle().bigText(detailInfo));
+ final NotificationManager notificationManager =
+ (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
+ notificationManager.notifyAsUser(null,
+ SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICE_WHILE_IN_USE_PERMISSION,
+ n.build(), UserHandle.ALL);
}
// TODO: remove this toast after feature development is done
// show a toast message to ask user to file a bugreport so we know how many apps are impacted by
// the new background started foreground service while-in-use permission restriction.
- void showWhileInUseDebugToastLocked(int uid, int op, int mode) {
- StringBuilder sb = new StringBuilder();
+ void showWhileInUseDebugNotificationLocked(int uid, int op, int mode) {
+ StringBuilder packageNameBuilder = new StringBuilder();
+ StringBuilder detailInfoBuilder = new StringBuilder();
for (int i = mAm.mProcessList.mLruProcesses.size() - 1; i >= 0; i--) {
ProcessRecord pr = mAm.mProcessList.mLruProcesses.get(i);
if (pr.uid != uid) {
@@ -4713,17 +4726,22 @@ public final class ActiveServices {
}
if (!r.mAllowWhileInUsePermissionInFgs
&& r.mInfoDenyWhileInUsePermissionInFgs != null) {
- Slog.wtf(TAG, r.mInfoDenyWhileInUsePermissionInFgs
- + " affected while-use-permission:" + AppOpsManager.opToPublicName(op));
- sb.append(r.mRecentCallingPackage + " ");
+ final String msg = r.mInfoDenyWhileInUsePermissionInFgs
+ + " affected while-in-use permission:"
+ + AppOpsManager.opToPublicName(op);
+ Slog.wtf(TAG, msg);
+ packageNameBuilder.append(r.mRecentCallingPackage + " ");
+ detailInfoBuilder.append(msg);
+ detailInfoBuilder.append("\n");
}
}
}
- final String callingPackageStr = sb.toString();
+ final String callingPackageStr = packageNameBuilder.toString();
if (mAm.mConstants.mFlagForegroundServiceStartsLoggingEnabled
&& !callingPackageStr.isEmpty()) {
- showWhileInUsePermissionInFgsBlockedToastLocked(callingPackageStr);
+ showWhileInUsePermissionInFgsBlockedNotificationLocked(callingPackageStr,
+ detailInfoBuilder.toString());
}
}
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 9082807f6bbc..0a825cf5a45b 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -19333,7 +19333,8 @@ public class ActivityManagerService extends IActivityManager.Stub
@Override
public void showWhileInUseDebugToast(int uid, int op, int mode) {
synchronized (ActivityManagerService.this) {
- ActivityManagerService.this.mServices.showWhileInUseDebugToastLocked(uid, op, mode);
+ ActivityManagerService.this.mServices.showWhileInUseDebugNotificationLocked(
+ uid, op, mode);
}
}
}