зеркало из https://github.com/mozilla/gecko-dev.git
Bug 897711 - Show a notification when in guest mode. r=bnicholson
This commit is contained in:
Родитель
77beea494c
Коммит
173f344670
|
@ -149,6 +149,11 @@
|
|||
<action android:name="org.mozilla.gecko.ACTION_ALERT_CALLBACK" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="org.mozilla.gecko.GUEST_SESSION_INPROGRESS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Notification API V2 -->
|
||||
<intent-filter>
|
||||
<action android:name="@ANDROID_PACKAGE_NAME@.helperBroadcastAction" />
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -489,6 +489,8 @@ just addresses the organization to follow, e.g. "This site is run by " -->
|
|||
<!ENTITY guest_session_dialog_cancel "Cancel">
|
||||
<!ENTITY new_guest_session_title "&brandShortName; will now restart">
|
||||
<!ENTITY new_guest_session_text "The person using it will not be able to see any of your personal browsing data (like saved passwords, history or bookmarks).\n\nWhen your guest is done, their browsing data will be deleted and your session will be restored.">
|
||||
<!ENTITY guest_browsing_notification_title "Guest browsing is enabled">
|
||||
<!ENTITY guest_browsing_notification_text "Tap to exit">
|
||||
|
||||
<!ENTITY exit_guest_session_title "&brandShortName; will now restart">
|
||||
<!ENTITY exit_guest_session_text "The browsing data from this session will be deleted.">
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 1.1 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 1.3 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 782 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 669 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 1.5 KiB |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 891 B |
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
<resources>
|
||||
|
||||
<item type="id" name="guestNotification"/>
|
||||
|
||||
</resources>
|
|
@ -447,6 +447,8 @@
|
|||
<string name="guest_session_dialog_cancel">&guest_session_dialog_cancel;</string>
|
||||
<string name="new_guest_session_title">&new_guest_session_title;</string>
|
||||
<string name="new_guest_session_text">&new_guest_session_text;</string>
|
||||
<string name="guest_browsing_notification_title">&guest_browsing_notification_title;</string>
|
||||
<string name="guest_browsing_notification_text">&guest_browsing_notification_text;</string>
|
||||
|
||||
<string name="exit_guest_session_title">&exit_guest_session_title;</string>
|
||||
<string name="exit_guest_session_text">&exit_guest_session_text;</string>
|
||||
|
|
Загрузка…
Ссылка в новой задаче