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: No prompt to enable notifications #778

Merged
merged 13 commits into from
Aug 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ android {
buildConfigField 'String', 'OONI_RUN_DASHBOARD_URL', '"https://run.test.ooni.org"'
resValue "string", "APP_ID", 'org.openobservatory.ooniprobe'
resValue "string", "APP_NAME", "OONI Probe"
resValue "string", "RUN_V2_DOMAIN", "run.test.ooni.org"
buildConfigField 'String', 'SOFTWARE_NAME', 'BASE_SOFTWARE_NAME+IS_DEBUG'
buildConfigField 'String', 'COUNTLY_KEY', '"146836f41172f9e3287cab6f2cc347de3f5ddf3b"'
buildConfigField "boolean", "RUN_AUTOMATION", "false"
Expand Down Expand Up @@ -71,6 +72,7 @@ android {
buildConfigField 'String', 'BASE_SOFTWARE_NAME', '"ooniprobe-android"'
buildConfigField 'String', 'OONI_API_BASE_URL', '"https://api.prod.ooni.io"'
buildConfigField 'String', 'OONI_RUN_DASHBOARD_URL', '"https://run-v2.ooni.org"'
resValue "string", "RUN_V2_DOMAIN", "run.ooni.org"
}
dev {
dimension 'testing'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class RunTestsExpandableListViewAdapter(
convertView.findViewById<ImageView>(R.id.child_select).apply {
visibility = View.GONE
}
convertView.setPadding(parent.context.resources.getDimensionPixelOffset(R.dimen.item_padding_prefix), 0, 0, 0)
return convertView
}
}
4 changes: 4 additions & 0 deletions app/src/dw/res/drawable/ooni_phone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/logo" />
</layer-list>
85 changes: 85 additions & 0 deletions app/src/dw/res/layout/activity_prompt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:paddingHorizontal="16dp"
tools:context=".activity.PromptActivity"
android:background="@color/onboarding_background">

<ImageView
android:id="@+id/image"
android:layout_width="250dp"
android:layout_height="250dp"
android:paddingTop="50dp"
android:paddingBottom="50dp"
android:src="@drawable/logo"
android:contentDescription="@string/APP_NAME"
app:layout_constraintBaseline_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/title"
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/image"
tools:text="@tools:sample/lorem"
android:textColor="@android:color/white"/>

<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
android:layout_marginVertical="8dp"
tools:text="@tools:sample/lorem"
android:textColor="@android:color/white"/>

<Button
android:id="@+id/sounds_great"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_marginHorizontal="64dp"
android:text="@string/Modal_SoundsGreat"
android:textAllCaps="false"
android:textColor="#002B54"
app:backgroundTint="@android:color/white"
app:cornerRadius="32dp"
app:layout_constraintBottom_toTopOf="@id/not_now"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/not_now"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Modal_NotNow"
android:textAllCaps="false"
android:textColor="@android:color/white"
app:layout_constraintBottom_toTopOf="@id/dont_ask_again"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/dont_ask_again"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Prompt_DontAskAgain"
android:textAllCaps="false"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="16dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/dw/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="onboarding_image_margin_bottom">8dp</dimen>
<dimen name="item_padding_prefix">40dp</dimen>
</resources>
13 changes: 9 additions & 4 deletions app/src/dw/res/xml/preferences_global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
android:icon="@drawable/notifications"
android:key="@string/notifications"
android:title="@string/Settings_Notifications_Label">
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/notifications_enabled"
android:title="@string/Settings_Notifications_Enabled" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/notifications_enabled"
android:title="@string/Settings_Notifications_Enabled" />
<SwitchPreferenceCompat
android:defaultValue="false"
app:iconSpaceReserved="false"
android:key="@string/test_progress_notifications_enabled"
android:title="@string/Prompt_EnableTestProgressNotifications_Title" />
<PreferenceCategory
android:title="@string/Modal_EnableNotifications_Paragraph"
app:iconSpaceReserved="false" />
Expand Down
90 changes: 7 additions & 83 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.oonirun.OoniRunV2Activity"
android:exported="true"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<action android:name="${applicationId}.nettest" />

<data
android:host="run.test.ooni.org"
android:pathPrefix="/v2"
android:scheme="https" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="runv2"
android:scheme="ooni" />
</intent-filter>
</activity>
<activity
android:name=".activity.adddescriptor.AddDescriptorActivity"
android:exported="false"
Expand Down Expand Up @@ -154,59 +124,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activity.OoniRunActivity"
android:exported="true"
android:label=""
android:launchMode="singleTop"
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="userPortrait"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.App">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />

<action android:name="${applicationId}.nettest" />

<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<action android:name="${applicationId}.nettest" />

<data
android:host="run.ooni.io"
android:pathPrefix="/nettest"
android:scheme="https" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<action android:name="${applicationId}.nettest" />

<data
android:host="run.ooni.io"
android:pathPrefix="/nettest"
android:scheme="http" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="nettest"
android:scheme="ooni" />
</intent-filter>
</activity>

<activity
android:name=".activity.LogActivity"
Expand All @@ -220,11 +137,18 @@
</intent-filter>
</activity>


<activity
android:name=".activity.PromptActivity"
android:theme="@style/Theme.MaterialComponents.NoActionBar.Onboarding"
android:exported="false" />

<service
android:name=".common.service.RunTestService"
android:foregroundServiceType="dataSync"
android:icon="@drawable/notification_icon"
android:label="@string/Dashboard_Card_Run" />

<service
android:name=".common.service.RunTestJobService"
android:label="Run Test Service"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.openobservatory.ooniprobe.common.service.RunTestService.CHANNEL_ID;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand Down Expand Up @@ -81,9 +82,6 @@ public class MainActivity extends ReviewUpdatesAbstractActivity implements Confi
@Inject
AppUpdatesViewModel updatesViewModel;

private ActivityResultLauncher<String> requestPermissionLauncher;


public static Intent newIntent(Context context, int resItem) {
return new Intent(context, MainActivity.class).putExtra(RES_ITEM, resItem).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
Expand Down Expand Up @@ -144,14 +142,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.withExtra(AUTOTEST_DIALOG)
.build().show(getSupportFragmentManager(), null);
} else if (notificationManager.shouldShow()) {
new ConfirmDialogFragment.Builder()
.withTitle(getString(R.string.Modal_EnableNotifications_Title))
.withMessage(getString(R.string.Modal_EnableNotifications_Paragraph))
.withPositiveButton(getString(R.string.Modal_SoundsGreat))
.withNegativeButton(getString(R.string.Modal_NotNow))
.withNeutralButton(getString(R.string.Modal_DontAskAgain))
.withExtra(NOTIFICATION_DIALOG)
.build().show(getSupportFragmentManager(), null);
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK) {}
}).launch(PromptActivity.newIntent(this, PromptActivity.Prompt.CENSORSHIP_CONSENT));
}
ThirdPartyServices.checkUpdates(this);
scheduleWorkers();
Expand All @@ -167,7 +160,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}
onNewIntent(getIntent());
requestNotificationPermission();
}

