Skip to content

Commit 869f88f

Browse files
Yash MalikYash Malik
authored andcommitted
VR: Add java-side plumbing for updating GVR Keyboard
Note that this path is not exercised yet. Bug: 799584 Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel Change-Id: I45f34d54eabcbd539c17d3d87ba8c029489a0f28 Reviewed-on: https://chromium-review.googlesource.com/944750 Commit-Queue: Yash Malik <[email protected]> Reviewed-by: Michael Thiessen <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#540391}(cherry picked from commit d68a05a) Reviewed-on: https://chromium-review.googlesource.com/952644 Reviewed-by: Yash Malik <[email protected]> Cr-Commit-Position: refs/branch-heads/3359@{#52} Cr-Branched-From: 66afc5e-refs/heads/master@{#540276}
1 parent d5f66d3 commit 869f88f

File tree

13 files changed

+68
-3
lines changed

13 files changed

+68
-3
lines changed

chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public class VrShellDelegate
8787
// when used with startActivityForResult...
8888
public static final int EXIT_VR_RESULT = 7212;
8989
public static final int VR_SERVICES_UPDATE_RESULT = 7213;
90+
public static final int GVR_KEYBOARD_UPDATE_RESULT = 7214;
9091

9192
private static final int ENTER_VR_NOT_NECESSARY = 0;
9293
private static final int ENTER_VR_CANCELLED = 1;
@@ -113,6 +114,9 @@ public class VrShellDelegate
113114
private static final String VR_CORE_MARKET_URI =
114115
"market://details?id=" + VrCoreVersionChecker.VR_CORE_PACKAGE_ID;
115116

117+
private static final String GVR_KEYBOARD_MARKET_URI =
118+
"market://details?id=com.google.android.vr.inputmethod";
119+
116120
// This value is intentionally probably overkill. This is the time we need to wait from when
117121
// Chrome is resumed, to when Chrome actually renders a black frame, so that we can cancel the
118122
// stay_hidden animation and not see a white monoscopic frame in-headset. 150ms is definitely
@@ -322,6 +326,10 @@ public static boolean onActivityResultWithNative(int requestCode, int resultCode
322326
if (sInstance != null) sInstance.onVrServicesMaybeUpdated();
323327
return true;
324328
}
329+
// Handles the result of requesting to update GVR Keyboard.
330+
if (requestCode == GVR_KEYBOARD_UPDATE_RESULT) {
331+
return true;
332+
}
325333
return false;
326334
}
327335

@@ -1776,6 +1784,12 @@ public boolean onInfoBarButtonClicked(boolean isPrimary) {
17761784
buttonText, null, true);
17771785
}
17781786

1787+
/* package */ void promptForKeyboardUpdate() {
1788+
mActivity.startActivityForResult(
1789+
new Intent(Intent.ACTION_VIEW, Uri.parse(GVR_KEYBOARD_MARKET_URI)),
1790+
GVR_KEYBOARD_UPDATE_RESULT);
1791+
}
1792+
17791793
private boolean createVrShell() {
17801794
assert mVrShell == null;
17811795
if (mVrClassesWrapper == null) return false;

chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,21 @@ public void onDenied() {}
513513
}, UiUnsupportedMode.VOICE_SEARCH_NEEDS_RECORD_AUDIO_OS_PERMISSION);
514514
}
515515

