Commit 41eada01 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Improved app to start on device tests and suites

parent 2c1f2ae4
......@@ -54,4 +54,5 @@ dependencies {
implementation 'com.android.support:support-annotations:24.0.0'
implementation 'com.android.support.test:runner:0.5'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
}
......@@ -6,12 +6,12 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<application
android:allowBackup="true"
......@@ -19,14 +19,17 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".SuitesActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TestsActivity"></activity>
<activity android:name=".LogsActivity"></activity>
</application>
</manifest>
\ No newline at end of file
......@@ -22,7 +22,7 @@ package org.linphone.tester;
import java.util.ArrayList;
import java.util.List;
public class LinphoneTestSuite extends Tester {
public class LinphoneTestSuite implements TesterLogListener {
private List<String> mList;
protected LinphoneTestSuite() {
......@@ -30,14 +30,24 @@ public class LinphoneTestSuite extends Tester {
if (!Tester.getInstance().isReady()) {
Tester.getInstance().installTester();
}
Tester.getInstance().setListener(this);
}
public void printLog(final int level, final String message) {
super.printLog(level, message);
public List<String> getList() {
return mList;
}
public void run(String[] args) {
Tester.getInstance().run(args);
}
@Override
public void onMessage(String message) {
mList.add(message);
}
public List<String> getList() {
return mList;
@Override
public void onError(String message) {
}
}
package org.linphone.tester;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.widget.TextView;
public class LogsActivity extends Activity implements TesterLogListener {
private String mSuite, mTest;
private TextView mLogs;
private String mHtmlLogs;
private Handler mHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logs);
mLogs = findViewById(R.id.logs);
mSuite = getIntent().getStringExtra("Suite");
mTest = getIntent().getStringExtra("Test");
}
@Override
protected void onStart() {
super.onStart();
Tester.getInstance().setListener(this);
new Thread() {
@Override
public void run() {
Tester.getInstance().runTestInSuite(mSuite.equals("All") ? null : mSuite, mTest.equals("All") ? null : mTest);
}
}.start();
}
@Override
public void onMessage(final String message) {
mHandler.post(new Runnable() {
@Override
public void run() {
mHtmlLogs += "<p>" + message + "</p>";
mLogs.setText(Html.fromHtml(mHtmlLogs));
}
});
}
@Override
public void onError(final String message) {
mHandler.post(new Runnable() {
@Override
public void run() {
mHtmlLogs += "<p><font color=#ff0000>" + message + "</font></p>";
mLogs.setText(Html.fromHtml(mHtmlLogs));
}
});
}
}
......@@ -20,25 +20,42 @@ package org.linphone.tester;
*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
public class SuitesActivity extends Activity {
private static String[] sSuites = {"Setup", "Register", "Tunnel", "Offer-answer", "Single Call",
"Video Call", "Audio Bypass", "Multi call", "Message", "Presence",
"Presence using server", "Account creator", "Stun", "Event", "Conference event",
"Contents", "Flexisip", "RemoteProvisioning", "QualityReporting", "LogCollection",
"Player", "DTMF", "Cpim", "Multipart", "ClonableObject", "MainDb", "PropertyContainer",
"Video", "Multicast Call", "Proxy config", "VCard", "Group Chat", "Utils", "Setup",
"Register", "Tunnel", "Offer-answer", "Single Call", "Video Call", "Audio Bypass",
"Multi call", "Message", "Presence", "Presence using server", "Account creator", "Stun",
"Event", "Conference event", "Contents", "Flexisip", "RemoteProvisioning",
"QualityReporting", "LogCollection", "Player", "DTMF", "Cpim", "Multipart",
"ClonableObject", "MainDb", "PropertyContainer", "Video", "Multicast Call",
"Proxy config", "VCard", "Group Chat", "Utils"};
public class SuitesActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_suites);
LinearLayout suitesLayout = findViewById(R.id.suitesLayout);
Tester.getInstance().setContext(getApplicationContext());
Button button = new Button(this);
button.setText("All");
button.setTag("All");
suitesLayout.addView(button);
button.setOnClickListener(this);
LinphoneTestSuite suitesList = new LinphoneTestSuite();
suitesList.run(new String[]{"tester", "--list-suites"});
for (String suite : suitesList.getList()) {
button = new Button(this);
button.setText(suite);
button.setTag(suite);
suitesLayout.addView(button);
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, TestsActivity.class);
intent.putExtra("Suite", (String)v.getTag());
startActivity(intent);
}
}
......@@ -41,6 +41,7 @@ public class Tester {
private Context mContext;
private boolean mHasBeenSetUp = false;
private TesterLogListener mListener;
private static Tester instance;
......@@ -55,6 +56,10 @@ public class Tester {
}
public void setContext(Context context) {
mContext = context;
}
public void installTester() {
if (!mHasBeenSetUp) {
try {
......@@ -70,6 +75,10 @@ public class Tester {
return mHasBeenSetUp;
}
public void setListener(TesterLogListener listener) {
mListener = listener;
}
public int runTestInSuite(String suite, String test) {
installTester();
......@@ -77,10 +86,18 @@ public class Tester {
"tester",
"--verbose",
"--resource-dir", mContext.getFilesDir().getAbsolutePath(),
"--writable-dir", mContext.getCacheDir().getPath(),
"--suite", suite,
"--test", test
"--writable-dir", mContext.getCacheDir().getPath()
}));
if (suite != null) {
list.add("--suite");
list.add(suite);
if (test != null) {
list.add("--test");
list.add(test);
}
}
String[] array = list.toArray(new String[list.size()]);
return run(array);
}
......@@ -91,7 +108,9 @@ public class Tester {
System.loadLibrary("linphonetester");
keepAccounts(true);
mContext = InstrumentationRegistry.getTargetContext();
if (mContext == null) {
mContext = InstrumentationRegistry.getTargetContext();
}
setApplicationContext(mContext);
org.linphone.core.tools.AndroidPlatformHelper.copyAssetsFromPackage(mContext,"config_files", ".");
......@@ -106,9 +125,15 @@ public class Tester {
switch(level) {
case 0:
android.util.Log.i(TAG, message);
if (mListener != null) {
mListener.onMessage(message);
}
break;
case 1:
android.util.Log.e(TAG, message);
if (mListener != null) {
mListener.onError(message);
}
break;
}
}
......
package org.linphone.tester;
public interface TesterLogListener {
void onMessage(String message);
void onError(String message);
}
package org.linphone.tester;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
public class TestsActivity extends Activity implements View.OnClickListener {
private String mSuiteName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tests);
LinearLayout testsLayout = findViewById(R.id.testsLayout);
String suiteName = getIntent().getStringExtra("Suite");
if (suiteName.equals("All")) {
Intent intent = new Intent(this, LogsActivity.class);
intent.putExtra("Suite", "All");
intent.putExtra("Test", "All");
startActivity(intent);
return;
}
mSuiteName = suiteName;
Button button = new Button(this);
button.setText("All");
button.setTag("All");
testsLayout.addView(button);
button.setOnClickListener(this);
LinphoneTestSuite suitesList = new LinphoneTestSuite();
suitesList.run(new String[]{"tester", "--list-tests", suiteName});
for (String test : suitesList.getList()) {
button = new Button(this);
button.setText(test);
button.setTag(test);
testsLayout.addView(button);
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, LogsActivity.class);
intent.putExtra("Suite", mSuiteName);
intent.putExtra("Test", (String)v.getTag());
startActivity(intent);
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LogsActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/logs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -6,4 +6,14 @@
android:layout_height="match_parent"
tools:context=".SuitesActivity">
<LinearLayout
android:id="@+id/suitesLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TestsActivity">
<LinearLayout
android:id="@+id/testsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>
<resources>
<string name="app_name">LibLinphoneTester</string>
<string name="title_activity_tests">TestsActivity</string>
<string name="title_activity_logs">LogsActivity</string>
</resources>
......@@ -8,4 +8,17 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.NoActionBar.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.NoActionBar.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment