Bug 1476720 - Set MLS notification action. r?sdaswani
Added a content action which will open the privacy settings when
tapping the mozilla location services notification.
MozReview-Commit-ID: 9h85amcoF0T
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -73,16 +73,20 @@ import java.util.UUID;
public class GeckoApplication extends Application
implements HapticFeedbackDelegate {
private static final String LOG_TAG = "GeckoApplication";
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
private static final String MEDIA_DECODING_PROCESS_CRASH = "MEDIA_DECODING_PROCESS_CRASH";
private static NotificationChannel defaultNotificationChannel = null;
+ /**
+ * Mozilla Location Services Notification Channel.
+ */
+ private static NotificationChannel mlsNotificationChannel = null;
private boolean mInBackground;
private boolean mPausedGecko;
private boolean mIsInitialResume;
private LightweightTheme mLightweightTheme;
private RefWatcher mRefWatcher;
@@ -353,16 +357,17 @@ public class GeckoApplication extends Ap
MulticastDNSManager.getInstance(context).init();
GeckoService.register();
IntentHelper.init();
if (!AppConstants.Versions.preO) {
createDefaultNotificationChannel();
+ createMLSNotificationChannel();
}
EventDispatcher.getInstance().registerGeckoThreadListener(mListener,
"Distribution:GetDirectories",
null);
EventDispatcher.getInstance().registerUiThreadListener(mListener,
"Gecko:Exited",
"RuntimePermissions:Check",
@@ -442,16 +447,30 @@ public class GeckoApplication extends Ap
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
defaultNotificationChannel = notificationManager.getNotificationChannel(DEFAULT_CHANNEL);
if (defaultNotificationChannel == null) {
defaultNotificationChannel = new NotificationChannel(DEFAULT_CHANNEL, DEFAULT_NAME, DEFAULT_IMPORTANCE);
notificationManager.createNotificationChannel(defaultNotificationChannel);
}
}
+ @TargetApi(26)
+ private void createMLSNotificationChannel() {
+ final String DEFAULT_CHANNEL = AppConstants.MOZ_APP_DISPLAYNAME;
+ final String DEFAULT_NAME = AppConstants.MOZ_APP_DISPLAYNAME;
+ final int DEFAULT_IMPORTANCE = NotificationManager.IMPORTANCE_LOW;
+
+ NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ mlsNotificationChannel = notificationManager.getNotificationChannel(DEFAULT_CHANNEL);
+ if (mlsNotificationChannel == null) {
+ mlsNotificationChannel = new NotificationChannel(DEFAULT_CHANNEL, DEFAULT_NAME, DEFAULT_IMPORTANCE);
+ notificationManager.createNotificationChannel(mlsNotificationChannel);
+ }
+ }
+
public void onDelayedStartup() {
if (AppConstants.MOZ_ANDROID_GCM) {
// TODO: only run in main process.
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
initPushService();
}
@@ -641,16 +660,20 @@ public class GeckoApplication extends Ap
}
}
}
public static NotificationChannel getDefaultNotificationChannel() {
return defaultNotificationChannel;
}
+ public static NotificationChannel getMLSNotificationChannel() {
+ return mlsNotificationChannel;
+ }
+
public boolean isApplicationInBackground() {
return mInBackground;
}
public LightweightTheme getLightweightTheme() {
return mLightweightTheme;
}
--- a/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
@@ -2,16 +2,17 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.overlays.ui.ShareDialog;
+import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.widget.ExternalIntentDuringPrivateBrowsingPromptFragment;
import android.annotation.TargetApi;
import android.app.Activity;
@@ -236,16 +237,23 @@ public final class IntentHelper implemen
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(BrowserContract.SKIP_TAB_QUEUE_FLAG, true);
intent.putExtra(INTENT_EXTRA_TAB_ID, tab.getId());
intent.putExtra(INTENT_EXTRA_SESSION_UUID, GeckoApplication.getSessionUUID());
return intent;
}
+ public static Intent getPrivacySettingsIntent() {
+ final Intent intent = new Intent(GeckoApp.ACTION_LAUNCH_SETTINGS);
+ intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
+ GeckoPreferences.setResourceToOpen(intent, "preferences_privacy");
+ return intent;
+ }
+
public static Intent getAudioCaptureIntent() {
return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
}
public static Intent getImageCaptureIntent(final Context context, final File destinationFile) {
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri destination = FileProvider.getUriForFile(context,
AppConstants.MOZ_FILE_PROVIDER_AUTHORITY, destinationFile);
--- a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/StumblerService.java
+++ b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/StumblerService.java
@@ -2,29 +2,31 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.mozstumbler.service.stumblerthread;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Notification;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoApplication;
+import org.mozilla.gecko.IntentHelper;
import org.mozilla.gecko.R;
import org.mozilla.mozstumbler.service.AppGlobals;
import org.mozilla.mozstumbler.service.Prefs;
import org.mozilla.mozstumbler.service.stumblerthread.blocklist.WifiBlockListInterface;
import org.mozilla.mozstumbler.service.stumblerthread.datahandling.DataStorageManager;
import org.mozilla.mozstumbler.service.stumblerthread.scanners.ScanManager;
import org.mozilla.mozstumbler.service.uploadthread.UploadAlarmReceiver;
import org.mozilla.mozstumbler.service.utils.PersistentIntentService;
@@ -137,19 +139,20 @@ public class StumblerService extends Per
super.onCreate();
setIntentRedelivery(true);
}
@Override
@SuppressLint("NewApi")
public int onStartCommand(Intent intent, int flags, int startId) {
if (!AppConstants.Versions.preO) {
- final Notification notification = new NotificationCompat.Builder(this, GeckoApplication.getDefaultNotificationChannel().getId())
+ final Notification notification = new NotificationCompat.Builder(this, GeckoApplication.getMLSNotificationChannel().getId())
.setSmallIcon(R.drawable.ic_status_logo)
.setContentTitle(getString(R.string.datareporting_stumbler_notification_title))
+ .setContentIntent(createContentIntent())
.setOngoing(true)
.setShowWhen(false)
.setWhen(0)
.build();
startForeground(R.id.stumblerNotification, notification);
}
return super.onStartCommand(intent, flags, startId);
@@ -269,9 +272,14 @@ public class StumblerService extends Per
} else if (!mScanManager.isPassiveMode()) {
UploadAlarmReceiver.scheduleAlarm(this, FREQUENCY_IN_SEC_OF_UPLOAD_IN_ACTIVE_MODE, true /* repeating */);
}
}
private boolean hasLocationPermission() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
}
+
+ private PendingIntent createContentIntent() {
+ Intent intent = IntentHelper.getPrivacySettingsIntent();
+ return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
}