Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export profile on pre-19 API levels #320

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.aprsdroid.app;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
55 changes: 55 additions & 0 deletions androidTest/java/org/aprsdroid/app/ProfileTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.aprsdroid.app;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.junit.Assume.assumeTrue;

import android.Manifest;
import android.app.Instrumentation;
import android.content.Intent;
import android.os.Environment;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.intent.Intents;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.GrantPermissionRule;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class ProfileTests {
@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Before
public void setUp() {
Intents.init();
}

@After
public void tearDown() {
Intents.release();
}

@Test
public void testThatExportProfileOpensTheChooser() {
assumeTrue(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()));
ActivityScenario scenario = ActivityScenario.launch(PrefsAct.class);
Intents.intending(hasAction(Intent.ACTION_CHOOSER)).respondWith(new Instrumentation.ActivityResult(0, null));
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().getTargetContext());
onView(withText(R.string.profile_export))
.perform(click());
Intents.intended(hasAction(Intent.ACTION_MAIN)); // Validate the activity launch
Intents.intended(allOf(hasAction(Intent.ACTION_CHOOSER)));
Intents.assertNoUnverifiedIntents();
}
}
16 changes: 11 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

Expand Down Expand Up @@ -90,7 +90,7 @@ android {

resValue "string", "google_maps_key", mapsApiKey()

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
useLibrary 'org.apache.http.legacy'
compileOptions {
Expand Down Expand Up @@ -167,7 +167,13 @@ dependencies {


implementation 'com.squareup.okio:okio:2.1.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'

testImplementation 'junit:junit:4.13.1'
testImplementation 'org.hamcrest:hamcrest-core:1.3'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
}
1 change: 1 addition & 0 deletions res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="APRSdroid" path="Documents/APRSdroid" />
<external-path name="APRSdroid-top" path="APRSdroid" />
</paths>
13 changes: 10 additions & 3 deletions src/PrefsAct.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import _root_.android.preference.PreferenceActivity
import _root_.android.preference.PreferenceManager
import _root_.android.view.{Menu, MenuItem}
import _root_.android.widget.Toast
import android.util.Log

import java.text.SimpleDateFormat
import java.io.{File, PrintWriter}
import java.util.Date

import org.json.JSONObject

class PrefsAct extends PreferenceActivity {
val TAG = "APRSdroid.PrefsAct"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit-pick, this would normally be a Java private final static and I believe it's currently an instance variable. I'd have to look up what the Scala version of that is. I believe I copied this from the style used elsewhere, however.


lazy val db = StorageDatabase.open(this)
lazy val prefs = new PrefsWrapper(this)

Expand All @@ -33,7 +37,10 @@ class PrefsAct extends PreferenceActivity {

UIHelper.shareFile(this, file, filename)
} catch {
case e : Exception => Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show()
case e : Exception => {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show()
Log.i(TAG, "Caught exception sharing file: " + e, e)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this shouldn't be Log.e or at least Log.w ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Probably any errors that warrant generating an on-screen toast message should probably be warn or higher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further thought, if we ever hit that catch, it basically means that a piece of user functionality was not able to do its job so it should probably be an error-level log. I can push an update this evening if preferred or, I think this could even be edited from the web though without the GitHub CI branch in place to automatically compile and test, I don't know if I'd trust that.

}
}
}

Expand Down Expand Up @@ -62,7 +69,7 @@ class PrefsAct extends PreferenceActivity {

def resolveContentUri(uri : Uri) = {
val Array(storage, path) = uri.getPath().replace("/document/", "").split(":", 2)
android.util.Log.d("PrefsAct", "resolveContentUri s=" + storage + " p=" + path)
android.util.Log.d(TAG, "resolveContentUri s=" + storage + " p=" + path)
if (storage == "primary")
Environment.getExternalStorageDirectory() + "/" + path
else
Expand Down Expand Up @@ -108,7 +115,7 @@ class PrefsAct extends PreferenceActivity {
}

override def onActivityResult(reqCode : Int, resultCode : Int, data : Intent) {
android.util.Log.d("PrefsAct", "onActResult: request=" + reqCode + " result=" + resultCode + " " + data)
android.util.Log.d(TAG, "onActResult: request=" + reqCode + " result=" + resultCode + " " + data)
if (resultCode == android.app.Activity.RESULT_OK && reqCode == 123456) {
parseFilePickerResult(data, "mapfile", R.string.mapfile_error)
} else
Expand Down