Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dab4d01b authored by Aaron Kling's avatar Aaron Kling Committed by Michael Bestas
Browse files

ATV: Display battery notifications

This is for handheld gaming devices that have batteries and are
using Android TV.

Change-Id: I22592699214d40aac2a733203b05c076b2a1ae70
parent 938cb08d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -137,4 +137,7 @@
    <string name="screenrecord_skip_time_summary">Remove the 3 second wait</string>
    <string name="screenrecord_hevc_switch_label">HEVC encoding</string>
    <string name="screenrecord_hevc_switch_summary">Use the more efficient HEVC encoder</string>

    <!-- Channel name for Battery notifications -->
    <string name="battery_notification_channel_tv">Battery warning</string>
</resources>
+18 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.settingslib.fuelgauge.BatterySaverLogging.SaverManualE
import android.app.Dialog;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
@@ -34,6 +35,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Bundle;
@@ -96,6 +98,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    private static final String TAG = PowerUI.TAG + ".Notification";
    private static final boolean DEBUG = PowerUI.DEBUG;

    private static final String BATTERY_NOTIF_CHANNEL_ID_TV = "powernotifications.battery.tv";

    private static final String TAG_BATTERY = "low_battery";
    private static final String TAG_TEMPERATURE = "high_temp";
    private static final String TAG_AUTO_SAVER = "auto_saver";
@@ -210,6 +214,13 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
        mUserTracker = userTracker;
        mUseExtraSaverConfirmation =
                mContext.getResources().getBoolean(R.bool.config_extra_battery_saver_confirmation);

        if (isTv()) {
            // TV-specific notification channel
            mNoMan.createNotificationChannel(new NotificationChannel(BATTERY_NOTIF_CHANNEL_ID_TV,
                    mContext.getString(R.string.battery_notification_channel_tv),
                    NotificationManager.IMPORTANCE_HIGH));
        }
    }

    @Override
@@ -277,6 +288,10 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
        }
    }

    private boolean isTv() {
        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
    }

    private void showInvalidChargerNotification() {
        final Notification.Builder nb =
                new Notification.Builder(mContext, NotificationChannels.ALERTS)
@@ -316,7 +331,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
                        .setOnlyAlertOnce(true)
                        .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_WARNING))
                        .setStyle(new Notification.BigTextStyle().bigText(contentText))
                        .setVisibility(Notification.VISIBILITY_PUBLIC);
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .extend(new Notification.TvExtender()
                                .setChannelId(BATTERY_NOTIF_CHANNEL_ID_TV));
        if (hasBatterySettings()) {
            nb.setContentIntent(pendingBroadcast(ACTION_SHOW_BATTERY_SAVER_SETTINGS));
        }