Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #85 from google/useintent
app: run test from an Intent
  • Loading branch information
philburk committed Jun 21, 2019
2 parents 50d15bb + 6f1f700 commit 09b13c6
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 31 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.sonodroid.synthmark"
minSdkVersion 26
targetSdkVersion 26
versionCode 6
versionName "1.6"
versionCode 7
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Expand Up @@ -3,6 +3,7 @@
package="com.sonodroid.synthmark">

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name=".AppObject"
Expand All @@ -11,7 +12,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:launchMode="singleTask" android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
29 changes: 20 additions & 9 deletions android/app/src/main/java/com/sonodroid/synthmark/AppObject.java
Expand Up @@ -36,7 +36,7 @@
public class AppObject extends Application {
public final static String TAG = "SynthMark";

private final static int PROGRESS_REFRESH_RATE_MS = 300;
private final static int PROGRESS_REFRESH_RATE_MS = 200;
private final static int PROGRESS_WARM_UP_WAIT = 300;

private final static int NATIVETEST_STATUS_RUNNING = 2; //from NativeTest.h
Expand Down Expand Up @@ -212,6 +212,10 @@ List<Param> getParamsForTest(int testId) {
return paramList;
}

List<Param> getParamsForTest() {
return getParamsForTest(getCurrentTestId());
}

@Override
protected void finalize() throws Throwable {
testClose(mNativeTest);
Expand Down Expand Up @@ -263,8 +267,11 @@ public static String getDeviceInfo(){
info.append("\n");
}

String boostInfo = readFile(SCHEDTUNE_BOOST_FILE_NAME);
info.append("schedtune.boost: " + boostInfo.trim() + "\n");
String boostInfo = readFile(SCHEDTUNE_BOOST_FILE_NAME).trim();
if (boostInfo.length() == 0) {
boostInfo = "----";
}
info.append("schedtune.boost: " + boostInfo + "\n");

return info.toString();
}
Expand Down Expand Up @@ -320,17 +327,20 @@ protected String doInBackground(String... params) {
while (running) {
if (mNativeTest != 0) {
updateProgressBar();
updateOutputReport();

int status = testStatus(mNativeTest);
if (status != NATIVETEST_STATUS_RUNNING) {
running = false;
}

try {
Thread.sleep(PROGRESS_REFRESH_RATE_MS);
} catch (InterruptedException e) {
e.printStackTrace();
}


updateOutputReport();
} else {
break;
}
Expand Down Expand Up @@ -358,6 +368,7 @@ private void updateOutputReport() {
protected void onPostExecute(String result) {
log("TestProgressTask.onPostExecute result: " + result);
postNotificationTestShortUpdate(mTestId, result);
postNotificationTestCompleted(mTestId);
}
}

Expand All @@ -373,16 +384,15 @@ protected String doInBackground(String... params) {
log("Started running test... ["+mTestId +"]");
testInit(mNativeTest, mTestId);

postNotificationTestUpdate(mTestId, "Test inited");
postNotificationTestUpdate(mTestId, "Test initialized\n");
testRun(mNativeTest);
setRunning(false);

return "done"; // gets passed to onPostExecute()
}

protected void onPostExecute(String result) {
log("TestTack.onPostExecute result: " + result);
postNotificationTestCompleted(mTestId);
log("TestTask.onPostExecute result: " + result);
setRunning(false);
}
}
Expand Down Expand Up @@ -425,7 +435,8 @@ public void postNotificationTestStarted(int testId) {
}

public void postNotificationTestUpdate(int testId, String message) {
log("test update");
int end = Math.min(message.length(), 40);
log("Post test update: #" + message.length() + ", " + message.substring(0, end));
Intent intent = new Intent(AppObject.INTENT_NOTIFICATION);
intent.putExtra(INTENT_NOTIFICATION_TYPE, NOTIFICATION_TEST_UPDATE);
intent.putExtra(NOTIFICATION_KEY_TEST_ID, testId);
Expand All @@ -434,7 +445,7 @@ public void postNotificationTestUpdate(int testId, String message) {
}

public void postNotificationTestCompleted(int testId) {
log("Test ended");
log("Post test completed");
Intent intent = new Intent(AppObject.INTENT_NOTIFICATION);
intent.putExtra(INTENT_NOTIFICATION_TYPE, NOTIFICATION_TEST_COMPLETED);
intent.putExtra(NOTIFICATION_KEY_TEST_ID, testId);
Expand Down
Expand Up @@ -40,12 +40,14 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onPause() {
super.onPause();
log("onPause() UNregister Broadcast receiver for notification");
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
}

@Override
protected void onResume() {
super.onResume();
log("onResume() Register Broadcast receiver for notification");
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
new IntentFilter(AppObject.INTENT_NOTIFICATION));
}
Expand Down Expand Up @@ -73,26 +75,26 @@ public void setViewEnable(View v, boolean enable) {
}

public void notificationTestStarted(int testId) {
log("notificationTestStarted " + testId);

log("notificationTestStarted(" + testId + ")");
}

public void notificationTestUpdate(int testId, String message) {
log("notificationTestUpdate " + testId + " m: " + message);
log("notificationTestUpdate(" + testId + ",...)");
}

public void notificationTestCompleted(int testId) {
log("notificationTestCompleted " + testId);
log("notificationTestCompleted(" + testId + ")");
}

public void notificationTestShortUpdate(int testId, String message) {
log("notificationTestShortUpdate " + testId + " m: " + message);
// log("notificationTestShortUpdate(" + testId + ", " + message + ")");
}

private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int type = intent.getIntExtra(AppObject.INTENT_NOTIFICATION_TYPE, -1);
log("BroadcastReceiver: type = " + type);

switch(type) {
case AppObject.NOTIFICATION_TEST_STARTED: {
Expand Down

0 comments on commit 09b13c6

Please sign in to comment.