Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 99abd68

Browse files
keianhzobluemarvin
authored andcommitted
Setting for enable/disable restoring tabs (#2513)
* Add a setting to enable/disable tab restoration * Save state before restarting
1 parent d6412fa commit 99abd68

File tree

9 files changed

+53
-7
lines changed

9 files changed

+53
-7
lines changed

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,11 @@ public TrayWidget getTray() {
14751475
return mTray;
14761476
}
14771477

1478+
@Override
1479+
public void saveState() {
1480+
mWindows.saveState();
1481+
}
1482+
14781483
private native void addWidgetNative(int aHandle, WidgetPlacement aPlacement);
14791484
private native void updateWidgetNative(int aHandle, WidgetPlacement aPlacement);
14801485
private native void updateVisibleWidgetsNative();

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@
77
import android.preference.PreferenceManager;
88
import android.util.Log;
99

10+
import androidx.annotation.NonNull;
11+
1012
import org.json.JSONArray;
1113
import org.json.JSONObject;
1214
import org.mozilla.geckoview.GeckoSessionSettings;
1315
import org.mozilla.telemetry.TelemetryHolder;
1416
import org.mozilla.vrbrowser.R;
1517
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
1618
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
17-
import org.mozilla.vrbrowser.ui.widgets.UISurfaceTextureRenderer;
1819
import org.mozilla.vrbrowser.utils.DeviceType;
1920
import org.mozilla.vrbrowser.utils.LocaleUtils;
2021
import org.mozilla.vrbrowser.utils.StringUtils;
2122
import org.mozilla.vrbrowser.utils.SystemUtils;
2223

23-
import androidx.annotation.NonNull;
24-
2524
import java.util.ArrayList;
26-
import java.util.HashMap;
2725
import java.util.Iterator;
2826
import java.util.List;
2927
import java.util.Locale;
@@ -86,6 +84,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
8684
public final static boolean HISTORY_SYNC_DEFAULT = true;
8785
public final static boolean WHATS_NEW_DISPLAYED = false;
8886
public final static long FXA_LAST_SYNC_NEVER = 0;
87+
public final static boolean RESTORE_TABS_ENABLED = true;
8988

9089
// Enable telemetry by default (opt-out).
9190
public final static boolean CRASH_REPORTING_DEFAULT = false;
@@ -690,8 +689,16 @@ public long getFxALastSync(@NonNull String email) {
690689
} catch (Exception e) {
691690
return FXA_LAST_SYNC_NEVER;
692691
}
692+
}
693693

694+
public void setRestoreTabsEnabled(boolean isEnabled) {
695+
SharedPreferences.Editor editor = mPrefs.edit();
696+
editor.putBoolean(mContext.getString(R.string.settings_key_restore_tabs), isEnabled);
697+
editor.commit();
698+
}
694699

700+
public boolean isRestoreTabsEnabled() {
701+
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_restore_tabs), RESTORE_TABS_ENABLED);
695702
}
696703

697704
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetManagerDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import androidx.annotation.NonNull;
77

88
import org.mozilla.geckoview.GeckoSession;
9-
import org.mozilla.vrbrowser.VRBrowserActivity;
109
import org.mozilla.vrbrowser.ui.widgets.menus.VideoProjectionMenuWidget;
1110
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
1211

