-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#308): Add prominent disclosure on startup requesting user to lin…
…k app and domain (#354)
- Loading branch information
Showing
14 changed files
with
393 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,9 @@ | |
<activity android:name="RequestSendSmsPermissionActivity" | ||
android:screenOrientation="portrait" | ||
tools:ignore="DiscouragedApi"/> | ||
<activity android:name="DomainVerificationActivity" | ||
android:screenOrientation="portrait" | ||
tools:ignore="DiscouragedApi" /> | ||
<activity android:name="AppUrlIntentActivity" | ||
Check warning Code scanning / SonarCloud Exported component access should be restricted with appropriate permissions Medium
Implement permissions on this exported component. See more on SonarCloud
|
||
android:launchMode="singleInstance" | ||
android:exported="true"> | ||
|
42 changes: 42 additions & 0 deletions
42
src/main/java/org/medicmobile/webapp/mobile/DomainVerificationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.medicmobile.webapp.mobile; | ||
|
||
import static org.medicmobile.webapp.mobile.MedicLog.trace; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.provider.Settings; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
|
||
public class DomainVerificationActivity extends Activity { | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
trace(this, "onCreate()"); | ||
|
||
setContentView(R.layout.request_app_domain_association); | ||
|
||
String appName = getResources().getString(R.string.app_name); | ||
String title = getResources().getString(R.string.domainAppAssociationTitle); | ||
TextView field = findViewById(R.id.domainAppAssociationTitleText); | ||
field.setText(String.format(title, appName)); | ||
} | ||
|
||
@SuppressLint("unused") | ||
public void onClickOk(View view) { | ||
trace(this, "DomainVerificationActivity :: User agreed with prominent disclosure message."); | ||
@SuppressLint("InlinedApi") Intent intent = new Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, Uri.parse("package:" + this.getPackageName())); | ||
this.startActivity(intent); | ||
finish(); | ||
} | ||
|
||
@SuppressLint("unused") | ||
public void onClickNegative(View view) { | ||
trace(this, "DomainVerificationActivity :: User disagreed with prominent disclosure message."); | ||
finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:paddingLeft="16dp" | ||
android:paddingRight="16dp"> | ||
|
||
<TextView | ||
android:id="@+id/domainAppAssociationTitleText" | ||
style="@android:style/Widget.DeviceDefault.Light.TextView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="100dp" | ||
android:gravity="center" | ||
android:padding="10dp" | ||
android:text="@string/domainAppAssociationTitle" | ||
android:textSize="25sp" | ||
android:textStyle="bold" /> | ||
|
||
<TextView | ||
android:id="@+id/domainAppAssociationMessageText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/domainAppAssociationTitleText" | ||
android:layout_marginTop="10dp" | ||
android:gravity="center" | ||
android:padding="20dp" | ||
android:text="@string/domainAppAssociationMessage" | ||
android:textSize="18sp" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/domainAppAssociationButtons" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignParentBottom="true" | ||
android:paddingLeft="20dp" | ||
android:paddingRight="20dp" | ||
android:paddingBottom="20dp"> | ||
|
||
<Button | ||
android:id="@+id/domainAppAssociationNegativeButton" | ||
style="@style/borderlessButton" | ||
android:onClick="onClickNegative" | ||
android:text="@string/domainAppAssociationRequestDenyButton" | ||
tools:ignore="OnClick" | ||
android:layout_marginTop="10dp"/> | ||
|
||
<View | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" /> | ||
|
||
<Button | ||
android:id="@+id/domainAppAssociationOkButton" | ||
style="@style/standardButton" | ||
android:layout_width="137dp" | ||
android:background="@android:color/holo_blue_dark" | ||
android:onClick="onClickOk" | ||
android:text="@string/domainAppAssociationRequestOkButton" | ||
android:textColor="#ffffff" | ||
tools:ignore="OnClick" /> | ||
|
||
</LinearLayout> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/test/java/org/medicmobile/webapp/mobile/DomainVerificationActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.medicmobile.webapp.mobile; | ||
|
||
import static android.provider.Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.robolectric.Shadows.shadowOf; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
|
||
import androidx.lifecycle.Lifecycle; | ||
import androidx.test.core.app.ActivityScenario; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.MockedStatic; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.shadows.ShadowActivity; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class DomainVerificationActivityTest { | ||
@Test | ||
public void onClickOk_withSdkVersionGreaterThanS_startAppOpenByDefaultSettings() { | ||
try ( | ||
MockedStatic<MedicLog> medicLogMock = mockStatic(MedicLog.class); | ||
ActivityScenario<DomainVerificationActivity> scenario = ActivityScenario.launch(DomainVerificationActivity.class) | ||
) { | ||
scenario.onActivity(domainVerificationActivity -> { | ||
ShadowActivity shadowActivity = shadowOf(domainVerificationActivity); | ||
|
||
domainVerificationActivity.onClickOk(null); | ||
|
||
Intent startedIntent = shadowActivity.getNextStartedActivity(); | ||
assertNotNull(startedIntent); | ||
assertEquals(ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, startedIntent.getAction()); | ||
assertEquals("package:" + domainVerificationActivity.getPackageName(), startedIntent.getData().toString()); | ||
|
||
medicLogMock.verify(() -> MedicLog.trace( | ||
any(DomainVerificationActivity.class), | ||
eq("DomainVerificationActivity :: User agreed with prominent disclosure message.") | ||
)); | ||
}); | ||
|
||
scenario.moveToState(Lifecycle.State.DESTROYED); | ||
} | ||
} | ||
|
||
@Test | ||
public void onClickNegative_finishActivity() { | ||
try ( | ||
MockedStatic<MedicLog> medicLogMock = mockStatic(MedicLog.class); | ||
ActivityScenario<DomainVerificationActivity> scenario = ActivityScenario.launchActivityForResult(DomainVerificationActivity.class) | ||
) { | ||
scenario.onActivity(domainVerificationActivity -> { | ||
domainVerificationActivity.onClickNegative(null); | ||
|
||
assertEquals(Activity.RESULT_CANCELED, scenario.getResult().getResultCode()); | ||
|
||
medicLogMock.verify(() -> MedicLog.trace( | ||
any(DomainVerificationActivity.class), | ||
eq("DomainVerificationActivity :: User disagreed with prominent disclosure message.") | ||
)); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.