mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Show notification while hotspot is active
This commit is contained in:
committed by
Sebastian Kürten
parent
d0bc17e634
commit
de8ad8f6f9
@@ -30,6 +30,7 @@ import org.briarproject.bramble.util.StringUtils;
|
|||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.conversation.ConversationActivity;
|
import org.briarproject.briar.android.conversation.ConversationActivity;
|
||||||
import org.briarproject.briar.android.forum.ForumActivity;
|
import org.briarproject.briar.android.forum.ForumActivity;
|
||||||
|
import org.briarproject.briar.android.hotspot.HotspotActivity;
|
||||||
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||||
@@ -63,9 +64,11 @@ import static android.app.Notification.DEFAULT_SOUND;
|
|||||||
import static android.app.Notification.DEFAULT_VIBRATE;
|
import static android.app.Notification.DEFAULT_VIBRATE;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
|
import static android.app.PendingIntent.getActivity;
|
||||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
|
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static androidx.core.app.NotificationCompat.CATEGORY_MESSAGE;
|
import static androidx.core.app.NotificationCompat.CATEGORY_MESSAGE;
|
||||||
import static androidx.core.app.NotificationCompat.CATEGORY_SERVICE;
|
import static androidx.core.app.NotificationCompat.CATEGORY_SERVICE;
|
||||||
@@ -274,7 +277,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
b.setWhen(0); // Don't show the time
|
b.setWhen(0); // Don't show the time
|
||||||
b.setOngoing(true);
|
b.setOngoing(true);
|
||||||
Intent i = new Intent(appContext, SplashScreenActivity.class);
|
Intent i = new Intent(appContext, SplashScreenActivity.class);
|
||||||
b.setContentIntent(PendingIntent.getActivity(appContext, 0, i, 0));
|
b.setContentIntent(getActivity(appContext, 0, i, 0));
|
||||||
if (SDK_INT >= 21) {
|
if (SDK_INT >= 21) {
|
||||||
b.setCategory(CATEGORY_SERVICE);
|
b.setCategory(CATEGORY_SERVICE);
|
||||||
b.setVisibility(VISIBILITY_SECRET);
|
b.setVisibility(VISIBILITY_SECRET);
|
||||||
@@ -619,13 +622,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
public void showSignInNotification() {
|
public void showSignInNotification() {
|
||||||
if (blockSignInReminder) return;
|
if (blockSignInReminder) return;
|
||||||
if (SDK_INT >= 26) {
|
if (SDK_INT >= 26) {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel = new NotificationChannel(
|
||||||
new NotificationChannel(REMINDER_CHANNEL_ID, appContext
|
REMINDER_CHANNEL_ID, appContext
|
||||||
.getString(
|
.getString(R.string.reminder_notification_channel_title),
|
||||||
R.string.reminder_notification_channel_title),
|
IMPORTANCE_LOW);
|
||||||
IMPORTANCE_LOW);
|
channel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
channel.setLockscreenVisibility(
|
|
||||||
NotificationCompat.VISIBILITY_SECRET);
|
|
||||||
notificationManager.createNotificationChannel(channel);
|
notificationManager.createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,7 +653,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
|
|
||||||
Intent i = new Intent(appContext, SplashScreenActivity.class);
|
Intent i = new Intent(appContext, SplashScreenActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
|
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
b.setContentIntent(PendingIntent.getActivity(appContext, 0, i, 0));
|
b.setContentIntent(getActivity(appContext, 0, i, 0));
|
||||||
|
|
||||||
notificationManager.notify(REMINDER_NOTIFICATION_ID, b.build());
|
notificationManager.notify(REMINDER_NOTIFICATION_ID, b.build());
|
||||||
}
|
}
|
||||||
@@ -720,4 +721,39 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
public void unblockAllBlogPostNotifications() {
|
public void unblockAllBlogPostNotifications() {
|
||||||
androidExecutor.runOnUiThread((Runnable) () -> blockBlogs = false);
|
androidExecutor.runOnUiThread((Runnable) () -> blockBlogs = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showHotspotNotification() {
|
||||||
|
if (SDK_INT >= 26) {
|
||||||
|
String channelTitle = appContext
|
||||||
|
.getString(R.string.hotspot_notification_channel_title);
|
||||||
|
NotificationChannel channel = new NotificationChannel(
|
||||||
|
HOTSPOT_CHANNEL_ID, channelTitle, IMPORTANCE_LOW);
|
||||||
|
channel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
|
notificationManager.createNotificationChannel(channel);
|
||||||
|
}
|
||||||
|
BriarNotificationBuilder b =
|
||||||
|
new BriarNotificationBuilder(appContext, HOTSPOT_CHANNEL_ID);
|
||||||
|
b.setSmallIcon(R.drawable.ic_wifi_tethering);
|
||||||
|
b.setColorRes(R.color.briar_brand_green);
|
||||||
|
b.setContentTitle(
|
||||||
|
appContext.getText(R.string.hotspot_notification_title));
|
||||||
|
b.setNotificationCategory(CATEGORY_SERVICE);
|
||||||
|
b.setOngoing(true);
|
||||||
|
b.setShowWhen(true);
|
||||||
|
|
||||||
|
String actionTitle =
|
||||||
|
appContext.getString(R.string.hotspot_button_stop_sharing);
|
||||||
|
Intent i = new Intent(appContext, HotspotActivity.class);
|
||||||
|
i.addFlags(FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
i.setAction(ACTION_STOP_HOTSPOT);
|
||||||
|
PendingIntent actionIntent = getActivity(appContext, 0, i, 0);
|
||||||
|
b.addAction(R.drawable.ic_portable_wifi_off, actionTitle, actionIntent);
|
||||||
|
notificationManager.notify(HOTSPOT_NOTIFICATION_ID, b.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearHotspotNotification() {
|
||||||
|
notificationManager.cancel(HOTSPOT_NOTIFICATION_ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.google.android.material.tabs.TabLayoutMediator;
|
import com.google.android.material.tabs.TabLayoutMediator;
|
||||||
@@ -28,7 +27,7 @@ import androidx.lifecycle.ViewModelProvider;
|
|||||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||||
import androidx.viewpager2.widget.ViewPager2;
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static androidx.core.app.ActivityCompat.finishAfterTransition;
|
||||||
import static org.briarproject.briar.android.AppModule.getAndroidComponent;
|
import static org.briarproject.briar.android.AppModule.getAndroidComponent;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -81,8 +80,8 @@ public abstract class AbstractTabsFragment extends Fragment {
|
|||||||
|
|
||||||
stopButton = view.findViewById(R.id.stopButton);
|
stopButton = view.findViewById(R.id.stopButton);
|
||||||
stopButton.setOnClickListener(v -> {
|
stopButton.setOnClickListener(v -> {
|
||||||
Toast.makeText(requireContext(), "Not yet implemented",
|
// also clears hotspot
|
||||||
LENGTH_SHORT).show();
|
finishAfterTransition(requireActivity());
|
||||||
});
|
});
|
||||||
connectedButton = view.findViewById(R.id.connectedButton);
|
connectedButton = view.findViewById(R.id.connectedButton);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.android.hotspot;
|
package org.briarproject.briar.android.hotspot;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_STOP_HOTSPOT;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class HotspotActivity extends BriarActivity {
|
public class HotspotActivity extends BriarActivity {
|
||||||
@@ -61,4 +64,13 @@ public class HotspotActivity extends BriarActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
if (ACTION_STOP_HOTSPOT.equals(intent.getAction())) {
|
||||||
|
// also closes hotspot
|
||||||
|
supportFinishAfterTransition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class HotspotIntroFragment extends Fragment {
|
|||||||
progressTextView.setVisibility(VISIBLE);
|
progressTextView.setVisibility(VISIBLE);
|
||||||
// TODO remove below, tell viewModel to start hotspot instead
|
// TODO remove below, tell viewModel to start hotspot instead
|
||||||
v.postDelayed(() -> {
|
v.postDelayed(() -> {
|
||||||
|
viewModel.startHotspot();
|
||||||
getParentFragmentManager().beginTransaction()
|
getParentFragmentManager().beginTransaction()
|
||||||
.setCustomAnimations(R.anim.step_next_in,
|
.setCustomAnimations(R.anim.step_next_in,
|
||||||
R.anim.step_previous_out,
|
R.anim.step_previous_out,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@@ -16,13 +17,31 @@ import javax.inject.Inject;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class HotspotViewModel extends DbViewModel {
|
class HotspotViewModel extends DbViewModel {
|
||||||
|
|
||||||
|
private final AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
HotspotViewModel(Application application,
|
HotspotViewModel(Application application,
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager,
|
LifecycleManager lifecycleManager,
|
||||||
TransactionManager db,
|
TransactionManager db,
|
||||||
AndroidExecutor androidExecutor) {
|
AndroidExecutor androidExecutor,
|
||||||
|
AndroidNotificationManager notificationManager) {
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
this.notificationManager = notificationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void startHotspot() {
|
||||||
|
notificationManager.showHotspotNotification();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopHotspot() {
|
||||||
|
notificationManager.clearHotspotNotification();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCleared() {
|
||||||
|
super.onCleared();
|
||||||
|
stopHotspot();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO copy actual code from Offline Hotspot app
|
// TODO copy actual code from Offline Hotspot app
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public interface AndroidNotificationManager {
|
|||||||
int FORUM_POST_NOTIFICATION_ID = 6;
|
int FORUM_POST_NOTIFICATION_ID = 6;
|
||||||
int BLOG_POST_NOTIFICATION_ID = 7;
|
int BLOG_POST_NOTIFICATION_ID = 7;
|
||||||
int CONTACT_ADDED_NOTIFICATION_ID = 8;
|
int CONTACT_ADDED_NOTIFICATION_ID = 8;
|
||||||
|
int HOTSPOT_NOTIFICATION_ID = 9;
|
||||||
|
|
||||||
// Channel IDs
|
// Channel IDs
|
||||||
String CONTACT_CHANNEL_ID = "contacts";
|
String CONTACT_CHANNEL_ID = "contacts";
|
||||||
@@ -43,9 +44,11 @@ public interface AndroidNotificationManager {
|
|||||||
String ONGOING_CHANNEL_ID = "zForegroundService2";
|
String ONGOING_CHANNEL_ID = "zForegroundService2";
|
||||||
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
||||||
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
||||||
|
String HOTSPOT_CHANNEL_ID = "zHotspot";
|
||||||
|
|
||||||
// Actions for pending intents
|
// Actions for pending intents
|
||||||
String ACTION_DISMISS_REMINDER = "dismissReminder";
|
String ACTION_DISMISS_REMINDER = "dismissReminder";
|
||||||
|
String ACTION_STOP_HOTSPOT = "stopHotspot";
|
||||||
|
|
||||||
Notification getForegroundNotification();
|
Notification getForegroundNotification();
|
||||||
|
|
||||||
@@ -94,4 +97,8 @@ public interface AndroidNotificationManager {
|
|||||||
void blockAllBlogPostNotifications();
|
void blockAllBlogPostNotifications();
|
||||||
|
|
||||||
void unblockAllBlogPostNotifications();
|
void unblockAllBlogPostNotifications();
|
||||||
|
|
||||||
|
void showHotspotNotification();
|
||||||
|
|
||||||
|
void clearHotspotNotification();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -698,6 +698,8 @@
|
|||||||
<string name="hotspot_button_start_sharing">Start sharing</string>
|
<string name="hotspot_button_start_sharing">Start sharing</string>
|
||||||
<string name="hotspot_button_stop_sharing">Stop sharing</string>
|
<string name="hotspot_button_stop_sharing">Stop sharing</string>
|
||||||
<string name="hotspot_progress_text_start">Setting up hotspot…</string>
|
<string name="hotspot_progress_text_start">Setting up hotspot…</string>
|
||||||
|
<string name="hotspot_notification_channel_title">Wi-Fi hotspot</string>
|
||||||
|
<string name="hotspot_notification_title">Sharing Briar offline</string>
|
||||||
<string name="hotspot_button_connected">Confirm connection</string>
|
<string name="hotspot_button_connected">Confirm connection</string>
|
||||||
<string name="hotspot_tab_manual">Manual</string>
|
<string name="hotspot_tab_manual">Manual</string>
|
||||||
<string name="hotspot_manual_wifi">To download the app on another phone, please connect to this Wi-Fi network:</string>
|
<string name="hotspot_manual_wifi">To download the app on another phone, please connect to this Wi-Fi network:</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user