PendingUi.java revision 838ba3dbbd0753b3bbf7cff6232e57c488cfdf2d
1/*
2 * Copyright (C) 2017 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 */
16package com.android.server.autofill.ui;
17
18import android.annotation.NonNull;
19import android.os.IBinder;
20import android.util.DebugUtils;
21import android.view.autofill.IAutoFillManagerClient;
22
23/**
24 * Helper class used to handle a pending Autofill affordance such as the Save UI.
25 *
26 * <p>This class is not thread safe.
27 */
28// NOTE: this class could be an interface implemented by Session, but that would make it harder
29// to move the Autofill UI logic to a different process.
30public final class PendingUi {
31
32    public static final int STATE_CREATED = 1;
33    public static final int STATE_PENDING = 2;
34    public static final int STATE_FINISHED = 4;
35
36    private final IBinder mToken;
37    private int mState;
38    public final int id;
39    public final IAutoFillManagerClient client;
40
41    /**
42     * Default constructor.
43     *
44     * @param token token used to identify this pending UI.
45     */
46    public PendingUi(@NonNull IBinder token, int id, @NonNull IAutoFillManagerClient client) {
47        mToken = token;
48        mState = STATE_CREATED;
49        this.id = id;
50        this.client = client;
51    }
52
53    /**
54     * Gets the token used to identify this pending UI.
55     */
56    @NonNull
57    public IBinder getToken() {
58        return mToken;
59    }
60
61    /**
62     * Sets the current lifecycle state.
63     */
64    public void setState(int state) {
65        mState = state;
66    }
67
68    /**
69     * Gets the current lifecycle state.
70     */
71    public int getState() {
72        return mState;
73    }
74
75    /**
76     * Determines whether the given token matches the token used to identify this pending UI.
77     */
78    public boolean matches(IBinder token) {
79        return mToken.equals(token);
80    }
81
82    @Override
83    public String toString() {
84        return "PendingUi: [token=" + mToken + ", id=" + id + ", state="
85                + DebugUtils.flagsToString(PendingUi.class, "STATE_", mState) + "]";
86    }
87}
88