1 /* 2 * Copyright (C) 2015 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; 18 19 import android.app.Fragment; 20 import android.content.Intent; 21 import android.os.Bundle; 22 23 /** 24 * An invisible retained fragment to track lock check result. 25 */ 26 public class CredentialCheckResultTracker extends Fragment { 27 28 private Listener mListener; 29 private boolean mHasResult = false; 30 31 private boolean mResultMatched; 32 private Intent mResultData; 33 private int mResultTimeoutMs; 34 private int mResultEffectiveUserId; 35 36 @Override onCreate(Bundle savedInstanceState)37 public void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setRetainInstance(true); 40 } 41 setListener(Listener listener)42 public void setListener(Listener listener) { 43 if (mListener == listener) { 44 return; 45 } 46 47 mListener = listener; 48 if (mListener != null && mHasResult) { 49 mListener.onCredentialChecked(mResultMatched, mResultData, mResultTimeoutMs, 50 mResultEffectiveUserId, false /* newResult */); 51 } 52 } 53 setResult(boolean matched, Intent intent, int timeoutMs, int effectiveUserId)54 public void setResult(boolean matched, Intent intent, int timeoutMs, int effectiveUserId) { 55 mResultMatched = matched; 56 mResultData = intent; 57 mResultTimeoutMs = timeoutMs; 58 mResultEffectiveUserId = effectiveUserId; 59 60 mHasResult = true; 61 if (mListener != null) { 62 mListener.onCredentialChecked(mResultMatched, mResultData, mResultTimeoutMs, 63 mResultEffectiveUserId, true /* newResult */); 64 mHasResult = false; 65 } 66 } 67 clearResult()68 public void clearResult() { 69 mHasResult = false; 70 mResultMatched = false; 71 mResultData = null; 72 mResultTimeoutMs = 0; 73 mResultEffectiveUserId = 0; 74 } 75 76 interface Listener { onCredentialChecked(boolean matched, Intent intent, int timeoutMs, int effectiveUserId, boolean newResult)77 public void onCredentialChecked(boolean matched, Intent intent, int timeoutMs, 78 int effectiveUserId, boolean newResult); 79 } 80 } 81