blob: 1993ec6b64e3fc0545773a56bc59d8f979491694 [file] [log] [blame]
Xiyuan Xia00b17fa2015-08-31 11:59:46 -07001/*
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
Maurice Lam2eb170c2017-04-28 16:18:47 -070017package com.android.settings.password;
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070018
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070019import android.content.Intent;
20import android.os.Bundle;
21
tmfang99cc23d2018-06-26 19:01:57 +080022import androidx.fragment.app.Fragment;
23
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070024/**
25 * An invisible retained fragment to track lock check result.
26 */
Jorim Jaggi69671da2015-09-10 13:35:04 -070027public class CredentialCheckResultTracker extends Fragment {
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070028
29 private Listener mListener;
30 private boolean mHasResult = false;
31
32 private boolean mResultMatched;
33 private Intent mResultData;
34 private int mResultTimeoutMs;
35 private int mResultEffectiveUserId;
36
37 @Override
38 public void onCreate(Bundle savedInstanceState) {
39 super.onCreate(savedInstanceState);
40 setRetainInstance(true);
41 }
42
43 public void setListener(Listener listener) {
44 if (mListener == listener) {
45 return;
46 }
47
48 mListener = listener;
49 if (mListener != null && mHasResult) {
50 mListener.onCredentialChecked(mResultMatched, mResultData, mResultTimeoutMs,
Clara Bayarri9d357ea2016-01-28 17:50:53 +000051 mResultEffectiveUserId, false /* newResult */);
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070052 }
53 }
54
55 public void setResult(boolean matched, Intent intent, int timeoutMs, int effectiveUserId) {
56 mResultMatched = matched;
57 mResultData = intent;
58 mResultTimeoutMs = timeoutMs;
59 mResultEffectiveUserId = effectiveUserId;
60
61 mHasResult = true;
62 if (mListener != null) {
63 mListener.onCredentialChecked(mResultMatched, mResultData, mResultTimeoutMs,
Clara Bayarri9d357ea2016-01-28 17:50:53 +000064 mResultEffectiveUserId, true /* newResult */);
Tony Makb27d5b22016-03-18 18:24:13 +000065 mHasResult = false;
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070066 }
67 }
68
69 public void clearResult() {
70 mHasResult = false;
71 mResultMatched = false;
72 mResultData = null;
73 mResultTimeoutMs = 0;
74 mResultEffectiveUserId = 0;
75 }
76
77 interface Listener {
78 public void onCredentialChecked(boolean matched, Intent intent, int timeoutMs,
Clara Bayarri9d357ea2016-01-28 17:50:53 +000079 int effectiveUserId, boolean newResult);
Xiyuan Xia00b17fa2015-08-31 11:59:46 -070080 }
81}