1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.pm.PackageManager; 22 import android.os.UserHandle; 23 24 import com.android.settings.core.BasePreferenceController; 25 import com.android.settingslib.applications.DefaultAppInfo; 26 import com.android.settingslib.widget.CandidateInfo; 27 28 import com.google.common.annotations.VisibleForTesting; 29 30 public class NotificationAssistantPreferenceController extends BasePreferenceController { 31 32 @VisibleForTesting 33 protected NotificationBackend mNotificationBackend; 34 private PackageManager mPackageManager; 35 NotificationAssistantPreferenceController(Context context, String preferenceKey)36 public NotificationAssistantPreferenceController(Context context, String preferenceKey) { 37 super(context, preferenceKey); 38 mNotificationBackend = new NotificationBackend(); 39 mPackageManager = mContext.getPackageManager(); 40 } 41 42 @Override getAvailabilityStatus()43 public int getAvailabilityStatus() { 44 return BasePreferenceController.AVAILABLE; 45 } 46 47 @Override getSummary()48 public CharSequence getSummary() { 49 CandidateInfo appSelected = new NotificationAssistantPicker.CandidateNone(mContext); 50 ComponentName assistant = mNotificationBackend.getAllowedNotificationAssistant(); 51 if (assistant != null) { 52 appSelected = createCandidateInfo(assistant); 53 } 54 return appSelected.loadLabel(); 55 } 56 57 @VisibleForTesting createCandidateInfo(ComponentName cn)58 protected CandidateInfo createCandidateInfo(ComponentName cn) { 59 return new DefaultAppInfo(mContext, mPackageManager, UserHandle.myUserId(), cn); 60 } 61 } 62