From 173f344670c2f00e7113e2b2081cdb34bbfb0018 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 10 Sep 2014 16:32:22 -0700 Subject: [PATCH] Bug 897711 - Show a notification when in guest mode. r=bnicholson --- mobile/android/base/AndroidManifest.xml.in | 5 +++ mobile/android/base/BrowserApp.java | 23 +++++++++-- mobile/android/base/GeckoProfile.java | 9 ++++- mobile/android/base/GuestSession.java | 36 ++++++++++++++++++ .../base/locales/en-US/android_strings.dtd | 2 + mobile/android/base/prompts/Prompt.java | 6 ++- .../drawable-hdpi-v11/alert_guest.png | Bin 0 -> 1099 bytes .../resources/drawable-hdpi/alert_guest.png | Bin 0 -> 1335 bytes .../drawable-mdpi-v11/alert_guest.png | Bin 0 -> 782 bytes .../resources/drawable-mdpi/alert_guest.png | Bin 0 -> 669 bytes .../drawable-xhdpi-v11/alert_guest.png | Bin 0 -> 1514 bytes .../resources/drawable-xhdpi/alert_guest.png | Bin 0 -> 891 bytes mobile/android/base/resources/values/ids.xml | 10 +++++ mobile/android/base/strings.xml.in | 2 + 14 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 mobile/android/base/resources/drawable-hdpi-v11/alert_guest.png create mode 100644 mobile/android/base/resources/drawable-hdpi/alert_guest.png create mode 100644 mobile/android/base/resources/drawable-mdpi-v11/alert_guest.png create mode 100644 mobile/android/base/resources/drawable-mdpi/alert_guest.png create mode 100644 mobile/android/base/resources/drawable-xhdpi-v11/alert_guest.png create mode 100644 mobile/android/base/resources/drawable-xhdpi/alert_guest.png create mode 100644 mobile/android/base/resources/values/ids.xml diff --git a/mobile/android/base/AndroidManifest.xml.in b/mobile/android/base/AndroidManifest.xml.in index bd5f65961b9b..6030334d98cc 100644 --- a/mobile/android/base/AndroidManifest.xml.in +++ b/mobile/android/base/AndroidManifest.xml.in @@ -149,6 +149,11 @@ + + + + + diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 9e3151617aa2..9502666b45c4 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -183,7 +183,7 @@ public class BrowserApp extends GeckoApp } // The types of guest mdoe dialogs we show - private static enum GuestModeDialog { + public static enum GuestModeDialog { ENTERING, LEAVING } @@ -526,11 +526,15 @@ public class BrowserApp extends GeckoApp mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar); mProgressView = (ToolbarProgressView) findViewById(R.id.progress); mBrowserToolbar.setProgressBar(mProgressView); - if (Intent.ACTION_VIEW.equals(intent.getAction())) { + + final String action = intent.getAction(); + if (Intent.ACTION_VIEW.equals(action)) { // Show the target URL immediately in the toolbar. mBrowserToolbar.setTitle(intent.getDataString()); Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT); + } else if (GuestSession.NOTIFICATION_INTENT.equals(action)) { + showGuestModeDialog(BrowserApp.GuestModeDialog.LEAVING); } ((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener()); @@ -646,6 +650,13 @@ public class BrowserApp extends GeckoApp Log.e(LOGTAG, "Error initializing media manager", ex); } } + + if (getProfile().inGuestMode()) { + GuestSession.showNotification(this); + } else { + // If we're restarting, we won't destroy the activity. Make sure we remove any guest notifications that might have been shown. + GuestSession.hideNotification(this); + } } private void registerOnboardingReceiver(Context context) { @@ -1012,6 +1023,8 @@ public class BrowserApp extends GeckoApp mBrowserHealthReporter = null; } + GuestSession.onDestroy(this); + EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener)this, "Menu:Update", "Reader:Added", @@ -2806,7 +2819,7 @@ public class BrowserApp extends GeckoApp return super.onOptionsItemSelected(item); } - private void showGuestModeDialog(final GuestModeDialog type) { + public void showGuestModeDialog(final GuestModeDialog type) { final Prompt ps = new Prompt(this, new Prompt.PromptCallback() { @Override public void onPromptFinished(String result) { @@ -2903,7 +2916,9 @@ public class BrowserApp extends GeckoApp } // Only solicit feedback when the app has been launched from the icon shortcut. - if (!Intent.ACTION_MAIN.equals(action)) { + if (GuestSession.NOTIFICATION_INTENT.equals(action)) { + showGuestModeDialog(BrowserApp.GuestModeDialog.LEAVING); + } else if (!Intent.ACTION_MAIN.equals(action)) { return; } diff --git a/mobile/android/base/GeckoProfile.java b/mobile/android/base/GeckoProfile.java index d1ed00e91ac7..2ac7ff60379d 100644 --- a/mobile/android/base/GeckoProfile.java +++ b/mobile/android/base/GeckoProfile.java @@ -335,12 +335,17 @@ public final class GeckoProfile { try { // If this dir doesn't exist getDir will create it for us final File lockFile = new File(getDir(), LOCK_FILE_NAME); - final boolean result = lockFile.createNewFile(); - if (result) { + final boolean result; + lockFile.createNewFile(); + + if (lockFile.exists()) { mLocked = LockState.LOCKED; + result = true; } else { mLocked = LockState.UNLOCKED; + result = false; } + return result; } catch(IOException ex) { Log.e(LOGTAG, "Error locking profile", ex); diff --git a/mobile/android/base/GuestSession.java b/mobile/android/base/GuestSession.java index aa8bfc210b83..86937ec8ba97 100644 --- a/mobile/android/base/GuestSession.java +++ b/mobile/android/base/GuestSession.java @@ -17,9 +17,14 @@ import org.json.JSONException; import org.json.JSONObject; import android.app.KeyguardManager; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Intent; import android.content.Context; import android.content.Intent; import android.content.res.Resources; +import android.net.Uri; +import android.support.v4.app.NotificationCompat; import android.util.Log; import android.view.Window; import android.view.WindowManager; @@ -28,6 +33,8 @@ import android.widget.ListView; // Utility methods for entering/exiting guest mode. public final class GuestSession { private static final String LOGTAG = "GeckoGuestSession"; + public static final String NOTIFICATION_INTENT = "org.mozilla.gecko.GUEST_SESSION_INPROGRESS"; + private static final int NOTIFICATION_ID = LOGTAG.hashCode(); // Returns true if the user is using a secure keyguard, and its currently locked. static boolean isSecureKeyguardLocked(Context context) { @@ -66,6 +73,35 @@ public final class GuestSession { return profile.locked(); } + private static PendingIntent getNotificationIntent(Context context) { + Intent intent = new Intent(NOTIFICATION_INTENT); + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } + + public static void showNotification(Context context) { + final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); + final Resources res = context.getResources(); + builder.setContentTitle(res.getString(R.string.guest_browsing_notification_title)) + .setContentText(res.getString(R.string.guest_browsing_notification_text)) + .setSmallIcon(R.drawable.alert_guest) + .setOngoing(true) + .setContentIntent(getNotificationIntent(context)); + + final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + manager.notify(NOTIFICATION_ID, builder.build()); + } + + public static void hideNotification(Context context) { + final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + manager.cancel(NOTIFICATION_ID); + } + + public static void onDestroy(Context context) { + if (GeckoProfile.get(context).inGuestMode()) { + hideNotification(context); + } + } + public static void configureWindow(Window window) { // In guest sessions we allow showing over the keyguard. window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index 27d2e873aa57..e0b4c2ae6228 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -489,6 +489,8 @@ just addresses the organization to follow, e.g. "This site is run by " --> + + diff --git a/mobile/android/base/prompts/Prompt.java b/mobile/android/base/prompts/Prompt.java index 41b5ec27eb40..68b8125c4caf 100644 --- a/mobile/android/base/prompts/Prompt.java +++ b/mobile/android/base/prompts/Prompt.java @@ -11,6 +11,7 @@ import org.json.JSONObject; import org.mozilla.gecko.GeckoAppShell; import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.R; +import org.mozilla.gecko.gfx.LayerView; import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.Tab; import org.mozilla.gecko.Tabs; @@ -162,7 +163,10 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis private void create(String title, String text, PromptListItem[] listItems, int choiceMode) throws IllegalStateException { - GeckoAppShell.getLayerView().abortPanning(); + final LayerView view = GeckoAppShell.getLayerView(); + if (view != null) { + view.abortPanning(); + } AlertDialog.Builder builder = new AlertDialog.Builder(mContext); if (!TextUtils.isEmpty(title)) { diff --git a/mobile/android/base/resources/drawable-hdpi-v11/alert_guest.png b/mobile/android/base/resources/drawable-hdpi-v11/alert_guest.png new file mode 100644 index 0000000000000000000000000000000000000000..55d569730182a3f73787da8905f4614b983826c0 GIT binary patch literal 1099 zcmV-R1ho5!P)j{00006VoOIv0D}O7 z0E3vv27Ukl010qNS#tmY3ljhU3ljkVnw%H_000McNliru-U$K{1}Coz81?`F1K3GK zK~!ko?O8i$R6!KI^EL}Eh`Zt^7y>IHg3T5S8h_D%q)L^-YKs&?3Q3X1!bY@7Wn+~> zuvD-JK>`vKf^4%vV>AeEV~X`hlmy-Q#i+-^30#Kvnc10Lmt+ns%)YrZXU@#LH}~El z^6>ER@bK{P@E`)v3E&cdGJsY5!#4m60ImV(Z4z$^z&QZ70Mr2dmcJT+I{=0Oh-L~O z0Z>Ogege1-AnlO17r-KtvCx#s2XFyqn0B!eQuvAi?+SptOW_5%qNW(PNU`jP0OeTXG>hFF!1eVkBfD`!%`eOm-1~F=jvK zLi`x)Fs<}glc&RQ0&iBC^t8rU)6D)ifNY$-&UAE55^l_#FxL=ZWZcOq(ADT%TNu|K&hDAN;Nen*rtjhQZ`D1Re1o z9q@cksQ)TgKZ-YJz?IV-yN>vprSNqjL_MZ{jfl<)A?_*9-?H)n1HQcO*mcA|vlPD+ zQ}>F9jte0kCGeUYw4JTXAiBU5Vc-{c%$aIpCgR{auQ& zyUgrvxlU%>F%SOtWWf6PFW~-W}u-G_K>(N#2aS9I1p|O2o8#t=QH9OsXDc z9C1pXt234v+c12SzQU+nsZ_}7U6)5y)NM>(fgB@D}uoS~N7Uma!LHnSZklEFlgo51mVJJmKPyZ8>0E&)3*g}3o_-0Kq*=nHhx&(zc(ivWAfh6*2ky3jgQvBM0TC72 zM0}+M94}e9Cm^DOZ6f}03pjYt(-n}L>nK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sio4&u?jhXNu+-wKCm;YvN z0fvoMD=PFm&A+!erG4TxV7JlgR4jR$O}X7F?#XyrOj%#yD8)S6sL|>#M|X!E=zD=n zBl-^m+bRS>ghKWJd&&mDb^cd^B+#S)TboHgIx977| zwg691%o0cG++nnO`5bxc7Z-pF=Ez=D0G>Bm?Mo3Cbl5MrH=_C;qt*Tr`JKSybAa@2 zV4u-yB&!#OLN?f?^qBKCd;=^ik^h?XDe5fHQiC()I|u>A>+DiiXmwzB^|?TNc(#aJ z4|T@w{w3TT5P#=gFC40a4tF_q20+IgA^%Aobht78(tzUq_FTYcbPBR2(QvGD(eQ}s|%7U(oLghEbG{ohsdI-YN0VPZO< t_%Dfth$(X9$dMyQjvP61W>2I;Wgh4)7efaUPK`iN_~kB9QZO0^boZn@8vh>1YSO zNsA^>*OxH`yioi1pq&E7bcI)B-M~a9KV5tY>rr7-T%7_ndLtKqH3pvpzo?<8P|}U1-41^5yTug`0$| zv=-s3DHp(8o}8S9h@W;byCHtWoI_Pg4y2MhJWMW`?6&_aSSU~xk?TppJ?n>Lvy+HSYIoan z+iY|>qb<}>W(6!1*1JMQ9)UCl|sB5m!N`!1w4arf+~ zI0b9b=oWCfd}40}6%lC+=@R><01lh?Z&yU*){un0FMz`)l*vj;tjvQy+I}s7YhT-| z6%n~suuz+^z7;9d0EbZ(^*QiUM6MLQO9o&FTR&3%Ay%S9iT?zD0ZBNMHZNnuTL1t6 M07*qoM6N<$f@q^#R{#J2 literal 0 HcmV?d00001 diff --git a/mobile/android/base/resources/drawable-mdpi/alert_guest.png b/mobile/android/base/resources/drawable-mdpi/alert_guest.png new file mode 100644 index 0000000000000000000000000000000000000000..40e5ccac9ef971f2f143217768c3497092dda528 GIT binary patch literal 669 zcmeAS@N?(olHy`uVBq!ia0vp^S|H593?x6vT4n;Ns{uYCuJOqk!w>CJk_!ZSkg+7l zFPOpM*^M+1C&}C0g`tC0)&t1lEbxddW?ItLF58y`CGYFYowe=u+GhU^R&5*8#e?UpG0YTZVcfhg;e3GU;s{mF;v}VD4hIIJqH>=j!W&0&ln6 zR?3@tG2y~7wd@+DpApgVOV)2q$PhAn{U9m*eq-Yjv66=ys(!zzh}ZOZRr>ti4VJA^ z?rLXr#B{?wSBk%J`f=rSU2oi_9vF)x48ectBj+V>Y zn{+JYdJ*|sElhD?WX0M&Q$m8Z%oP46|22=js(;O^dF|xGH9ElXW$<+Mb6Mw<&;$UL C6AS?W literal 0 HcmV?d00001 diff --git a/mobile/android/base/resources/drawable-xhdpi-v11/alert_guest.png b/mobile/android/base/resources/drawable-xhdpi-v11/alert_guest.png new file mode 100644 index 0000000000000000000000000000000000000000..5bb71d4c77f27fef3352f5fb00f1ced5369757c5 GIT binary patch literal 1514 zcmVDM3)bDj`4Uz{)o+DYI9kV36GuBulxoD|x zo#dEqfXt0~EQZjXY?6F01AU6*S-LSz@<5ixY$y2}lQHC3CB+PyJM6$N8fp$#_VGHoC$c&B*}4-yBsuLHivn_2HDu2B77M10}lqhRbv!P##tCh zwghb9jyb&NtWihFwrnBhvtIGgPS4iZq6`3-CfROTSGRFk`C2J;-9b~?NcZ?M=<}Xt zlcPqudB@K$0GP3y2hHC2rK6tjBJ?FUs2+OzJsGsaNI!0*TLD}lIT*8^MMph98tG?z z^w4(r<0*?gj{^8e&*Nb}h*l&0tD~M(BfZ~;L7P1qv?Zd4?sVpi0JspcSUqB-|8&%I z-$*~e&~eFO)bfxT1T2kGb?tjJyv4yrY!*IN)!;80j`gJ%^0+ zQtCZa&npX_dgx8de0Kr#h8Pn7<|6i`uKVo;A447hzV%?t2LR?R@?8UPLMio4jXbkP z`h=sVmyPs{ue1D+hqL@-z;jH>HfMV6f?GDqo{GC5kz6(EDEjK57Xwz(q?98TpAP}N zt(5x1Vp{qez$eD9PsY^quCb9{P)gl|FGyZWv3CZ##z=myuUG~h^z{Wirz=MJX`}3@ z*9{}d{uB*5;Ys7Hi%&Gf7up8j1PFFvQ{U(N&{vA`xrUT8Z%NN)a;!;dahmj~FKBV< zwk;{T(`fJ{ z&XFWnz}GT}A-bv$4cojJv6nTkcP?jb(4_=rfABre>!b2o3}?v^BYit-g9>6$G3fup zpxRmRR)Xgq_7;utuY=<>sxQ~>*C=+wNFViTdA;#1=}?zS3LE=%k`rmhHj(VmAv{5$ zma`FMM?wOGhf)n|B-uuC)G@d=PJrua7vZ|02ei|s;u?<{;#ApYRmYnaU5%);6Qr!q z+*z@zdsv&zw4?9n7cG1SLzeG75>Z!0kI<4;*tnj1hDqLHec9Bp`<($Ay8Qg^ZQgpJiam~_C+=x=k&`eWPqM-#zLmVft?w98qk>I_1e7a4mcik z`>?&Sf1?2pC6o1fu=cl_&wmZj(Y_?7P<$W00~+*BPIQ>D_=gJs4mO}c zmvW+G#YjJ0Ky@r+Be0ee9p=XkEd{s-rRM2H>VXh2AP9mW2!bF8f*=TjAP8yl4?!{b30bm7 Q0ssI207*qoM6N<$f?#pI(EtDd literal 0 HcmV?d00001 diff --git a/mobile/android/base/resources/drawable-xhdpi/alert_guest.png b/mobile/android/base/resources/drawable-xhdpi/alert_guest.png new file mode 100644 index 0000000000000000000000000000000000000000..4ca6d845102329b0a71f6cff47a95a65a8159181 GIT binary patch literal 891 zcmeAS@N?(olHy`uVBq!ia0vp^At21b3?#L;KKKlzRtNZmxW*@E3>9?3?6Mfp*^DJY ze!&b5&u*lFI7!~_E({&4vK~MVXMsm#F#`j)FbFd;%$g$s6l5>)^mS#w$H^qbA(i={ zGLwOU$C->|ZC54ECK`Eei@nkM zC%o(O`7=Ih#@`A!xVX4}bpt(B^Jy1j;Jq;Va<}rFLO>we78(r^@NtI zb(Pc1a;?)T;aX*uht7yZSD8rY@rSRM|NM2jq?f7hF@?8!+t*tsr988mA{D>RV#Y50 zDVK_Frff|qzg>I3E`uwC-|_sJRyPxsRqU;n%OzQsX2%p&CaRx3F4R`$_F~QhFQ+R~ zUtY-tvGp!}TY7Qs)51?}L6_b~d;HIQ&fME_V9T2Wj0-#YOZx7e$j{q+m&Ix2`rpUj zIvB10@`C&6^)(W~0#OGq9AS$U4{pA2Xzv%-3{{07-YkuO>PKYEG7|4ijX!ab+fn-8 zg1c|Ere0LMaHQnRTj_f3l|hkb53|fIQ9FJ1YhT`J;Y|T2>Ua2xd}{2HS-#q^^yTuP zRnIbF_}+Qv@{|Rwvbs`j8ya!DKjzYr-TjwM6yMyAdmAD4|Lo-B8+K2O+!MY~(@O5; zbVjZfQy0$kUZf^drF`ok`?Sp3>3vQ)4t)>H7Uiz))M!1JXI<-(`7rL#nbyK3{f)aG z$i7iiJTDUdDTK>U^Yo0b*jvMCPXzMxW z#9S1f`!i|P^|Xt>9oF72E3T2bd?Yk-VYat~?SjdoRjC2;@4bJ!Z?M1euzBX*U!O00 z6R4G&b#U>$>I*Wn=HF{QcDmqe;)@L1uXPIof9pSD_S(aB%F^qJ`2t5EsE@iYH~Wl2 UXSwh)U^-*)boFyt=akR{07^xG=>Px# literal 0 HcmV?d00001 diff --git a/mobile/android/base/resources/values/ids.xml b/mobile/android/base/resources/values/ids.xml new file mode 100644 index 000000000000..4e25fe2c5c4d --- /dev/null +++ b/mobile/android/base/resources/values/ids.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/mobile/android/base/strings.xml.in b/mobile/android/base/strings.xml.in index a977c44510ba..25cd65a0075f 100644 --- a/mobile/android/base/strings.xml.in +++ b/mobile/android/base/strings.xml.in @@ -447,6 +447,8 @@ &guest_session_dialog_cancel; &new_guest_session_title; &new_guest_session_text; + &guest_browsing_notification_title; + &guest_browsing_notification_text; &exit_guest_session_title; &exit_guest_session_text;