@@ -88,4 +87,5 @@ interface WorldClickListener {
8887
TrayWidget getTray();
8988
void addConnectivityListener(ConnectivityReceiver.Delegate aListener);
9089
void removeConnectivityListener(ConnectivityReceiver.Delegate aListener);
90+
void saveState();
9191
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public Windows(Context aContext) {
146146
restoreWindows();
147147
}
148148

149-
private void saveState() {
149+
public void saveState() {
150150
File file = new File(mContext.getFilesDir(), WINDOWS_SAVE_FILENAME);
151151
try (Writer writer = new FileWriter(file)) {
152152
WindowsState state = new WindowsState();
@@ -602,8 +602,9 @@ private WindowWidget getRightWindow() {
602602
}
603603

604604
private void restoreWindows() {
605+
boolean restoreEnabled = SettingsStore.getInstance(mContext).isRestoreTabsEnabled();
605606
WindowsState windowsState = restoreState();
606-
if (windowsState != null) {
607+
if (restoreEnabled && windowsState != null) {
607608
ArrayList<Session> restoredSessions = new ArrayList<>();
608609
if (windowsState.tabs != null) {
609610
windowsState.tabs.forEach(state -> {

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/RestartDialogWidget.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected void initialize(Context aContext) {
3030
onDismiss();
3131

3232
} else if (index == PromptDialogWidget.POSITIVE) {
33+
mWidgetManager.saveState();
3334
postDelayed(() -> SystemUtils.scheduleRestart(getContext(), 100), 500);
3435
}
3536
});

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ private void initialize(Context aContext) {
122122
setPopUpsBlocking(SettingsStore.getInstance(getContext()).isPopUpsBlockingEnabled(), false);
123123

124124
mBinding.popUpsBlockingExceptionsButton.setOnClickListener(v -> mDelegate.showView(mPopUpsBlockingExceptions));
125+
126+
mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);
127+
setRestoreTabs(SettingsStore.getInstance(getContext()).isRestoreTabsEnabled(), false);
125128
}
126129

127130
private void togglePermission(SwitchSetting aButton, String aPermission) {
@@ -171,6 +174,10 @@ public void reject() {
171174
setPopUpsBlocking(value, doApply);
172175
};
173176

177+
private SwitchSetting.OnCheckedChangeListener mRestoreTabsListener = (compoundButton, value, doApply) -> {
178+
setRestoreTabs(value, doApply);
179+
};
180+
174181
private void resetOptions() {
175182
if (mBinding.drmContentPlaybackSwitch.isChecked() != SettingsStore.DRM_PLAYBACK_DEFAULT) {
176183
setDrmContent(SettingsStore.DRM_PLAYBACK_DEFAULT, true);
@@ -199,6 +206,10 @@ private void resetOptions() {
199206
if (mBinding.popUpsBlockingSwitch.isChecked() != SettingsStore.POP_UPS_BLOCKING_DEFAULT) {
200207
setPopUpsBlocking(SettingsStore.POP_UPS_BLOCKING_DEFAULT, true);
201208
}
209+
210+
if (mBinding.restoreTabsSwitch.isChecked() != SettingsStore.RESTORE_TABS_ENABLED) {
211+
setRestoreTabs(SettingsStore.RESTORE_TABS_ENABLED, true);
212+
}
202213
}
203214

204215
private void setDrmContent(boolean value, boolean doApply) {
@@ -273,6 +284,16 @@ private void setPopUpsBlocking(boolean value, boolean doApply) {
273284
}
274285
}
275286

287+
private void setRestoreTabs(boolean value, boolean doApply) {
288+
mBinding.restoreTabsSwitch.setOnCheckedChangeListener(null);
289+
mBinding.restoreTabsSwitch.setValue(value, false);
290+
mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);
291+
292+
if (doApply) {
293+
SettingsStore.getInstance(getContext()).setRestoreTabsEnabled(value);
294+
}
295+
}
296+
276297
@Override
277298
public Point getDimensions() {
278299
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.privacy_options_width),

app/src/main/res/layout/options_privacy.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
app:buttonText="@string/developer_options_show"
4646
app:description="@string/settings_privacy_policy" />
4747

48+
<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
49+
android:id="@+id/restoreTabsSwitch"
50+
android:layout_width="match_parent"
51+
android:layout_height="wrap_content"
52+
app:description="@string/security_options_restore_tabs" />
53+
4854
<org.mozilla.vrbrowser.ui.views.settings.ButtonSetting
4955
android:id="@+id/clearCookiesSite"
5056
android:layout_width="match_parent"

app/src/main/res/values/non_L10n.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<string name="settings_key_whats_new_displayed" translatable="false">settings_key_whats_new_displayed</string>
5252
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration</string>
5353
<string name="settings_key_fxa_last_sync" translatable="false">settings_key_fxa_last_sync</string>
54+
<string name="settings_key_restore_tabs" translatable="false">settings_key_restore_tabs</string>
5455
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
5556
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
5657
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@
554554
and is used to enable or disable playback of DRM controlled content. -->
555555
<string name="security_options_drm_content">Play DRM-Controlled Content (&lt;a href="http://somesite.com/">Learn More&lt;/a>)</string>
556556

557+
<!-- This string labels an Allow/Don't Allow switch in the Privacy and Security settings dialog
558+
and is used to enable or disable the tabs restoration after a fresh app start. -->
559+
<string name="security_options_restore_tabs">Restore tabs and windows after restart</string>
560+
557561
<!-- This string labels an On/Off switch in the Privacy and Security settings dialog
558562
and is used to enable or disable tracking protection. -->
559563
<string name="security_options_tracking_protection">Tracking Protection</string>

0 commit comments

Comments
 (0)