ECode CAccessibilityServiceClientWrapper::ExecuteMessage(
    /* [in] */ IMessage* message)
{
    Int32 what, arg1;
    message->GetWhat(&what);
    message->GetArg1(&arg1);

    switch (what) {
        case DO_ON_ACCESSIBILITY_EVENT : {
            AutoPtr<IInterface> obj;
            message->GetObj((IInterface**)&obj);
            IAccessibilityEvent* event = IAccessibilityEvent::Probe(obj);
            if (event != NULL) {
                AutoPtr<IAccessibilityInteractionClientHelper> helper;
                CAccessibilityInteractionClientHelper::AcquireSingleton((IAccessibilityInteractionClientHelper**)&helper);
                AutoPtr<IAccessibilityInteractionClient> client;
                helper->GetInstance((IAccessibilityInteractionClient**)&client);

                client->OnAccessibilityEvent(event);
                mCallback->OnAccessibilityEvent(event);
                event->Recycle();
            }
            return NOERROR;
        }

        case DO_ON_INTERRUPT :
            mCallback->OnInterrupt();
            return NOERROR;

        case DO_SET_SET_CONNECTION : {
            AutoPtr<IAccessibilityInteractionClientHelper> helper;
            CAccessibilityInteractionClientHelper::AcquireSingleton((IAccessibilityInteractionClientHelper**)&helper);
            AutoPtr<IAccessibilityInteractionClient> client;
            helper->GetInstance((IAccessibilityInteractionClient**)&client);

            const Int32 connectionId = arg1;
            AutoPtr<IInterface> obj;
            message->GetObj((IInterface**)&obj);
            IIAccessibilityServiceConnection* connection = IIAccessibilityServiceConnection::Probe(obj);

            if (connection != NULL) {
                client->AddConnection(connectionId, connection);
                mCallback->OnSetConnectionId(connectionId);
                mCallback->OnServiceConnected();
            }
            else {
                client->RemoveConnection(connectionId);
                mCallback->OnSetConnectionId(IAccessibilityInteractionClient::NO_ID);
            }
            return NOERROR;
        }

        case DO_ON_GESTURE : {
            Boolean result;
            mCallback->OnGesture(arg1, &result);
            return NOERROR;
        }

        default :
            // Logger::W(LOG_TAG, "Unknown message type %d", what);
            break;
    }
    return NOERROR;
}
Esempio n. 2
0
ECode IAccessibilityServiceClientWrapper::ExecuteMessage(
    /* [in] */ IMessage* message)
{
    Int32 what, arg1;
    message->GetWhat(&what);
    message->GetArg1(&arg1);

    switch (what) {
        case DO_ON_ACCESSIBILITY_EVENT : {
            AutoPtr<IInterface> obj;
            message->GetObj((IInterface**)&obj);

            IAccessibilityEvent* event = IAccessibilityEvent::Probe(obj);
            if (event != NULL) {
                AutoPtr<IAccessibilityInteractionClient> client = CAccessibilityInteractionClient::GetInstance();
                client->OnAccessibilityEvent(event);
                mCallback->OnAccessibilityEvent(event);
                // Make sure the event is recycled.
                // try {
                IAccessibilityRecord::Probe(event)->Recycle();
                // } catch (IllegalStateException ise) {
                //             /* ignore - best effort */
                // }
            }
            return NOERROR;
        }

        case DO_ON_INTERRUPT :
            mCallback->OnInterrupt();
            return NOERROR;

        case DO_SET_SET_CONNECTION : {
            AutoPtr<IAccessibilityInteractionClient> client = CAccessibilityInteractionClient::GetInstance();
            mConnectionId = arg1;
            AutoPtr<IInterface> obj;
            message->GetObj((IInterface**)&obj);
            IIAccessibilityServiceConnection* connection = IIAccessibilityServiceConnection::Probe(obj);

            if (connection != NULL) {
                client->AddConnection(mConnectionId, connection);
                mCallback->OnSetConnectionId(mConnectionId);
                mCallback->OnServiceConnected();
            }
            else {
                client->RemoveConnection(mConnectionId);
                client->ClearCache();
                mCallback->OnSetConnectionId(IAccessibilityInteractionClient::NO_ID);
            }
            return NOERROR;
        }

        case DO_ON_GESTURE : {
            Boolean result;
            mCallback->OnGesture(arg1, &result);
            break;
        }
        case DO_CLEAR_ACCESSIBILITY_CACHE : {
            AutoPtr<IAccessibilityInteractionClient> client = CAccessibilityInteractionClient::GetInstance();
            client->ClearCache();
            return NOERROR;
        }

        case DO_ON_KEY_EVENT : {
            AutoPtr<IInterface> obj;
            message->GetObj((IInterface**)&obj);
            AutoPtr<IKeyEvent> event = IKeyEvent::Probe(obj);
            // try {
            AutoPtr<IAccessibilityInteractionClient> client = CAccessibilityInteractionClient::GetInstance();
            AutoPtr<IIAccessibilityServiceConnection> connection;
            client->GetConnection(mConnectionId, (IIAccessibilityServiceConnection**)&connection);
            if (connection != NULL) {
                Boolean result;
                mCallback->OnKeyEvent(event, &result);
                Int32 sequence = arg1;
                // try {
                connection->SetOnKeyEventResult(result, sequence);
                // } catch (RemoteException re) {
                            /* ignore */
                // }
            }
            // } finally {
                    // Make sure the event is recycled.
                    // try {
            IAccessibilityRecord::Probe(event)->Recycle();
                    // } catch (IllegalStateException ise) {
                        /* ignore - best effort */
                    // // }
            // }
            return NOERROR;
        }

        default :
            Logger::W("IAccessibilityServiceClientWrapper", "Unknown message type %d", what);
            return NOERROR;
    }
    return NOERROR;
}