Bug 1476720 - Set MLS notification action. r=jchen

Added a content action which will open the privacy settings when
tapping the mozilla location services notification.

MozReview-Commit-ID: 9h85amcoF0T

--HG--
extra : rebase_source : 8e8914e742023d3a6fb16397480df0d6eea6adb3
This commit is contained in:
Vlad Baicu 2018-07-25 14:32:02 +03:00
Родитель 3e8fbc2f0f
Коммит f9a7a9224f
3 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -78,6 +78,10 @@ public class GeckoApplication extends Application
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;
@ -358,6 +362,7 @@ public class GeckoApplication extends Application
if (!AppConstants.Versions.preO) {
createDefaultNotificationChannel();
createMLSNotificationChannel();
}
EventDispatcher.getInstance().registerGeckoThreadListener(mListener,
@ -447,6 +452,20 @@ public class GeckoApplication extends Application
}
}
@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.
@ -646,6 +665,10 @@ public class GeckoApplication extends Application
return defaultNotificationChannel;
}
public static NotificationChannel getMLSNotificationChannel() {
return mlsNotificationChannel;
}
public boolean isApplicationInBackground() {
return mInBackground;
}

Просмотреть файл

@ -7,6 +7,7 @@ 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;
@ -241,6 +242,13 @@ public final class IntentHelper implements BundleEventListener {
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);
}

Просмотреть файл

@ -7,6 +7,7 @@ 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;
@ -20,6 +21,7 @@ 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;
@ -142,9 +144,10 @@ public class StumblerService extends PersistentIntentService
@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)
@ -274,4 +277,9 @@ public class StumblerService extends PersistentIntentService
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);
}
}