| 14792 |
manas |
1 |
/**
|
|
|
2 |
* Copyright 2010-present Facebook.
|
|
|
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.facebook;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* <p>
|
|
|
21 |
* Identifies the state of a Session.
|
|
|
22 |
* </p>
|
|
|
23 |
* <p>
|
|
|
24 |
* Session objects implement a state machine that controls their lifecycle. This
|
|
|
25 |
* enum represents the states of the state machine.
|
|
|
26 |
* </p>
|
|
|
27 |
*/
|
|
|
28 |
public enum SessionState {
|
|
|
29 |
/**
|
|
|
30 |
* Indicates that the Session has not yet been opened and has no cached
|
|
|
31 |
* token. Opening a Session in this state will involve user interaction.
|
|
|
32 |
*/
|
|
|
33 |
CREATED(Category.CREATED_CATEGORY),
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* <p>
|
|
|
37 |
* Indicates that the Session has not yet been opened and has a cached
|
|
|
38 |
* token. Opening a Session in this state will not involve user interaction.
|
|
|
39 |
* </p>
|
|
|
40 |
* <p>
|
|
|
41 |
* If you are using Session from an Android Service, you must provide a
|
|
|
42 |
* TokenCachingStrategy implementation that contains a valid token to the Session
|
|
|
43 |
* constructor. The resulting Session will be created in this state, and you
|
|
|
44 |
* can then safely call open, passing null for the Activity.
|
|
|
45 |
* </p>
|
|
|
46 |
*/
|
|
|
47 |
CREATED_TOKEN_LOADED(Category.CREATED_CATEGORY),
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Indicates that the Session is in the process of opening.
|
|
|
51 |
*/
|
|
|
52 |
OPENING(Category.CREATED_CATEGORY),
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Indicates that the Session is opened. In this state, the Session may be
|
|
|
56 |
* used with a {@link Request}.
|
|
|
57 |
*/
|
|
|
58 |
OPENED(Category.OPENED_CATEGORY),
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* <p>
|
|
|
62 |
* Indicates that the Session is opened and that the token has changed. In
|
|
|
63 |
* this state, the Session may be used with {@link Request}.
|
|
|
64 |
* </p>
|
|
|
65 |
* <p>
|
|
|
66 |
* Every time the token is updated, {@link Session.StatusCallback
|
|
|
67 |
* StatusCallback} is called with this value.
|
|
|
68 |
* </p>
|
|
|
69 |
*/
|
|
|
70 |
OPENED_TOKEN_UPDATED(Category.OPENED_CATEGORY),
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Indicates that the Session is closed, and that it was not closed
|
|
|
74 |
* normally. Typically this means that the open call failed, and the
|
|
|
75 |
* Exception parameter to {@link Session.StatusCallback StatusCallback} will
|
|
|
76 |
* be non-null.
|
|
|
77 |
*/
|
|
|
78 |
CLOSED_LOGIN_FAILED(Category.CLOSED_CATEGORY),
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Indicates that the Session was closed normally.
|
|
|
82 |
*/
|
|
|
83 |
CLOSED(Category.CLOSED_CATEGORY);
|
|
|
84 |
|
|
|
85 |
private final Category category;
|
|
|
86 |
|
|
|
87 |
SessionState(Category category) {
|
|
|
88 |
this.category = category;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Returns a boolean indicating whether the state represents a successfully
|
|
|
93 |
* opened state in which the Session can be used with a {@link Request}.
|
|
|
94 |
*
|
|
|
95 |
* @return a boolean indicating whether the state represents a successfully
|
|
|
96 |
* opened state in which the Session can be used with a
|
|
|
97 |
* {@link Request}.
|
|
|
98 |
*/
|
|
|
99 |
public boolean isOpened() {
|
|
|
100 |
return this.category == Category.OPENED_CATEGORY;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Returns a boolean indicating whether the state represents a closed
|
|
|
105 |
* Session that can no longer be used with a {@link Request}.
|
|
|
106 |
*
|
|
|
107 |
* @return a boolean indicating whether the state represents a closed
|
|
|
108 |
* Session that can no longer be used with a {@link Request}.
|
|
|
109 |
*/
|
|
|
110 |
public boolean isClosed() {
|
|
|
111 |
return this.category == Category.CLOSED_CATEGORY;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
private enum Category {
|
|
|
115 |
CREATED_CATEGORY, OPENED_CATEGORY, CLOSED_CATEGORY
|
|
|
116 |
}
|
|
|
117 |
}
|