Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1c8e388 authored by Xia Wang's avatar Xia Wang Committed by Android (Google) Code Review
Browse files

Merge "Port mock ril controller and tests to GB. DO NOT MERGE" into gingerbread

parents 4a962a06 afeeaf35
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#

LOCAL_PATH:=$(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_JAVA_LIBRARIES := core framework

LOCAL_STATIC_JAVA_LIBRARIES := librilproto-java

LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := mockrilcontroller

include $(BUILD_STATIC_JAVA_LIBRARY)
+156 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.mockril;

import android.os.Bundle;
import android.util.Log;
import android.telephony.PhoneNumberUtils;

import com.android.internal.communication.MsgHeader;
import com.android.internal.communication.Msg;
import com.android.internal.telephony.RilChannel;
import com.android.internal.telephony.ril_proto.RilCtrlCmds;
import com.android.internal.telephony.ril_proto.RilCmds;
import com.google.protobuf.micro.MessageMicro;

import java.io.IOException;

/**
 * Contain a list of commands to control Mock RIL. Before using these commands the devices
 * needs to be set with Mock RIL. Refer to hardware/ril/mockril/README.txt for details.
 *
 */
public class MockRilController {
    private static final String TAG = "MockRILController";
    private RilChannel mRilChannel = null;
    private Msg mMessage = null;

    public MockRilController() throws IOException {
        mRilChannel = RilChannel.makeRilChannel();
    }

    /**
     * Close the channel after the communication is done.
     * This method has to be called after the test is finished.
     */
    public void closeChannel() {
        mRilChannel.close();
    }

    /**
     * Send commands and return true on success
     * @param cmd for MsgHeader
     * @param token for MsgHeader
     * @param status for MsgHeader
     * @param pbData for Msg data
     * @return true if command is sent successfully, false if it fails
     */
    private boolean sendCtrlCommand(int cmd, long token, int status, MessageMicro pbData) {
        try {
            Msg.send(mRilChannel, cmd, token, status, pbData);
        } catch (IOException e) {
            Log.v(TAG, "send command : %d failed: " + e.getStackTrace());
            return false;
        }
        return true;
    }

    /**
     * Get control response
     * @return Msg if response is received, else return null.
     */
    private Msg getCtrlResponse() {
        Msg response = null;
        try {
            response = Msg.recv(mRilChannel);
        } catch (IOException e) {
            Log.v(TAG, "receive response for getRadioState() error: " + e.getStackTrace());
            return null;
        }
        return response;
    }

    /**
     * @return the radio state if it is valid, otherwise return -1
     */
    public int getRadioState() {
        if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_GET_RADIO_STATE, 0, 0, null)) {
            return -1;
        }
        Msg response = getCtrlResponse();
        if (response == null) {
            Log.v(TAG, "failed to get response");
            return -1;
        }
        response.printHeader(TAG);
        RilCtrlCmds.CtrlRspRadioState resp =
            response.getDataAs(RilCtrlCmds.CtrlRspRadioState.class);
        int state = resp.getState();
        if ((state >= RilCmds.RADIOSTATE_OFF) && (state <= RilCmds.RADIOSTATE_NV_READY))
            return state;
        else
            return -1;
    }

    /**
     * Set the radio state of mock ril to the given state
     * @param state for given radio state
     * @return true if the state is set successful, false if it fails
     */
    public boolean setRadioState(int state) {
        RilCtrlCmds.CtrlReqRadioState req = new RilCtrlCmds.CtrlReqRadioState();
        if (state < 0 || state > RilCmds.RADIOSTATE_NV_READY) {
            Log.v(TAG, "the give radio state is not valid.");
            return false;
        }
        req.setState(state);
        if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_RADIO_STATE, 0, 0, req)) {
            Log.v(TAG, "send set radio state request failed.");
            return false;
        }
        Msg response = getCtrlResponse();
        if (response == null) {
            Log.v(TAG, "failed to get response for setRadioState");
            return false;
        }
        response.printHeader(TAG);
        RilCtrlCmds.CtrlRspRadioState resp =
            response.getDataAs(RilCtrlCmds.CtrlRspRadioState.class);
        int curstate = resp.getState();
        return curstate == state;
    }



    /**
     * Set an MT call
     *
     * @param phoneNumber for the number shown
     */
    public boolean setMTCall(String phoneNumber) {
        RilCtrlCmds.CtrlReqSetMTCall req = new RilCtrlCmds.CtrlReqSetMTCall();

        // Check whether it is a valid number
        req.setPhoneNumber(phoneNumber);
        if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_MT_CALL, 0, 0, req)) {
            Log.v(TAG, "send CMD_SET_MT_CALL request failed");
            return false;
        }
        return true;
    }

}
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ LOCAL_MODULE_TAGS := tests

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_STATIC_JAVA_LIBRARIES := librilproto-java

LOCAL_JAVA_LIBRARIES := android.test.runner

LOCAL_PACKAGE_NAME := FrameworksTelephonyTests
+7 −0
Original line number Diff line number Diff line
@@ -32,6 +32,13 @@
        android:targetPackage="com.android.frameworks.telephonytests"
        android:label="Frameworks Telephony Tests">
    </instrumentation>

    <instrumentation android:name=".TelephonyMockRilTestRunner"
        android:targetPackage="com.android.frameworks.telephonytests"
        android:label="Test Runner for Mock Ril Tests"
    />

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

</manifest>
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.frameworks.telephonytests;

import android.os.Bundle;

import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
import android.util.Log;

import java.io.IOException;

import com.android.internal.telephony.RilChannel;
import com.android.internal.telephony.mockril.MockRilTest;

import junit.framework.TestSuite;

public class TelephonyMockRilTestRunner extends InstrumentationTestRunner {

    public RilChannel mMockRilChannel;

    @Override
    public TestSuite getAllTests() {
        log("getAllTests E");
        TestSuite suite = new InstrumentationTestSuite(this);
        suite.addTestSuite(MockRilTest.class);
        log("getAllTests X");
        return suite;
    }

    @Override
    public ClassLoader getLoader() {
        log("getLoader EX");
        return TelephonyMockRilTestRunner.class.getClassLoader();
    }

    @Override
    public void onCreate(Bundle icicle) {
        log("onCreate E");
        try {
            mMockRilChannel = RilChannel.makeRilChannel();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        log("onCreate X");

        super.onCreate(icicle);
    }

    @Override
    public void onDestroy() {
        // I've not seen this called
        log("onDestroy EX");
        super.onDestroy();
    }

    @Override
    public void onStart() {
        // Called when the instrumentation thread is started.
        // At the moment we don't need the thread so return
        // which will shut down this unused thread.
        log("onStart EX");
        super.onStart();
    }

    @Override
    public void finish(int resultCode, Bundle results) {
        // Called when complete so I ask the mMockRilChannel to quit.
        log("finish E");
        mMockRilChannel.close();
        log("finish X");
        super.finish(resultCode, results);
    }

    private void log(String s) {
        Log.e("TelephonyMockRilTestRunner", s);
    }
}
Loading