| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.omaha; |
| 6 |
| 7 import android.app.Service; |
| 8 import android.content.Context; |
| 9 import android.content.pm.ApplicationInfo; |
| 10 |
| 11 import org.chromium.base.ApiCompatibilityUtils; |
| 12 import org.chromium.base.ApplicationStatus; |
| 13 import org.chromium.chrome.browser.ChromeApplication; |
| 14 |
| 15 import java.util.UUID; |
| 16 |
| 17 /** Delegates calls out from the OmahaClient. */ |
| 18 public class OmahaDelegateImpl extends OmahaDelegate { |
| 19 private final ExponentialBackoffScheduler mScheduler; |
| 20 |
| 21 OmahaDelegateImpl(Context context) { |
| 22 super(context); |
| 23 mScheduler = new ExponentialBackoffScheduler(OmahaBase.PREF_PACKAGE, con
text, |
| 24 OmahaClient.MS_POST_BASE_DELAY, OmahaClient.MS_POST_MAX_DELAY); |
| 25 } |
| 26 |
| 27 @Override |
| 28 boolean isInSystemImage() { |
| 29 return (getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_S
YSTEM) != 0; |
| 30 } |
| 31 |
| 32 @Override |
| 33 ExponentialBackoffScheduler getScheduler() { |
| 34 return mScheduler; |
| 35 } |
| 36 |
| 37 @Override |
| 38 String generateUUID() { |
| 39 return UUID.randomUUID().toString(); |
| 40 } |
| 41 |
| 42 @Override |
| 43 boolean isChromeBeingUsed() { |
| 44 boolean isChromeVisible = ApplicationStatus.hasVisibleActivities(); |
| 45 boolean isScreenOn = ApiCompatibilityUtils.isInteractive(getContext()); |
| 46 return isChromeVisible && isScreenOn; |
| 47 } |
| 48 |
| 49 @Override |
| 50 void scheduleService(Service service, long nextTimestamp) { |
| 51 if (service instanceof OmahaClient) { |
| 52 getScheduler().createAlarm(OmahaClient.createOmahaIntent(getContext(
)), nextTimestamp); |
| 53 } else { |
| 54 // TODO(dfalcantara): Do something here with a JobService. |
| 55 } |
| 56 } |
| 57 |
| 58 @Override |
| 59 protected RequestGenerator createRequestGenerator(Context context) { |
| 60 return ((ChromeApplication) context.getApplicationContext()).createOmaha
RequestGenerator(); |
| 61 } |
| 62 } |
| OLD | NEW |