private void scheduleWorkers() {
Expand Down Expand Up @@ -225,43 +217,6 @@ public void fetchManualUpdate() {
.observe(this, this::onManualUpdatesFetchComplete);
}

private void requestNotificationPermission() {

requestPermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestPermission(),
(result) -> {
if (!result) {
Snackbar.make(
binding.getRoot(),
"Please grant Notification permission from App Settings",
Snackbar.LENGTH_LONG
).setAction(R.string.Settings_Title, view -> {
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

//for Android 5-7
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);

// for Android 8 and above
intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());

startActivity(intent);
}).show();
}
}
);
NotificationUtility.setChannel(getApplicationContext(), CHANNEL_ID, getString(R.string.Settings_AutomatedTesting_Label), false, false, false);
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
}
}
}

/**
* Listens to updates from the {@link ManualUpdateDescriptorsWorker}.
Expand Down Expand Up @@ -360,17 +315,6 @@ protected void onNewIntent(Intent intent) {
@Override
public void onConfirmation(Serializable extra, int i) {
if (extra == null) return;
if (extra.equals(NOTIFICATION_DIALOG)) {
notificationManager.getUpdates(i == DialogInterface.BUTTON_POSITIVE);

//If positive answer reload consents and init notification
if (i == DialogInterface.BUTTON_POSITIVE){
ThirdPartyServices.reloadConsents((Application) getApplication());
}
else if (i == DialogInterface.BUTTON_NEUTRAL){
notificationManager.disableAskNotificationDialog();
}
}
if (extra.equals(AUTOTEST_DIALOG)) {
preferenceManager.setNotificationsFromDialog(i == DialogInterface.BUTTON_POSITIVE);
if (i == DialogInterface.BUTTON_POSITIVE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.openobservatory.ooniprobe.fragment.ConfirmDialogFragment;
import org.openobservatory.ooniprobe.model.database.InstalledDescriptor;
import org.openobservatory.ooniprobe.model.database.TestDescriptor;
import org.openobservatory.ooniprobe.test.test.WebConnectivity;

import java.io.Serializable;
import java.util.Locale;
Expand Down Expand Up @@ -207,6 +208,10 @@ private void onDescriptorLoaded(AbstractDescriptor<BaseNettest> descriptor) {

if (descriptor instanceof InstalledDescriptor installedDescriptor) {
try {

if (installedDescriptor.allTests().size() == 1 && installedDescriptor.allTests().get(0).getName().equals(WebConnectivity.NAME)) {
binding.expandableListView.setPadding(getResources().getDimensionPixelOffset(R.dimen.overview_test_group_list_padding_small),0,0,0);
}
if (Integer.parseInt(installedDescriptor.getTestDescriptor().getRevision()) > 1) {
getSupportFragmentManager().beginTransaction().replace(
binding.revisionsContainer.getId(),
Expand Down
Loading
Loading