Commit b8b99832 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Update Notification Service]: Launch Chrome flow.

- Implemented the flow when user clicked notification and launch Chrome
Activity from background.

Bug: 1013685
Change-Id: Ib9e96da59358fcc9f4016cf8a5ebcfe3ec043dc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994240
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Auto-Submit: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732990}
parent 93823ec8
......@@ -16,6 +16,8 @@ import android.content.SharedPreferences;
import androidx.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
......@@ -44,6 +46,7 @@ public class UpdateNotificationServiceBridge implements UpdateNotificationContro
private ChromeActivity mActivity;
private @Nullable UpdateStatusProvider.UpdateStatus mUpdateStatus;
private static final String TAG = "cr_UpdateNotif";
/**
* @param activity A {@link ChromeActivity} instance the notification will be shown in.
......@@ -147,4 +150,15 @@ public class UpdateNotificationServiceBridge implements UpdateNotificationContro
editor.putInt(PREF_UPDATE_NOTIFICATION_USER_DISMISS_COUNT_KEY, count);
editor.apply();
}
@CalledByNative
private static void launchChromeActivity() {
// TODO(hesen): Record metrics.
try {
// TODO(hesen): Handle the INLINE_UPDATE_AVAILABLE state.
UpdateUtils.onUpdateAvailable(ContextUtils.getApplicationContext(), UPDATE_AVAILABLE);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Failed to start activity in background.", e);
}
}
}
......@@ -44,7 +44,7 @@ void UpdateNotificationClient::OnUserAction(const UserActionData& action_data) {
switch (action_data.action_type) {
case notifications::UserActionType::kClick:
NOTIMPLEMENTED();
update_notification_service->OnUserClick();
break;
case notifications::UserActionType::kButtonClick:
NOTIMPLEMENTED();
......
......@@ -27,6 +27,9 @@ class UpdateNotificationService : public KeyedService {
// Called when the notification is dismissed by user.
virtual void OnUserDismiss() = 0;
// Called when the notification is clicked by user.
virtual void OnUserClick() = 0;
~UpdateNotificationService() override = default;
protected:
......
......@@ -80,4 +80,8 @@ int GetUserDismissCount() {
return Java_UpdateNotificationServiceBridge_getUserDismissCount(env);
}
void LaunchChromeActivity() {
JNIEnv* env = base::android::AttachCurrentThread();
Java_UpdateNotificationServiceBridge_launchChromeActivity(env);
}
} // namespace updates
......@@ -32,6 +32,9 @@ void UpdateUserDismissCount(int count);
// Returns persisted count from Android SharedPreferences.
int GetUserDismissCount();
// Launches Chrome activity after user clicked the notification.
void LaunchChromeActivity();
} // namespace updates
#endif // CHROME_BROWSER_UPDATES_UPDATE_NOTIFICATION_SERVICE_BRIDGE_H_
......@@ -124,4 +124,8 @@ void UpdateNotificationServiceImpl::ApplyLinearThrottle() {
updates::UpdateThrottleInterval(scale * interval + offset);
}
void UpdateNotificationServiceImpl::OnUserClick() {
updates::LaunchChromeActivity();
}
} // namespace updates
......@@ -31,10 +31,9 @@ class UpdateNotificationServiceImpl : public UpdateNotificationService {
private:
// UpdateNotificationService implementation.
void Schedule(UpdateNotificationInfo data) override;
bool IsReadyToDisplay() const override;
void OnUserDismiss() override;
void OnUserClick() override;
// Called after querying the |ClientOverview| struct from scheduler system
// completed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment