Search in sources :

Example 6 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class Identities method validateIdentityCredentials.

/**
 * Implementation of identities/validateidentitycredentials API. Parameters
 * are; [auth], Boolean dryrun [opt], String network [opt], String username,
 * String password, String server [opt], String contactdetail [opt], Map
 * identitycapabilitystatus [opt]
 *
 * @param engine handle to IdentitiesEngine
 * @param dryrun Whether this is a dry-run request.
 * @param network Name of network.
 * @param username User-name.
 * @param password Password.
 * @param server
 * @param contactdetail
 * @param identitycapabilitystatus Capabilities for this identity/network.
 * @return request id generated for this request
 */
public static int validateIdentityCredentials(BaseEngine engine, Boolean dryrun, String network, String username, String password, String server, String contactdetail, Map<String, Boolean> identitycapabilitystatus) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() Invalid session, return -1");
        return -1;
    }
    if (network == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() network cannot be NULL");
        return -1;
    }
    if (username == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() username cannot be NULL");
        return -1;
    }
    if (password == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() password cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_VALIDATE_IDENTITY_CREDENTIALS, Request.Type.EXPECTING_STATUS_ONLY, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_IDENTITIES);
    if (dryrun != null) {
        request.addData("dryrun", dryrun);
    }
    request.addData("network", network);
    request.addData("username", username);
    request.addData("password", password);
    if (server != null) {
        request.addData("server", server);
    }
    if (contactdetail != null) {
        request.addData("contactdetail", contactdetail);
    }
    if (identitycapabilitystatus != null) {
        request.addData("identitycapabilitystatus", new Hashtable<String, Object>(identitycapabilitystatus));
    }
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 7 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class Presence method getPresenceList.

// function?
/**
 * Retrieve current presence list
 *
 * @param engineId ID for Presence engine.
 * @param recipientUserIdList List of user IDs.
 */
public static void getPresenceList(EngineId engineId, Map<String, List<String>> recipientUserIdList) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Presence.getPresenceList() No session, return");
        return;
    }
    Request request = new Request(EMPTY, Request.Type.PRESENCE_LIST, engineId, false, Settings.API_REQUESTS_TIMEOUT_PRESENCE_LIST);
    if (recipientUserIdList != null) {
        // If not specified, then all presence information will be returned
        request.addData("tos", ApiUtils.createHashTable(recipientUserIdList));
    }
    QueueManager.getInstance().addRequest(request);
    QueueManager.getInstance().fireQueueStateChanged();
}
Also used : Request(com.vodafone360.people.service.io.Request)

Example 8 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class TcpConnectionThread method run.

public void run() {
    QueueManager queueManager = QueueManager.getInstance();
    setFailedRetrying(false);
    setIsRetrying(false);
    try {
        // start the initial connection
        reconnectSocket();
        HeartbeatSenderThread hbSender = new HeartbeatSenderThread(this, mService, mSocket);
        hbSender.setOutputStream(mOs);
        hbSender.sendHeartbeat();
        hbSender = null;
        // TODO run this when BE supports it but keep HB in front!
        /*
             * ConnectionTester connTester = new ConnectionTester(mIs, mOs); if
             * (connTester.runTest()) { } else {}
             */
        startHelperThreads();
        ConnectionManager.getInstance().onConnectionStateChanged(ITcpConnectionListener.STATE_CONNECTED);
    } catch (IOException e) {
        haltAndRetryConnection(FIRST_ATTEMPT);
    } catch (Exception e) {
        haltAndRetryConnection(FIRST_ATTEMPT);
    }
    while (mConnectionShouldBeRunning) {
        try {
            if ((null != mOs) && (!getFailedRetrying())) {
                List<Request> reqs = QueueManager.getInstance().getRpgRequests();
                int reqNum = reqs.size();
                List<Integer> reqIdList = null;
                if (Settings.sEnableProtocolTrace || Settings.sEnableSuperExpensiveResponseFileLogging) {
                    reqIdList = new ArrayList<Integer>();
                }
                if (reqNum > 0) {
                    mBaos.reset();
                    // batch payloads
                    for (int i = 0; i < reqNum; i++) {
                        Request req = reqs.get(i);
                        if ((null == req) || (req.getAuthenticationType() == Request.USE_API)) {
                            HttpConnectionThread.logV("TcpConnectionThread.run()", "Ignoring non-RPG method");
                            continue;
                        }
                        HttpConnectionThread.logD("TcpConnectionThread.run()", "Preparing [" + req.getRequestId() + "] for sending via RPG...");
                        req.setActive(true);
                        req.writeToOutputStream(mBaos, true);
                        // so we should not remove it from the queue otherwise there will be no timeout triggered.
                        if (req.isFireAndForget() && (req.mType != Request.Type.AVAILABILITY)) {
                            // f-a-f, no response,
                            // remove from queue
                            HttpConnectionThread.logD("TcpConnectionThread.run()", "Removed F&F-Request: " + req.getRequestId());
                            queueManager.removeRequest(req.getRequestId());
                        }
                        if (Settings.sEnableProtocolTrace) {
                            reqIdList.add(req.getRequestId());
                            HttpConnectionThread.logD("HttpConnectionThread.run()", "Req ID: " + req.getRequestId() + " <-> Auth: " + req.getAuth());
                        }
                    }
                    mBaos.flush();
                    byte[] payload = mBaos.toByteArray();
                    if (null != payload) {
                        // log file containing response to SD card
                        if (Settings.sEnableSuperExpensiveResponseFileLogging) {
                            StringBuffer sb = new StringBuffer();
                            for (int i = 0; i < reqIdList.size(); i++) {
                                sb.append(reqIdList.get(i));
                                sb.append("_");
                            }
                            LogUtils.logE("XXXXXXYYYXXXXXX Do not Remove this!");
                            LogUtils.logToFile(payload, "people_" + (reqIdList.size() > 0 ? reqIdList.get(0) : 0) + "_" + System.currentTimeMillis() + "_req_" + // message
                            ((int) payload[2]) + // type
                            ".txt");
                        }
                        if (Settings.sEnableProtocolTrace) {
                            Long userID = null;
                            AuthSessionHolder auth = LoginEngine.getSession();
                            if (auth != null) {
                                userID = auth.userID;
                            }
                            HttpConnectionThread.logI("TcpConnectionThread.run()", "\n  > Sending request(s) " + reqIdList.toString() + ", for user ID " + userID + " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + HessianUtils.getInHessian(new ByteArrayInputStream(payload), true) + "\n  ");
                        }
                        try {
                            synchronized (mOs) {
                                mOs.write(payload);
                                mOs.flush();
                            }
                        } catch (IOException ioe) {
                            HttpConnectionThread.logE("TcpConnectionThread.run()", "Could not send request", ioe);
                            notifyOfNetworkProblems();
                        }
                        payload = null;
                    }
                }
            }
            if (!getFailedRetrying()) {
                synchronized (requestLock) {
                    requestLock.wait();
                }
            } else {
                while (getFailedRetrying()) {
                    // loop until a retry
                    // succeeds
                    HttpConnectionThread.logI("TcpConnectionThread.run()", "Wait() for next connection retry has started.");
                    synchronized (errorLock) {
                        errorLock.wait(Settings.TCP_RETRY_BROKEN_CONNECTION_INTERVAL);
                    }
                    if (mConnectionShouldBeRunning) {
                        haltAndRetryConnection(FIRST_ATTEMPT);
                    }
                }
            }
        } catch (Throwable t) {
            HttpConnectionThread.logE("TcpConnectionThread.run()", "Unknown Error: ", t);
        }
    }
    stopConnection();
    ConnectionManager.getInstance().onConnectionStateChanged(ITcpConnectionListener.STATE_DISCONNECTED);
}
Also used : Request(com.vodafone360.people.service.io.Request) IOException(java.io.IOException) IOException(java.io.IOException) QueueManager(com.vodafone360.people.service.io.QueueManager) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 9 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class UserDataProtection method processUserChanges.

/**
 * Requests to log out from 360 if the user has changed.
 */
public void processUserChanges() {
    LogUtils.logD("UserDataProtection.checkUserChanges()");
    final LoginEngine loginEngine = EngineManager.getInstance().getLoginEngine();
    if (hasUserChanged()) {
        if (loginEngine.isLoggedIn()) {
            // User has changed, log out
            LogUtils.logD("UserDataProtection.checkUserChanges() - User has changed! Request logout.");
            loginEngine.addUiRemoveUserDataRequest();
        } else {
            LoginPreferences.clearPreferencesFile(mContext);
        }
    }
}
Also used : LoginEngine(com.vodafone360.people.engine.login.LoginEngine)

Example 10 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class ChatDbUtilsTest method testConvertUserId.

/**
 * Test ChatDbUtils.convertUserIds() method with a given parameter
 * combination.
 *
 * @param userId User ID.
 * @param networkId Network ID.
 * @param localContactId Local Contact ID.
 * @param expectedUserId Expected User ID.
 * @param expectedNetwork Expected Network ID.
 * @param expectedLocalContactId Expected Local Contact ID.
 */
private void testConvertUserId(final String userId, final int networkId, final Long localContactId, final String expectedUserId, final SocialNetwork expectedNetwork, final Long expectedLocalContactId) {
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setUserId(userId);
    chatMessage.setNetworkId(networkId);
    chatMessage.setLocalContactId(localContactId);
    ChatDbUtils.convertUserIds(chatMessage, mDatabaseHelper);
    assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected user ID", expectedUserId, chatMessage.getUserId());
    assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected network ID [" + expectedNetwork + "]", expectedNetwork.ordinal(), chatMessage.getNetworkId());
    assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected local contact ID", expectedLocalContactId, chatMessage.getLocalContactId());
}
Also used : ChatMessage(com.vodafone360.people.datatypes.ChatMessage)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)22 Contact (com.vodafone360.people.datatypes.Contact)12 ArrayList (java.util.ArrayList)12 User (com.vodafone360.people.engine.presence.User)11 Hashtable (java.util.Hashtable)9 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)7 Request (com.vodafone360.people.service.io.Request)7 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 PersistSettings (com.vodafone360.people.service.PersistSettings)6 QueueManager (com.vodafone360.people.service.io.QueueManager)6 SmallTest (android.test.suitebuilder.annotation.SmallTest)4 Identity (com.vodafone360.people.datatypes.Identity)4 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)3 RegistrationDetails (com.vodafone360.people.datatypes.RegistrationDetails)3 NetworkPresence (com.vodafone360.people.engine.presence.NetworkPresence)3 Cursor (android.database.Cursor)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)2