516+
// Called when the user has an older GVR Keyboard installed on their device and we need them to
517+
// have a newer one.
518+
@CalledByNative
519+
public void onNeedsKeyboardUpdate() {
520+
VrShellDelegate.requestToExitVr(new OnExitVrRequestListener() {
521+
@Override
522+
public void onSucceeded() {
523+
mDelegate.promptForKeyboardUpdate();
524+
}
525+
526+
@Override
527+
public void onDenied() {}
528+
}, UiUnsupportedMode.NEEDS_KEYBOARD_UPDATE);
529+
}
530+
516531
// Exits CCT, returning to the app that opened it.
517532
@CalledByNative
518533
public void exitCct() {

chrome/browser/android/vr/gvr_keyboard_delegate.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
// This method is supplied by the VR keyboard shim, but is not part of the
1919
// GVR interface.
20-
bool gvr_keyboard_supports_selection(gvr_keyboard_context* context);
20+
bool gvr_keyboard_supports_selection();
21+
int64_t gvr_keyboard_version();
2122

2223
namespace vr {
2324

25+
// The minimum keyboard version required for the needed features to work.
26+
constexpr int64_t kMinRequiredApiVersion = 2;
27+
2428
namespace {
2529

2630
void OnKeyboardEvent(void* closure, GvrKeyboardDelegate::EventType event) {
@@ -38,6 +42,12 @@ std::unique_ptr<GvrKeyboardDelegate> GvrKeyboardDelegate::Create() {
3842
auto* gvr_keyboard = gvr_keyboard_create(callback, OnKeyboardEvent);
3943
if (!gvr_keyboard)
4044
return nullptr;
45+
46+
if (gvr_keyboard_version() < kMinRequiredApiVersion) {
47+
gvr_keyboard_destroy(&gvr_keyboard);
48+
return nullptr;
49+
}
50+
4151
delegate->Init(gvr_keyboard);
4252
return delegate;
4353
}
@@ -126,7 +136,7 @@ void GvrKeyboardDelegate::Draw(const CameraModel& model) {
126136
}
127137

128138
bool GvrKeyboardDelegate::SupportsSelection() {
129-
return gvr_keyboard_supports_selection(gvr_keyboard_);
139+
return gvr_keyboard_supports_selection();
130140
}
131141

132142
void GvrKeyboardDelegate::OnTouchStateUpdated(

chrome/browser/android/vr/gvr_keyboard_shim.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,14 @@ void gvr_keyboard_hide(gvr_keyboard_context* context) {
282282
keyboard_api->impl_gvr_keyboard_hide(context);
283283
}
284284

285-
bool gvr_keyboard_supports_selection(gvr_keyboard_context* context) {
285+
bool gvr_keyboard_supports_selection() {
286+
if (!keyboard_api)
287+
return false;
286288
return keyboard_api->min_version >= kSelectionSupportApiVersion;
287289
}
288290

291+
int64_t gvr_keyboard_version() {
292+
if (!keyboard_api)
293+
return -1;
294+
return keyboard_api->min_version;
295+
}

chrome/browser/android/vr/vr_gl_thread.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void VrGLThread::Init() {
6464
}
6565
auto* keyboard_delegate =
6666
!keyboard_delegate_ ? nullptr : keyboard_delegate_.get();
67+
if (!keyboard_delegate)
68+
ui_initial_state_.needs_keyboard_update = true;
6769
auto ui = std::make_unique<Ui>(this, this, keyboard_delegate,
6870
text_input_delegate_.get(), ui_initial_state_);
6971
if (keyboard_enabled) {

chrome/browser/android/vr/vr_shell.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ void VrShell::OnUnsupportedMode(UiUnsupportedMode mode) {
715715
Java_VrShellImpl_onUnhandledPermissionPrompt(env, j_vr_shell_);
716716
return;
717717
}
718+
case UiUnsupportedMode::kNeedsKeyboardUpdate: {
719+
JNIEnv* env = base::android::AttachCurrentThread();
720+
Java_VrShellImpl_onNeedsKeyboardUpdate(env, j_vr_shell_);
721+
return;
722+
}
718723
case UiUnsupportedMode::kCount:
719724
NOTREACHED(); // Should never be used as a mode.
720725
return;

chrome/browser/vr/model/modal_prompt_type.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ UiUnsupportedMode GetReasonForPrompt(ModalPromptType prompt) {
1616
return UiUnsupportedMode::kVoiceSearchNeedsRecordAudioOsPermission;
1717
case kModalPromptTypeGenericUnsupportedFeature:
1818
return UiUnsupportedMode::kGenericUnsupportedFeature;
19+
case kModalPromptTypeUpdateKeyboard:
20+
return UiUnsupportedMode::kNeedsKeyboardUpdate;
1921
case kModalPromptTypeNone:
2022
return UiUnsupportedMode::kCount;
2123
}

chrome/browser/vr/model/modal_prompt_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum ModalPromptType {
1414
kModalPromptTypeExitVRForSiteInfo,
1515
kModalPromptTypeExitVRForVoiceSearchRecordAudioOsPermission,
1616
kModalPromptTypeGenericUnsupportedFeature,
17+
kModalPromptTypeUpdateKeyboard,
1718
};
1819

1920
UiUnsupportedMode GetReasonForPrompt(ModalPromptType prompt);

chrome/browser/vr/model/model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct Model {
4949
bool can_apply_new_background = false;
5050
bool background_loaded = false;
5151
bool supports_selection = true;
52+
bool needs_keyboard_update = false;
5253

5354
// WebVR state.
5455
WebVrModel web_vr;

chrome/browser/vr/ui.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ void Ui::ShowExitVrPrompt(UiUnsupportedMode reason) {
160160
model_->active_modal_prompt_type =
161161
kModalPromptTypeGenericUnsupportedFeature;
162162
return;
163+
case UiUnsupportedMode::kNeedsKeyboardUpdate:
164+
model_->active_modal_prompt_type = kModalPromptTypeUpdateKeyboard;
165+
return;
163166
case UiUnsupportedMode::kCount:
164167
NOTREACHED(); // Should never be used as a mode (when |enabled| is true).
165168
return;
@@ -437,6 +440,7 @@ void Ui::InitializeModel(const UiInitialState& ui_initial_state) {
437440
ui_initial_state.skips_redraw_when_not_dirty;
438441
model_->background_available = ui_initial_state.assets_available;
439442
model_->supports_selection = ui_initial_state.supports_selection;
443+
model_->needs_keyboard_update = ui_initial_state.needs_keyboard_update;
440444
}
441445

442446
void Ui::AcceptDoffPromptForTesting() {

0 commit comments

Comments
 (0)