Home | History | Annotate | Download | only in pip
      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_LEANBACK_ONLY;
     20 import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
     21 
     22 import android.content.pm.PackageManager;
     23 import android.content.res.Configuration;
     24 
     25 import com.android.systemui.SystemUI;
     26 import com.android.systemui.recents.misc.SystemServicesProxy;
     27 import com.android.systemui.statusbar.CommandQueue;
     28 
     29 import java.io.FileDescriptor;
     30 import java.io.PrintWriter;
     31 
     32 /**
     33  * Controls the picture-in-picture window.
     34  */
     35 public class PipUI extends SystemUI implements CommandQueue.Callbacks {
     36 
     37     private BasePipManager mPipManager;
     38 
     39     private boolean mSupportsPip;
     40 
     41     @Override
     42     public void start() {
     43         PackageManager pm = mContext.getPackageManager();
     44         mSupportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
     45         if (!mSupportsPip) {
     46             return;
     47         }
     48 
     49         // Ensure that we are the primary user's SystemUI.
     50         final int processUser = SystemServicesProxy.getInstance(mContext).getProcessUser();
     51         if (!SystemServicesProxy.getInstance(mContext).isSystemUser(processUser)) {
     52             throw new IllegalStateException("Non-primary Pip component not currently supported.");
     53         }
     54 
     55         mPipManager = pm.hasSystemFeature(FEATURE_LEANBACK_ONLY)
     56                 ? com.android.systemui.pip.tv.PipManager.getInstance()
     57                 : com.android.systemui.pip.phone.PipManager.getInstance();
     58         mPipManager.initialize(mContext);
     59 
     60         getComponent(CommandQueue.class).addCallbacks(this);
     61     }
     62 
     63     @Override
     64     public void showPictureInPictureMenu() {
     65         mPipManager.showPictureInPictureMenu();
     66     }
     67 
     68     @Override
     69     protected void onConfigurationChanged(Configuration newConfig) {
     70         super.onConfigurationChanged(newConfig);
     71         if (mPipManager == null) {
     72             return;
     73         }
     74 
     75         mPipManager.onConfigurationChanged(newConfig);
     76     }
     77 
     78     @Override
     79     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
     80         if (mPipManager == null) {
     81             return;
     82         }
     83 
     84         mPipManager.dump(pw);
     85     }
     86 }
     87