1 /* 2 * Copyright (C) 2018 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.quickstep; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.pm.ApplicationInfo; 22 import android.content.pm.InstantAppInfo; 23 import android.content.pm.PackageManager; 24 import android.util.Log; 25 26 import com.android.launcher3.AppInfo; 27 import com.android.launcher3.util.InstantAppResolver; 28 29 import java.util.ArrayList; 30 import java.util.List; 31 32 /** 33 * Implementation of InstantAppResolver using platform APIs 34 */ 35 @SuppressWarnings("unused") 36 public class InstantAppResolverImpl extends InstantAppResolver { 37 38 private static final String TAG = "InstantAppResolverImpl"; 39 public static final String COMPONENT_CLASS_MARKER = "@instantapp"; 40 41 private final PackageManager mPM; 42 43 public InstantAppResolverImpl(Context context) 44 throws NoSuchMethodException, ClassNotFoundException { 45 mPM = context.getPackageManager(); 46 } 47 48 @Override 49 public boolean isInstantApp(ApplicationInfo info) { 50 return info.isInstantApp(); 51 } 52 53 @Override 54 public boolean isInstantApp(AppInfo info) { 55 ComponentName cn = info.getTargetComponent(); 56 return cn != null && cn.getClassName().equals(COMPONENT_CLASS_MARKER); 57 } 58 59 @Override 60 public List<ApplicationInfo> getInstantApps() { 61 try { 62 List<ApplicationInfo> result = new ArrayList<>(); 63 for (InstantAppInfo iai : mPM.getInstantApps()) { 64 ApplicationInfo info = iai.getApplicationInfo(); 65 if (info != null) { 66 result.add(info); 67 } 68 } 69 return result; 70 } catch (SecurityException se) { 71 Log.w(TAG, "getInstantApps failed. Launcher may not be the default home app.", se); 72 } catch (Exception e) { 73 Log.e(TAG, "Error calling API: getInstantApps", e); 74 } 75 return super.getInstantApps(); 76 } 77 } 78