diff options
3 files changed, 42 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java index 6c5312d57b2a..a692d0bdd1c7 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java @@ -708,7 +708,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio mActiveMediaSessionListener, null); updateMediaController(mMediaSessionManager.getActiveSessions(null)); for (int i = mListeners.size() - 1; i >= 0; i--) { - mListeners.get(i).onPipEntered(); + mListeners.get(i).onPipEntered(packageName); } updatePipVisibility(true); } @@ -758,7 +758,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio * because there's no guarantee for the PIP manager be return relavent information * correctly. (e.g. {@link isPipShown}). */ - void onPipEntered(); + void onPipEntered(String packageName); /** Invoked when a PIPed activity is closed. */ void onPipActivityClosed(); /** Invoked when the PIP menu gets shown. */ diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipMenuActivity.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipMenuActivity.java index c7e77ccfa488..158be45e0adb 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipMenuActivity.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipMenuActivity.java @@ -137,8 +137,8 @@ public class PipMenuActivity extends Activity implements PipManager.Listener { } @Override - public void onPipEntered() { - if (DEBUG) Log.d(TAG, "onPipEntered()"); + public void onPipEntered(String packageName) { + if (DEBUG) Log.d(TAG, "onPipEntered(), packageName=" + packageName); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipNotification.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipNotification.java index b01c2f4eb5fb..30ec29683942 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipNotification.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipNotification.java @@ -23,6 +23,8 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; import android.content.res.Resources; import android.graphics.Bitmap; @@ -50,6 +52,8 @@ public class PipNotification { private static final String ACTION_MENU = "PipNotification.menu"; private static final String ACTION_CLOSE = "PipNotification.close"; + private final PackageManager mPackageManager; + private final PipManager mPipManager; private final NotificationManager mNotificationManager; @@ -59,13 +63,16 @@ public class PipNotification { private String mDefaultTitle; private int mDefaultIconResId; + /** Package name for the application that owns PiP window. */ + private String mPackageName; private boolean mNotified; - private String mTitle; + private String mMediaTitle; private Bitmap mArt; private PipManager.Listener mPipListener = new PipManager.Listener() { @Override - public void onPipEntered() { + public void onPipEntered(String packageName) { + mPackageName = packageName; updateMediaControllerMetadata(); notifyPipNotification(); } @@ -73,6 +80,7 @@ public class PipNotification { @Override public void onPipActivityClosed() { dismissPipNotification(); + mPackageName = null; } @Override @@ -88,6 +96,7 @@ public class PipNotification { @Override public void onMoveToFullscreen() { dismissPipNotification(); + mPackageName = null; } @Override @@ -146,6 +155,8 @@ public class PipNotification { public PipNotification(Context context, BroadcastDispatcher broadcastDispatcher, PipManager pipManager) { + mPackageManager = context.getPackageManager(); + mNotificationManager = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE); @@ -188,7 +199,7 @@ public class PipNotification { .setShowWhen(true) .setWhen(System.currentTimeMillis()) .setSmallIcon(mDefaultIconResId) - .setContentTitle(!TextUtils.isEmpty(mTitle) ? mTitle : mDefaultTitle); + .setContentTitle(getNotificationTitle()); if (mArt != null) { mNotificationBuilder.setStyle(new Notification.BigPictureStyle() .bigPicture(mArt)); @@ -220,14 +231,36 @@ public class PipNotification { } } } - if (!TextUtils.equals(title, mTitle) || art != mArt) { - mTitle = title; + if (!TextUtils.equals(title, mMediaTitle) || art != mArt) { + mMediaTitle = title; mArt = art; return true; } return false; } + private String getNotificationTitle() { + if (!TextUtils.isEmpty(mMediaTitle)) { + return mMediaTitle; + } + + final String applicationTitle = getApplicationLabel(mPackageName); + if (!TextUtils.isEmpty(applicationTitle)) { + return applicationTitle; + } + + return mDefaultTitle; + } + + private String getApplicationLabel(String packageName) { + try { + final ApplicationInfo appInfo = mPackageManager.getApplicationInfo(packageName, 0); + return mPackageManager.getApplicationLabel(appInfo).toString(); + } catch (PackageManager.NameNotFoundException e) { + return null; + } + } + private static PendingIntent createPendingIntent(Context context, String action) { return PendingIntent.getBroadcast(context, 0, new Intent(action), PendingIntent.FLAG_CANCEL_CURRENT); |