From f8b42cb5a2302c4e0ca22fbf8f531208522308ad Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Tue, 9 Jul 2019 19:12:23 +0200 Subject: [PATCH] Fix BuildConfig.Flavor equality checks (#1381) --- .../org/mozilla/vrbrowser/VRBrowserActivity.java | 6 +++--- .../mozilla/vrbrowser/browser/SettingsStore.java | 3 ++- .../vrbrowser/telemetry/TelemetryWrapper.java | 3 ++- .../vrbrowser/ui/views/HoneycombButton.java | 2 +- .../ui/widgets/dialogs/VoiceSearchWidget.java | 4 +--- .../ui/widgets/settings/DisplayOptionsView.java | 4 ++-- .../ui/widgets/settings/PrivacyOptionsView.java | 4 +++- .../vrbrowser/{input => utils}/DeviceType.java | 16 +++++++++++++++- 8 files changed, 29 insertions(+), 13 deletions(-) rename app/src/common/shared/org/mozilla/vrbrowser/{input => utils}/DeviceType.java (55%) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 26ee34475..2f731016e 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -42,7 +42,7 @@ import org.mozilla.vrbrowser.crashreporting.CrashReporterService; import org.mozilla.vrbrowser.crashreporting.GlobalExceptionHandler; import org.mozilla.vrbrowser.geolocation.GeolocationWrapper; -import org.mozilla.vrbrowser.input.DeviceType; +import org.mozilla.vrbrowser.utils.DeviceType; import org.mozilla.vrbrowser.input.MotionEventGenerator; import org.mozilla.vrbrowser.search.SearchEngineWrapper; import org.mozilla.vrbrowser.telemetry.TelemetryWrapper; @@ -186,7 +186,7 @@ protected void onCreate(Bundle savedInstanceState) { // Set a global exception handler as soon as possible GlobalExceptionHandler.register(this.getApplicationContext()); - if (BuildConfig.FLAVOR_platform == "oculusvr") { + if (DeviceType.isOculusBuild()) { workaroundGeckoSigAction(); } mUiThread = Thread.currentThread(); @@ -497,7 +497,7 @@ public void onBackPressed() { @Override public boolean dispatchKeyEvent(KeyEvent event) { - if (BuildConfig.FLAVOR_platform == "oculusvr") { + if (DeviceType.isOculusBuild()) { int action = event.getAction(); if (action != KeyEvent.ACTION_DOWN) { return super.dispatchKeyEvent(event); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java index 53d194d9b..90241c842 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java @@ -11,6 +11,7 @@ import org.mozilla.vrbrowser.BuildConfig; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.telemetry.TelemetryWrapper; +import org.mozilla.vrbrowser.utils.DeviceType; import org.mozilla.vrbrowser.utils.LocaleUtils; import org.mozilla.vrbrowser.utils.StringUtils; @@ -362,7 +363,7 @@ public void setMSAALevel(int level) { } public boolean getLayersEnabled() { - if (BuildConfig.FLAVOR_platform.equalsIgnoreCase("oculusvr")) { + if (DeviceType.isOculusBuild()) { return true; } return false; diff --git a/app/src/common/shared/org/mozilla/vrbrowser/telemetry/TelemetryWrapper.java b/app/src/common/shared/org/mozilla/vrbrowser/telemetry/TelemetryWrapper.java index f771735d1..def782cf8 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/telemetry/TelemetryWrapper.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/telemetry/TelemetryWrapper.java @@ -23,6 +23,7 @@ import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.browser.SettingsStore; import org.mozilla.vrbrowser.search.SearchEngineWrapper; +import org.mozilla.vrbrowser.utils.DeviceType; import org.mozilla.vrbrowser.utils.UrlUtils; import java.net.URI; @@ -100,7 +101,7 @@ public static void init(Context aContext) { final JSONPingSerializer serializer = new JSONPingSerializer(); final FileTelemetryStorage storage = new FileTelemetryStorage(configuration, serializer); TelemetryScheduler scheduler; - if (BuildConfig.FLAVOR_platform.equals("oculusvr") || BuildConfig.FLAVOR_platform.equals("oculusvrStore")) { + if (DeviceType.isOculus6DOFBuild()) { scheduler = new FxRTelemetryScheduler(); } else { scheduler = new JobSchedulerTelemetryScheduler(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/HoneycombButton.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/HoneycombButton.java index 4daa627c3..d8bde0ed8 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/HoneycombButton.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/HoneycombButton.java @@ -12,7 +12,7 @@ import android.widget.LinearLayout; import android.widget.TextView; -import org.mozilla.vrbrowser.input.DeviceType; +import org.mozilla.vrbrowser.utils.DeviceType; import org.mozilla.vrbrowser.R; import androidx.annotation.Nullable; diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java index 95a663bc2..69a3c0375 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java @@ -26,13 +26,11 @@ import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; import org.mozilla.vrbrowser.browser.SettingsStore; -import org.mozilla.vrbrowser.input.DeviceType; +import org.mozilla.vrbrowser.utils.DeviceType; import org.mozilla.vrbrowser.ui.views.UIButton; -import org.mozilla.vrbrowser.ui.widgets.UIWidget; import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement; -import androidx.annotation.IdRes; import androidx.core.app.ActivityCompat; public class VoiceSearchWidget extends UIDialog implements WidgetManagerDelegate.PermissionListener, diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DisplayOptionsView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DisplayOptionsView.java index aaba0c271..89f0ccbe1 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DisplayOptionsView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/DisplayOptionsView.java @@ -21,6 +21,7 @@ import org.mozilla.vrbrowser.ui.views.settings.SingleEditSetting; import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting; import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; +import org.mozilla.vrbrowser.utils.DeviceType; class DisplayOptionsView extends SettingsView { private AudioEngine mAudio; @@ -245,8 +246,7 @@ protected void onDismiss() { if (!mMSAARadio.getValueForId(mMSAARadio.getCheckedRadioButtonId()).equals(SettingsStore.MSAA_DEFAULT_LEVEL)) { setMSAAMode(mMSAARadio.getIdForValue(SettingsStore.MSAA_DEFAULT_LEVEL), true); } - if (BuildConfig.FLAVOR_platform == "oculusvr" || - BuildConfig.FLAVOR_platform == "wavevr") { + if (DeviceType.isOculusBuild() || DeviceType.isWaveBuild()) { if (!mFoveatedAppRadio.getValueForId(mFoveatedAppRadio.getCheckedRadioButtonId()).equals(SettingsStore.FOVEATED_APP_DEFAULT_LEVEL)) { setFoveatedLevel(mFoveatedAppRadio, mFoveatedAppRadio.getIdForValue(SettingsStore.FOVEATED_APP_DEFAULT_LEVEL), true); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java index d5b13af2b..67c18b621 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/PrivacyOptionsView.java @@ -22,6 +22,7 @@ import org.mozilla.vrbrowser.ui.views.settings.ButtonSetting; import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting; import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; +import org.mozilla.vrbrowser.utils.DeviceType; import java.util.ArrayList; @@ -91,8 +92,9 @@ private void initialize(Context aContext) { mPermissionButtons.add(Pair.create(findViewById(R.id.locationPermissionButton), Manifest.permission.ACCESS_FINE_LOCATION)); mPermissionButtons.add(Pair.create(findViewById(R.id.storagePermissionButton), Manifest.permission.READ_EXTERNAL_STORAGE)); - if (BuildConfig.FLAVOR_platform == "oculusvr3dof" || BuildConfig.FLAVOR_platform == "oculusvr") + if (DeviceType.isOculusBuild()) { findViewById(R.id.cameraPermissionButton).setVisibility(View.GONE); + } for (Pair button: mPermissionButtons) { if (mWidgetManager.isPermissionGranted(button.second)) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/input/DeviceType.java b/app/src/common/shared/org/mozilla/vrbrowser/utils/DeviceType.java similarity index 55% rename from app/src/common/shared/org/mozilla/vrbrowser/input/DeviceType.java rename to app/src/common/shared/org/mozilla/vrbrowser/utils/DeviceType.java index 55d001128..8c077e33d 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/input/DeviceType.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/utils/DeviceType.java @@ -1,7 +1,9 @@ -package org.mozilla.vrbrowser.input; +package org.mozilla.vrbrowser.utils; import android.util.Log; +import org.mozilla.vrbrowser.BuildConfig; + public class DeviceType { // These values need to match those in Device.h public static final int Unknown = 0; @@ -21,4 +23,16 @@ public static void setType(int aType) { public static int getType() { return mType; } + + public static boolean isOculusBuild() { + return BuildConfig.FLAVOR_platform.toLowerCase().contains("oculusvr"); + } + + public static boolean isOculus6DOFBuild() { + return BuildConfig.FLAVOR_platform.equalsIgnoreCase("oculusvr") || BuildConfig.FLAVOR_platform.equalsIgnoreCase("oculusvrStore"); + } + + public static boolean isWaveBuild() { + return BuildConfig.FLAVOR_platform.toLowerCase().contains("wavevr"); + } }