Loading proto/src/system_messages.proto +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading services/core/java/com/android/server/am/ActiveServices.java +34 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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()); } } } services/core/java/com/android/server/am/ActivityManagerService.java +2 −1 Original line number Diff line number Diff line Loading @@ -19338,7 +19338,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); } } } Loading
proto/src/system_messages.proto +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
services/core/java/com/android/server/am/ActiveServices.java +34 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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()); } } }
services/core/java/com/android/server/am/ActivityManagerService.java +2 −1 Original line number Diff line number Diff line Loading @@ -19338,7 +19338,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); } } }