1 /* 2 * Copyright (C) 2022 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.keyguard; 18 19 import android.service.trust.TrustAgentService; 20 21 import java.util.Objects; 22 23 /** 24 * Translating {@link android.service.trust.TrustAgentService.GrantTrustFlags} to a more 25 * parsable object. These flags are requested by a TrustAgent. 26 */ 27 public class TrustGrantFlags { 28 final int mFlags; 29 TrustGrantFlags(int flags)30 public TrustGrantFlags(int flags) { 31 this.mFlags = flags; 32 } 33 34 /** {@link TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER} */ isInitiatedByUser()35 public boolean isInitiatedByUser() { 36 return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER) != 0; 37 } 38 39 /** 40 * Trust agent is requesting to dismiss the keyguard. 41 * See {@link TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD}. 42 * 43 * This does not guarantee that the keyguard is dismissed. 44 * KeyguardUpdateMonitor makes the final determination whether the keyguard should be dismissed. 45 * {@link KeyguardUpdateMonitorCallback#onTrustGrantedForCurrentUser( 46 * boolean, TrustGrantFlags, String). 47 */ dismissKeyguardRequested()48 public boolean dismissKeyguardRequested() { 49 return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD) != 0; 50 } 51 52 /** {@link TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE} */ temporaryAndRenewable()53 public boolean temporaryAndRenewable() { 54 return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) != 0; 55 } 56 57 /** {@link TrustAgentService.FLAG_GRANT_TRUST_DISPLAY_MESSAGE} */ displayMessage()58 public boolean displayMessage() { 59 return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_DISPLAY_MESSAGE) != 0; 60 } 61 62 @Override equals(Object o)63 public boolean equals(Object o) { 64 if (!(o instanceof TrustGrantFlags)) { 65 return false; 66 } 67 68 return ((TrustGrantFlags) o).mFlags == this.mFlags; 69 } 70 71 @Override hashCode()72 public int hashCode() { 73 return Objects.hash(mFlags); 74 } 75 76 @Override toString()77 public String toString() { 78 final StringBuilder sb = new StringBuilder(); 79 sb.append("["); 80 sb.append(mFlags); 81 sb.append("]="); 82 83 if (isInitiatedByUser()) { 84 sb.append("initiatedByUser|"); 85 } 86 if (dismissKeyguardRequested()) { 87 sb.append("dismissKeyguard|"); 88 } 89 if (temporaryAndRenewable()) { 90 sb.append("temporaryAndRenewable|"); 91 } 92 if (displayMessage()) { 93 sb.append("displayMessage|"); 94 } 95 96 return sb.toString(); 97 } 98 } 99