Skip to content

Error: Activity start ONLY allowed by BAL_ALLOW_NON_APP_VISIBLE_WINDOW realCallingUid has non-app visible window #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hossain-khan opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@hossain-khan
Copy link
Owner

hossain-khan commented Jan 20, 2025

Happens when notification is clicked.

Activity start ONLY allowed by BAL_ALLOW_NON_APP_VISIBLE_WINDOW realCallingUid has non-app visible window {2000=1, 2024=2, 2040=1}: [callingPackage: dev.hossain.weatheralert; callingPackageTargetSdk: 35; callingUid: 10231; callingPid: -1; appSwitchState: 2; callingUidHasVisibleActivity: false; callingUidHasNonAppVisibleWindow: false; callingUidProcState: CACHED_ACTIVITY; isCallingUidPersistentSystemProcess: false; allowBalExemptionForSystemProcess: true; intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10008000 pkg=dev.hossain.weatheralert cmp=dev.hossain.weatheralert/.MainActivity }; callerApp: null; balAllowedByPiCreator: BSP.NONE; balAllowedByPiCreatorWithHardening: BSP.NONE; resultIfPiCreatorAllowsBal: BAL_BLOCK; callerStartMode: MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; hasRealCaller: true; isCallForResult: false; isPendingIntent: true; autoOptInReason: null; realCallingPackage: com.android.systemui; realCallingPackageTargetSdk: 10000; realCallingUid: 10182; realCallingPid: 879; realCallingUidHasVisibleActivity: false; realCallingUidHasNonAppVisibleWindow: true; realCallingUidProcState: PERSISTENT_UI; isRealCallingUidPersistentSystemProcess: true; originatingPendingIntent: PendingIntentRecord{9ccc35 dev.hossain.weatheralert startActivity (allowlist: 8d3b92:+30s0ms/0/NOTIFICATION_SERVICE/NotificationManagerService)}; realCallerApp: ProcessRecord{90b869b 879:com.android.systemui/u0a182}; realInVisibleTask: false; balAllowedByPiSender: BSP.ALLOW_BAL; resultIfPiSenderAllowsBal: BAL_ALLOW_NON_APP_VISIBLE_WINDOW; realCallerStartMode: MODE_BACKGROUND_ACTIVITY_START_ALLOWED; balRequireOptInByPendingIntentCreator: true; balDontBringExistingBackgroundTaskStackToFg: true]

@hossain-khan
Copy link
Owner Author

The error message you are encountering indicates that your app is trying to start an activity from the background, which is restricted by the system due to the BAL_ALLOW_NON_APP_VISIBLE_WINDOW policy. This policy is enforced to prevent background apps from launching activities without user interaction.

To resolve this issue, you need to ensure that your app is in the foreground or has the necessary permissions to start activities from the background. Here are a few steps you can take:

  1. Check if the app is in the foreground: Ensure that the app is in the foreground when trying to start the activity. You can use the ActivityManager to check if your app is in the foreground.

  2. Use a foreground service: If your app needs to start an activity from the background, consider using a foreground service. Foreground services have higher priority and can start activities.

  3. Request the necessary permissions: Ensure that your app has the necessary permissions to start activities from the background. You may need to request the SYSTEM_ALERT_WINDOW permission.

  4. Use PendingIntent: If you are trying to start an activity from a notification, use a PendingIntent to start the activity.

Here is an example of how to use a PendingIntent to start an activity from a notification:

val intent = Intent(this, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(
    this,
    0,
    intent,
    PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)

val notification = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentTitle("Weather Alert")
    .setContentText("Tap to open the app")
    .setSmallIcon(R.drawable.ic_notification)
    .setContentIntent(pendingIntent)
    .setAutoCancel(true)
    .build()

val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(NOTIFICATION_ID, notification)

Make sure to replace CHANNEL_ID, NOTIFICATION_ID, and R.drawable.ic_notification with appropriate values for your app.

By following these steps, you should be able to resolve the issue and start the activity without encountering the BAL_ALLOW_NON_APP_VISIBLE_WINDOW restriction.

@hossain-khan hossain-khan added the bug Something isn't working label Jan 20, 2025
@hossain-khan hossain-khan added this to the 2.x milestone Jan 25, 2025
@hossain-khan hossain-khan modified the milestones: 2.x, 3.0 Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant