Home | History | Annotate | Download | only in ui
      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  */
     16 package com.android.server.autofill.ui;
     17 
     18 import android.annotation.NonNull;
     19 import android.os.IBinder;
     20 import android.util.DebugUtils;
     21 import android.view.autofill.IAutoFillManagerClient;
     22 
     23 /**
     24  * Helper class used to handle a pending Autofill UI 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.
     30 public 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 sessionId;
     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 sessionId,
     47             @NonNull IAutoFillManagerClient client) {
     48         mToken = token;
     49         mState = STATE_CREATED;
     50         this.sessionId = sessionId;
     51         this.client = client;
     52     }
     53 
     54     /**
     55      * Gets the token used to identify this pending UI.
     56      */
     57     @NonNull
     58     public IBinder getToken() {
     59         return mToken;
     60     }
     61 
     62     /**
     63      * Sets the current lifecycle state.
     64      */
     65     public void setState(int state) {
     66         mState = state;
     67     }
     68 
     69     /**
     70      * Gets the current lifecycle state.
     71      */
     72     public int getState() {
     73         return mState;
     74     }
     75 
     76     /**
     77      * Determines whether the given token matches the token used to identify this pending UI.
     78      */
     79     public boolean matches(IBinder token) {
     80         return mToken.equals(token);
     81     }
     82 
     83     @Override
     84     public String toString() {
     85         return "PendingUi: [token=" + mToken + ", sessionId=" + sessionId + ", state="
     86                 + DebugUtils.flagsToString(PendingUi.class, "STATE_", mState) + "]";
     87     }
     88 }
     89