1 /* 2 * Copyright (C) 2017 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.phone; 18 19 import static android.app.ActivityManager.StackId.PINNED_STACK_ID; 20 21 import android.app.ActivityManager.StackInfo; 22 import android.app.IActivityManager; 23 import android.content.ComponentName; 24 import android.content.Context; 25 import android.os.RemoteException; 26 import android.util.Log; 27 28 public class PipUtils { 29 30 private static final String TAG = "PipUtils"; 31 32 /** 33 * @return the ComponentName of the top non-SystemUI activity in the pinned stack, or null if 34 * none exists. 35 */ 36 public static ComponentName getTopPinnedActivity(Context context, 37 IActivityManager activityManager) { 38 try { 39 final String sysUiPackageName = context.getPackageName(); 40 final StackInfo pinnedStackInfo = activityManager.getStackInfo(PINNED_STACK_ID); 41 if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null && 42 pinnedStackInfo.taskIds.length > 0) { 43 for (int i = pinnedStackInfo.taskNames.length - 1; i >= 0; i--) { 44 ComponentName cn = ComponentName.unflattenFromString( 45 pinnedStackInfo.taskNames[i]); 46 if (cn != null && !cn.getPackageName().equals(sysUiPackageName)) { 47 return cn; 48 } 49 } 50 } 51 } catch (RemoteException e) { 52 Log.w(TAG, "Unable to get pinned stack."); 53 } 54 return null; 55 } 56 } 57