Skip to content

Commit

Permalink
chore: revert notification prompt and add run id (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel authored Sep 3, 2024
1 parent e32ac7e commit 14d4c9e
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 386 deletions.
5 changes: 0 additions & 5 deletions app/src/dw/res/xml/preferences_global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
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
6 changes: 0 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@
</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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -82,6 +81,9 @@ 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 @@ -142,9 +144,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.withExtra(AUTOTEST_DIALOG)
.build().show(getSupportFragmentManager(), null);
} else if (notificationManager.shouldShow()) {
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK) {}
}).launch(PromptActivity.newIntent(this, PromptActivity.Prompt.CENSORSHIP_CONSENT));
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);
}
ThirdPartyServices.checkUpdates(this);
scheduleWorkers();
Expand All @@ -160,6 +167,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}
onNewIntent(getIntent());
initiateRequestForNotificationPermission();
}

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

private void initiateRequestForNotificationPermission() {

requestPermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestPermission(),
(result) -> {
if (!result) {
Snackbar.make(
binding.getRoot(),
"Please grant Notification permission from App Settings",
Snackbar.LENGTH_INDEFINITE
).setAction(R.string.Settings_Title, view -> {
ServiceUtil.launchNotificationSettings(this);
}).show();
}
}
);
requestNotificationPermission();
}

public void requestNotificationPermission() {

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 @@ -315,6 +354,17 @@ 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import static java.util.Locale.ENGLISH;

import android.Manifest;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
Expand All @@ -18,8 +16,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import org.openobservatory.ooniprobe.R;
Expand Down Expand Up @@ -76,10 +72,6 @@ public static void runAsForegroundService(AbstractActivity context,
OnTestServiceStartedListener onTestServiceStartedListener,
PreferenceManager iPreferenceManager) {

if (iPreferenceManager.shouldShowTestProgressConsent() || ! NotificationManagerCompat.from(context).areNotificationsEnabled()){
context.startActivity(PromptActivity.newIntent(context, PromptActivity.Prompt.TEST_PROGRESS_CONSENT));
}

if (ReachabilityManager.getNetworkType(context).equals(ReachabilityManager.NO_INTERNET)) {
new MessageDialogFragment.Builder()
.withTitle(context.getString(R.string.Modal_Error))
Expand Down
Loading

0 comments on commit 14d4c9e

Please sign in to comment.