| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.debug; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.app.Notification; |
| 22 |
import android.app.PendingIntent; |
| 23 |
import android.content.Context; |
| 24 |
import android.content.Intent; |
| 25 |
import android.content.pm.PackageManager; |
| 26 |
import android.content.pm.ResolveInfo; |
| 27 |
import android.content.res.Resources; |
| 28 |
import android.os.UserHandle; |
| 29 |
import android.provider.Settings; |
| 30 |
|
| 31 |
import com.android.internal.notification.SystemNotificationChannels; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class AdbNotifications { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private static final String ADB_NOTIFICATION_CHANNEL_ID_TV = "usbdevicemanager.adb.tv"; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
@Nullable |
| 50 |
public static Notification createNotification(@NonNull Context context, |
| 51 |
byte transportType) { |
| 52 |
Resources resources = context.getResources(); |
| 53 |
int titleId; |
| 54 |
int messageId; |
| 55 |
|
| 56 |
if (transportType == AdbTransportType.USB) { |
| 57 |
titleId = com.android.internal.R.string.adb_active_notification_title; |
| 58 |
messageId = com.android.internal.R.string.adb_active_notification_message; |
| 59 |
} else if (transportType == AdbTransportType.WIFI) { |
| 60 |
titleId = com.android.internal.R.string.adbwifi_active_notification_title; |
| 61 |
messageId = com.android.internal.R.string.adbwifi_active_notification_message; |
| 62 |
} else { |
| 63 |
throw new IllegalArgumentException( |
| 64 |
"createNotification called with unknown transport type=" + transportType); |
| 65 |
} |
| 66 |
|
| 67 |
CharSequence title = resources.getText(titleId); |
| 68 |
CharSequence message = resources.getText(messageId); |
| 69 |
|
| 70 |
Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); |
| 71 |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 72 |
ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, |
| 73 |
PackageManager.MATCH_SYSTEM_ONLY); |
| 74 |
|
| 75 |
PendingIntent pIntent = null; |
| 76 |
if (resolveInfo != null) { |
| 77 |
intent.setPackage(resolveInfo.activityInfo.packageName); |
| 78 |
pIntent = PendingIntent.getActivityAsUser(context, 0, intent, |
| 79 |
PendingIntent.FLAG_IMMUTABLE, null, UserHandle.CURRENT); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
return new Notification.Builder(context, SystemNotificationChannels.DEVELOPER_IMPORTANT) |
| 84 |
.setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 85 |
.setWhen(0) |
| 86 |
.setOngoing(true) |
| 87 |
.setTicker(title) |
| 88 |
.setDefaults(0) |
| 89 |
.setColor(context.getColor( |
| 90 |
com.android.internal.R.color.system_notification_accent_color)) |
| 91 |
.setContentTitle(title) |
| 92 |
.setContentText(message) |
| 93 |
.setContentIntent(pIntent) |
| 94 |
.setVisibility(Notification.VISIBILITY_PUBLIC) |
| 95 |
.extend(new Notification.TvExtender() |
| 96 |
.setChannelId(ADB_NOTIFICATION_CHANNEL_ID_TV)) |
| 97 |
.build(); |
| 98 |
} |
| 99 |
} |