Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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.internal;
18
 
19
import android.content.Context;
20
import android.os.Bundle;
21
import android.util.Log;
22
import com.facebook.LoggingBehavior;
23
import com.facebook.Settings;
24
import org.json.JSONException;
25
import org.json.JSONObject;
26
 
27
import java.util.Collection;
28
import java.util.EnumSet;
29
 
30
/**
31
 * com.facebook.internal is solely for the use of other packages within the Facebook SDK for Android. Use of
32
 * any of the classes in this package is unsupported, and they may be modified or removed without warning at
33
 * any time.
34
 */
35
public final class ServerProtocol {
36
    private static final String TAG = ServerProtocol.class.getName();
37
 
38
    private static final String DIALOG_AUTHORITY_FORMAT = "m.%s";
39
    public static final String DIALOG_PATH = "dialog/";
40
    public static final String DIALOG_PARAM_ACCESS_TOKEN = "access_token";
41
    public static final String DIALOG_PARAM_APP_ID = "app_id";
42
    public static final String DIALOG_PARAM_AUTH_TYPE = "auth_type";
43
    public static final String DIALOG_PARAM_CLIENT_ID = "client_id";
44
    public static final String DIALOG_PARAM_DISPLAY = "display";
45
    public static final String DIALOG_PARAM_E2E = "e2e";
46
    public static final String DIALOG_PARAM_LEGACY_OVERRIDE = "legacy_override";
47
    public static final String DIALOG_PARAM_REDIRECT_URI = "redirect_uri";
48
    public static final String DIALOG_PARAM_RESPONSE_TYPE = "response_type";
49
    public static final String DIALOG_PARAM_RETURN_SCOPES = "return_scopes";
50
    public static final String DIALOG_PARAM_SCOPE = "scope";
51
    public static final String DIALOG_PARAM_DEFAULT_AUDIENCE = "default_audience";
52
    public static final String DIALOG_REREQUEST_AUTH_TYPE = "rerequest";
53
    public static final String DIALOG_RESPONSE_TYPE_TOKEN = "token";
54
    public static final String DIALOG_RETURN_SCOPES_TRUE = "true";
55
 
56
    public static final String FALLBACK_DIALOG_PARAM_APP_ID = "app_id";
57
    public static final String FALLBACK_DIALOG_PARAM_BRIDGE_ARGS = "bridge_args";
58
    public static final String FALLBACK_DIALOG_PARAM_KEY_HASH = "android_key_hash";
59
    public static final String FALLBACK_DIALOG_PARAM_METHOD_ARGS = "method_args";
60
    public static final String FALLBACK_DIALOG_PARAM_METHOD_RESULTS = "method_results";
61
    public static final String FALLBACK_DIALOG_PARAM_VERSION = "version";
62
    public static final String FALLBACK_DIALOG_DISPLAY_VALUE_TOUCH = "touch";
63
 
64
    // URL components
65
    private static final String GRAPH_VIDEO_URL_FORMAT = "https://graph-video.%s";
66
    private static final String GRAPH_URL_FORMAT = "https://graph.%s";
67
    public static final String GRAPH_API_VERSION = "v2.2";
68
 
69
    private static final String LEGACY_API_VERSION = "v1.0";
70
 
71
    public static final Collection<String> errorsProxyAuthDisabled =
72
            Utility.unmodifiableCollection("service_disabled", "AndroidAuthKillSwitchException");
73
    public static final Collection<String> errorsUserCanceled =
74
            Utility.unmodifiableCollection("access_denied", "OAuthAccessDeniedException");
75
 
76
    public static final String getDialogAuthority() {
77
        return String.format(DIALOG_AUTHORITY_FORMAT, Settings.getFacebookDomain());
78
    }
79
 
80
    public static final String getGraphUrlBase() {
81
        return String.format(GRAPH_URL_FORMAT, Settings.getFacebookDomain());
82
    }
83
 
84
    public static final String getGraphVideoUrlBase() {
85
        return String.format(GRAPH_VIDEO_URL_FORMAT, Settings.getFacebookDomain());
86
    }
87
 
88
    public static final String getAPIVersion() {
89
        if (Settings.getPlatformCompatibilityEnabled()) {
90
            return LEGACY_API_VERSION;
91
        }
92
        return GRAPH_API_VERSION;
93
    }
94
 
95
    public static Bundle getQueryParamsForPlatformActivityIntentWebFallback(
96
            Context context,
97
            String callId,
98
            int version,
99
            String applicationName,
100
            Bundle methodArgs) {
101
 
102
        String keyHash = Settings.getApplicationSignature(context);
103
        if (Utility.isNullOrEmpty(keyHash)) {
104
            return null;
105
        }
106
 
107
        Bundle webParams = new Bundle();
108
 
109
        webParams.putString(FALLBACK_DIALOG_PARAM_KEY_HASH, keyHash);
110
        webParams.putString(FALLBACK_DIALOG_PARAM_APP_ID, Settings.getApplicationId());
111
        webParams.putInt(FALLBACK_DIALOG_PARAM_VERSION, version);
112
        webParams.putString(DIALOG_PARAM_DISPLAY, FALLBACK_DIALOG_DISPLAY_VALUE_TOUCH);
113
 
114
        Bundle bridgeArguments = new Bundle();
115
        bridgeArguments.putString(NativeProtocol.BRIDGE_ARG_ACTION_ID_STRING, callId);
116
        bridgeArguments.putString(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING, applicationName);
117
 
118
        methodArgs = (methodArgs == null) ? new Bundle() : methodArgs;
119
 
120
        try {
121
            JSONObject bridgeArgsJSON = BundleJSONConverter.convertToJSON(bridgeArguments);
122
            JSONObject methodArgsJSON = BundleJSONConverter.convertToJSON(methodArgs);
123
 
124
            if (bridgeArgsJSON == null || methodArgsJSON == null) {
125
                return null;
126
            }
127
 
128
            webParams.putString(FALLBACK_DIALOG_PARAM_BRIDGE_ARGS, bridgeArgsJSON.toString());
129
            webParams.putString(FALLBACK_DIALOG_PARAM_METHOD_ARGS, methodArgsJSON.toString());
130
        } catch (JSONException je) {
131
            webParams = null;
132
            Logger.log(LoggingBehavior.DEVELOPER_ERRORS, Log.ERROR, TAG,
133
                    "Error creating Url -- " + je);
134
        }
135
 
136
        return webParams;
137
    }
138
}