1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.pip; 18 19 import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; 20 21 import android.content.Context; 22 import android.content.pm.PackageManager; 23 import android.content.res.Configuration; 24 import android.os.UserHandle; 25 import android.os.UserManager; 26 27 import com.android.systemui.SystemUI; 28 import com.android.systemui.shared.recents.IPinnedStackAnimationListener; 29 import com.android.systemui.statusbar.CommandQueue; 30 31 import java.io.FileDescriptor; 32 import java.io.PrintWriter; 33 34 import javax.inject.Inject; 35 import javax.inject.Singleton; 36 37 /** 38 * Controls the picture-in-picture window. 39 */ 40 @Singleton 41 public class PipUI extends SystemUI implements CommandQueue.Callbacks { 42 43 private final CommandQueue mCommandQueue; 44 private BasePipManager mPipManager; 45 46 @Inject PipUI(Context context, CommandQueue commandQueue, BasePipManager pipManager)47 public PipUI(Context context, CommandQueue commandQueue, 48 BasePipManager pipManager) { 49 super(context); 50 mCommandQueue = commandQueue; 51 mPipManager = pipManager; 52 } 53 54 @Override start()55 public void start() { 56 PackageManager pm = mContext.getPackageManager(); 57 boolean supportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); 58 if (!supportsPip) { 59 return; 60 } 61 62 // Ensure that we are the primary user's SystemUI. 63 final int processUser = UserManager.get(mContext).getUserHandle(); 64 if (processUser != UserHandle.USER_SYSTEM) { 65 throw new IllegalStateException("Non-primary Pip component not currently supported."); 66 } 67 68 mCommandQueue.addCallback(this); 69 } 70 71 @Override showPictureInPictureMenu()72 public void showPictureInPictureMenu() { 73 mPipManager.showPictureInPictureMenu(); 74 } 75 expandPip()76 public void expandPip() { 77 mPipManager.expandPip(); 78 } 79 hidePipMenu(Runnable onStartCallback, Runnable onEndCallback)80 public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) { 81 mPipManager.hidePipMenu(onStartCallback, onEndCallback); 82 } 83 84 @Override onConfigurationChanged(Configuration newConfig)85 protected void onConfigurationChanged(Configuration newConfig) { 86 super.onConfigurationChanged(newConfig); 87 if (mPipManager == null) { 88 return; 89 } 90 91 mPipManager.onConfigurationChanged(newConfig); 92 } 93 setShelfHeight(boolean visible, int height)94 public void setShelfHeight(boolean visible, int height) { 95 if (mPipManager == null) { 96 return; 97 } 98 99 mPipManager.setShelfHeight(visible, height); 100 } 101 setPinnedStackAnimationType(int animationType)102 public void setPinnedStackAnimationType(int animationType) { 103 if (mPipManager != null) { 104 mPipManager.setPinnedStackAnimationType(animationType); 105 } 106 } 107 setPinnedStackAnimationListener(IPinnedStackAnimationListener listener)108 public void setPinnedStackAnimationListener(IPinnedStackAnimationListener listener) { 109 if (mPipManager != null) { 110 mPipManager.setPinnedStackAnimationListener(listener); 111 } 112 } 113 114 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)115 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 116 if (mPipManager == null) { 117 return; 118 } 119 120 mPipManager.dump(pw); 121 } 122 } 123