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.car.developeroptions.notification; 18 19 import android.content.Context; 20 import android.service.notification.Adjustment; 21 22 import com.android.car.developeroptions.core.TogglePreferenceController; 23 24 import com.google.common.annotations.VisibleForTesting; 25 26 import java.util.List; 27 28 public class AssistantCapabilityPreferenceController extends TogglePreferenceController { 29 30 static final String PRIORITIZER_KEY = "asst_capability_prioritizer"; 31 static final String SMART_KEY = "asst_capabilities_actions_replies"; 32 private NotificationBackend mBackend; 33 AssistantCapabilityPreferenceController(Context context, String key)34 public AssistantCapabilityPreferenceController(Context context, String key) { 35 super(context, key); 36 mBackend = new NotificationBackend(); 37 } 38 39 @VisibleForTesting setBackend(NotificationBackend backend)40 void setBackend(NotificationBackend backend) { 41 mBackend = backend; 42 } 43 44 @Override isChecked()45 public boolean isChecked() { 46 List<String> capabilities = mBackend.getAssistantAdjustments(mContext.getPackageName()); 47 if (PRIORITIZER_KEY.equals(getPreferenceKey())) { 48 return capabilities.contains(Adjustment.KEY_IMPORTANCE); 49 } else if (SMART_KEY.equals(getPreferenceKey())) { 50 return capabilities.contains(Adjustment.KEY_CONTEXTUAL_ACTIONS) 51 && capabilities.contains(Adjustment.KEY_TEXT_REPLIES); 52 } 53 return false; 54 } 55 56 @Override setChecked(boolean isChecked)57 public boolean setChecked(boolean isChecked) { 58 if (PRIORITIZER_KEY.equals(getPreferenceKey())) { 59 mBackend.allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, isChecked); 60 } else if (SMART_KEY.equals(getPreferenceKey())) { 61 mBackend.allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, isChecked); 62 mBackend.allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, isChecked); 63 } 64 return true; 65 } 66 67 @Override getAvailabilityStatus()68 public int getAvailabilityStatus() { 69 return mBackend.getAllowedNotificationAssistant() != null 70 ? AVAILABLE : DISABLED_DEPENDENT_SETTING; 71 } 72 } 73 74 75