| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.sync; | 5 package org.chromium.chrome.browser.sync; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.Fragment; | 8 import android.app.Fragment; |
| 9 import android.app.Notification; | 9 import android.app.Notification; |
| 10 import android.app.NotificationManager; | 10 import android.app.NotificationManager; |
| 11 import android.app.PendingIntent; | 11 import android.app.PendingIntent; |
| 12 import android.content.ComponentName; | 12 import android.content.ComponentName; |
| 13 import android.content.Context; | 13 import android.content.Context; |
| 14 import android.content.Intent; | 14 import android.content.Intent; |
| 15 import android.support.v4.app.NotificationCompat; | |
| 16 import android.util.Log; | 15 import android.util.Log; |
| 17 | 16 |
| 18 import org.chromium.base.ThreadUtils; | 17 import org.chromium.base.ThreadUtils; |
| 19 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
| 19 import org.chromium.chrome.browser.ChromeApplication; |
| 20 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder; |
| 20 import org.chromium.chrome.browser.notifications.NotificationConstants; | 21 import org.chromium.chrome.browser.notifications.NotificationConstants; |
| 21 import org.chromium.chrome.browser.notifications.NotificationManagerProxy; | 22 import org.chromium.chrome.browser.notifications.NotificationManagerProxy; |
| 22 import org.chromium.chrome.browser.notifications.NotificationManagerProxyImpl; | 23 import org.chromium.chrome.browser.notifications.NotificationManagerProxyImpl; |
| 23 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 24 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 24 import org.chromium.components.sync.AndroidSyncSettings; | 25 import org.chromium.components.sync.AndroidSyncSettings; |
| 25 | 26 |
| 26 /** | 27 /** |
| 27 * {@link SyncNotificationController} provides functionality for displaying Andr
oid notifications | 28 * {@link SyncNotificationController} provides functionality for displaying Andr
oid notifications |
| 28 * regarding the user sync status. | 29 * regarding the user sync status. |
| 29 */ | 30 */ |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 */ | 94 */ |
| 94 private void showSyncNotification(int message, Intent intent) { | 95 private void showSyncNotification(int message, Intent intent) { |
| 95 String title = mApplicationContext.getString(R.string.app_name); | 96 String title = mApplicationContext.getString(R.string.app_name); |
| 96 String text = mApplicationContext.getString(R.string.sign_in_sync) + ":
" | 97 String text = mApplicationContext.getString(R.string.sign_in_sync) + ":
" |
| 97 + mApplicationContext.getString(message); | 98 + mApplicationContext.getString(message); |
| 98 | 99 |
| 99 PendingIntent contentIntent = PendingIntent.getActivity(mApplicationCont
ext, 0, intent, 0); | 100 PendingIntent contentIntent = PendingIntent.getActivity(mApplicationCont
ext, 0, intent, 0); |
| 100 | 101 |
| 101 // There is no need to provide a group summary notification because the
NOTIFICATION_ID_SYNC | 102 // There is no need to provide a group summary notification because the
NOTIFICATION_ID_SYNC |
| 102 // notification id ensures there's only one sync notification at a time. | 103 // notification id ensures there's only one sync notification at a time. |
| 103 NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp
licationContext) | 104 ChromeNotificationBuilder builder = |
| 104 .setAutoCancel(true) | 105 ((ChromeApplication) mApplicationContext) |
| 105 .setContentIntent(contentIn
tent) | 106 .createChromeNotificationBuilder(true /* preferCompat */
, |
| 106 .setContentTitle(title) | 107 NotificationConstants.CATEGORY_ID_BROWSER, |
| 107 .setContentText(text) | 108 mApplicationContext.getString( |
| 108 .setSmallIcon(R.drawable.ic
_chrome) | 109 R.string.notification_category_browser), |
| 109 .setTicker(text) | 110 NotificationConstants.CATEGORY_GROUP_ID_GENERAL, |
| 110 .setLocalOnly(true) | 111 mApplicationContext.getString( |
| 111 .setGroup(NotificationConst
ants.GROUP_SYNC); | 112 R.string.notification_category_group_gen
eral)) |
| 113 .setAutoCancel(true) |
| 114 .setContentIntent(contentIntent) |
| 115 .setContentTitle(title) |
| 116 .setContentText(text) |
| 117 .setSmallIcon(R.drawable.ic_chrome) |
| 118 .setTicker(text) |
| 119 .setLocalOnly(true) |
| 120 .setGroup(NotificationConstants.GROUP_SYNC); |
| 112 | 121 |
| 113 Notification notification = | 122 Notification notification = builder.buildWithBigTextStyle(text); |
| 114 new NotificationCompat.BigTextStyle(builder).bigText(text).build
(); | |
| 115 | 123 |
| 116 mNotificationManager.notify(NotificationConstants.NOTIFICATION_ID_SYNC,
notification); | 124 mNotificationManager.notify(NotificationConstants.NOTIFICATION_ID_SYNC,
notification); |
| 117 } | 125 } |
| 118 | 126 |
| 119 private boolean shouldSyncAuthErrorBeShown() { | 127 private boolean shouldSyncAuthErrorBeShown() { |
| 120 switch (mProfileSyncService.getAuthError()) { | 128 switch (mProfileSyncService.getAuthError()) { |
| 121 case NONE: | 129 case NONE: |
| 122 case CONNECTION_FAILED: | 130 case CONNECTION_FAILED: |
| 123 case SERVICE_UNAVAILABLE: | 131 case SERVICE_UNAVAILABLE: |
| 124 case REQUEST_CANCELED: | 132 case REQUEST_CANCELED: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 Intent intent = new Intent(Intent.ACTION_MAIN); | 167 Intent intent = new Intent(Intent.ACTION_MAIN); |
| 160 intent.setComponent(new ComponentName(mApplicationContext, mPassphraseRe
questActivity)); | 168 intent.setComponent(new ComponentName(mApplicationContext, mPassphraseRe
questActivity)); |
| 161 intent.addCategory(Intent.CATEGORY_LAUNCHER); | 169 intent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 162 // This activity will become the start of a new task on this history sta
ck. | 170 // This activity will become the start of a new task on this history sta
ck. |
| 163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 171 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 164 // Clears the task stack above this activity if it already exists. | 172 // Clears the task stack above this activity if it already exists. |
| 165 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | 173 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 166 return intent; | 174 return intent; |
| 167 } | 175 } |
| 168 } | 176 } |
| OLD | NEW |