Make sure work profile app cant enable notification listener services
Fix: 282934003
Test: Run test app in work profile
(cherry picked from commit 81893c2b6f0743e7786ee133922c68834e3a4e16)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3465535747643a64e7b5b88f43ced06492ad5264)
Merged-In: I7fed6d1baa1a40e9126493d37e33d63236bb4b3c
Change-Id: I7fed6d1baa1a40e9126493d37e33d63236bb4b3c
diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
index a6b565a..9ea8c58 100644
--- a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
+++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
@@ -17,6 +17,7 @@
package com.android.settings.notification;
+import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_APPS_CANNOT_ACCESS_NOTIFICATION_SETTINGS;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
@@ -26,6 +27,7 @@
import android.annotation.Nullable;
import android.app.Activity;
import android.app.NotificationManager;
+import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -35,10 +37,12 @@
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.os.UserHandle;
+import android.os.UserManager;
import android.text.TextUtils;
import android.util.Slog;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
+import android.widget.Toast;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
@@ -55,12 +59,28 @@
private ComponentName mComponentName;
private NotificationManager mNm;
+ private DevicePolicyManager mDpm;
+ private UserManager mUm;
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ mUm = getSystemService(UserManager.class);
+ mDpm = getSystemService(DevicePolicyManager.class);
+
+ if (mUm.isManagedProfile()) {
+ Slog.w(LOG_TAG, "Apps in the work profile do not support notification listeners");
+ Toast.makeText(this,
+ mDpm.getResources().getString(WORK_APPS_CANNOT_ACCESS_NOTIFICATION_SETTINGS,
+ () -> getString(R.string.notification_settings_work_profile)),
+ Toast.LENGTH_SHORT).show();
+ finish();
+ return;
+ }
+
mNm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);