1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 package org.mozilla.gecko; 6 7 import android.app.KeyguardManager; 8 import android.app.NotificationManager; 9 import android.app.PendingIntent; 10 import android.content.Context; 11 import android.content.Intent; 12 import android.content.res.Resources; 13 import android.support.v4.app.NotificationCompat; 14 import android.view.Window; 15 import android.view.WindowManager; 16 17 // Utility methods for entering/exiting guest mode. 18 public final class GuestSession { 19 private static final String LOGTAG = "GeckoGuestSession"; 20 21 public static final String NOTIFICATION_INTENT = "org.mozilla.gecko.GUEST_SESSION_INPROGRESS"; 22 getNotificationIntent(Context context)23 private static PendingIntent getNotificationIntent(Context context) { 24 Intent intent = new Intent(NOTIFICATION_INTENT); 25 intent.setClassName(context, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS); 26 return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 27 } 28 showNotification(Context context)29 public static void showNotification(Context context) { 30 final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 31 final Resources res = context.getResources(); 32 builder.setContentTitle(res.getString(R.string.guest_browsing_notification_title)) 33 .setContentText(res.getString(R.string.guest_browsing_notification_text)) 34 .setSmallIcon(R.drawable.alert_guest) 35 .setOngoing(true) 36 .setContentIntent(getNotificationIntent(context)); 37 38 final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 39 manager.notify(R.id.guestNotification, builder.build()); 40 } 41 hideNotification(Context context)42 public static void hideNotification(Context context) { 43 final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 44 manager.cancel(R.id.guestNotification); 45 } 46 onNotificationIntentReceived(BrowserApp context)47 public static void onNotificationIntentReceived(BrowserApp context) { 48 context.showGuestModeDialog(BrowserApp.GuestModeDialog.LEAVING); 49 } 50 51 } 52