Disable notification settings access from work apps.
Fixes: 79241388 Test: the following command does not open the notification settings in work profile user: $ adb shell am start --user $USER -W -a android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS Moreover, triggering the notifications from a sample app results in the new toast being displayed. Change-Id: I0a330a9cf22c813aea7600557660868263817e1e
This commit is contained in:
@@ -23,10 +23,12 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
|
||||
import android.widget.Toast;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
@@ -61,6 +63,18 @@ public class NotificationAccessSettings extends ManagedServiceSettings {
|
||||
|
||||
private NotificationManager mNm;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
final Context ctx = getContext();
|
||||
if (UserManager.get(ctx).isManagedProfile()) {
|
||||
// Apps in the work profile do not support notification listeners.
|
||||
Toast.makeText(ctx, R.string.notification_settings_work_profile, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.NOTIFICATION_ACCESS;
|
||||
|
Reference in New Issue
Block a user