1 /* 2 * Copyright (C) 2021 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.permissioncontroller.safetycenter.ui; 18 19 /** An entry to be shown as a preference in Safety Center */ 20 public class SafetyEntry { 21 22 /** Minimum entry order. Smaller values will be set to DEFAULT_ENTRY_ORDER. */ 23 private static final int MIN_ENTRY_ORDER = 1; 24 /** Default entry order. Unspecified order values will be set to this. */ 25 private static final int DEFAULT_ENTRY_ORDER = 1000; 26 27 private String mTitle; 28 private String mSummary; 29 private SeverityLevel mSeverityLevel; 30 private int mOrder; 31 private String mSafetySourceId; 32 SafetyEntry(SafetyEntry.Builder builder)33 private SafetyEntry(SafetyEntry.Builder builder) { 34 mTitle = builder.mTitle; 35 mSummary = builder.mSummary; 36 mSeverityLevel = builder.mSeverityLevel; 37 mOrder = builder.mOrder; 38 mSafetySourceId = builder.mSafetySourceId; 39 } 40 41 /** Builds the SafetyEntry. */ builder()42 public static SafetyEntry.Builder builder() { 43 return new SafetyEntry.Builder(); 44 } 45 46 /** Returns the title. */ getTitle()47 public String getTitle() { 48 return mTitle; 49 } 50 51 /** Returns the summary. */ getSummary()52 public String getSummary() { 53 return mSummary; 54 } 55 56 /** Returns the severity level. */ getSeverityLevel()57 public SeverityLevel getSeverityLevel() { 58 return mSeverityLevel; 59 } 60 61 /** Returns the order that this entry should have in the entry list. */ getOrder()62 public int getOrder() { 63 return mOrder; 64 } 65 66 /** Returns the safety source id. */ getSafetySourceId()67 public String getSafetySourceId() { 68 return mSafetySourceId; 69 } 70 71 /** Builder for the SafetyEntry class. */ 72 public static class Builder { 73 private String mTitle; 74 private String mSummary; 75 private SeverityLevel mSeverityLevel; 76 private int mOrder = DEFAULT_ENTRY_ORDER; 77 private String mSafetySourceId; 78 79 /** Sets the title. */ setTitle(String title)80 public SafetyEntry.Builder setTitle(String title) { 81 mTitle = title; 82 return this; 83 } 84 85 /** Sets the summary. */ setSummary(String summary)86 public SafetyEntry.Builder setSummary(String summary) { 87 mSummary = summary; 88 return this; 89 } 90 91 /** Sets the severity level. */ setSeverityLevel(SeverityLevel severityLevel)92 public SafetyEntry.Builder setSeverityLevel(SeverityLevel severityLevel) { 93 mSeverityLevel = severityLevel; 94 return this; 95 } 96 97 /** 98 * Sets the order that this entry should appear in the list of entries. 99 * If <= 0, the value will be ignored and the entry will use a default order. 100 */ setOrder(int order)101 public SafetyEntry.Builder setOrder(int order) { 102 mOrder = order >= MIN_ENTRY_ORDER ? order : DEFAULT_ENTRY_ORDER; 103 return this; 104 } 105 106 /** Sets the safety source id. */ setSafetySourceId(String safetySourceId)107 public SafetyEntry.Builder setSafetySourceId(String safetySourceId) { 108 mSafetySourceId = safetySourceId; 109 return this; 110 } 111 112 /** Builds the SafetyEntry. */ build()113 public SafetyEntry build() { 114 return new SafetyEntry(this); 115 } 116 } 117 } 118