blob: f6d9134c5e2b01207701b8f4e13330239e47b229 [file] [log] [blame]
Tony Mantlered03f452015-10-21 11:29:10 -07001/*
2 * Copyright (C) 2015 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
17package com.android.settingslib.applications;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.IntentFilter;
22import android.content.pm.PackageManager;
23import android.hardware.usb.IUsbManager;
24import android.os.RemoteException;
25import android.os.UserHandle;
26import android.util.Log;
27
28import com.android.settingslib.R;
29
30import java.util.ArrayList;
31import java.util.List;
32
33public class AppUtils {
34 private static final String TAG = "AppUtils";
35
36 public static CharSequence getLaunchByDefaultSummary(ApplicationsState.AppEntry appEntry,
37 IUsbManager usbManager, PackageManager pm, Context context) {
38 String packageName = appEntry.info.packageName;
39 boolean hasPreferred = hasPreferredActivities(pm, packageName)
40 || hasUsbDefaults(usbManager, packageName);
Jeff Sharkeye06b4d12016-01-06 14:51:50 -070041 int status = pm.getIntentVerificationStatusAsUser(packageName, UserHandle.myUserId());
Tony Mantlered03f452015-10-21 11:29:10 -070042 // consider a visible current link-handling state to be any explicitly designated behavior
43 boolean hasDomainURLsPreference =
44 status != PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
45 return context.getString(hasPreferred || hasDomainURLsPreference
46 ? R.string.launch_defaults_some
47 : R.string.launch_defaults_none);
48 }
49
50 public static boolean hasUsbDefaults(IUsbManager usbManager, String packageName) {
51 try {
52 if (usbManager != null) {
53 return usbManager.hasDefaults(packageName, UserHandle.myUserId());
54 }
55 } catch (RemoteException e) {
56 Log.e(TAG, "mUsbManager.hasDefaults", e);
57 }
58 return false;
59 }
60
61 public static boolean hasPreferredActivities(PackageManager pm, String packageName) {
62 // Get list of preferred activities
63 List<ComponentName> prefActList = new ArrayList<>();
64 // Intent list cannot be null. so pass empty list
65 List<IntentFilter> intentList = new ArrayList<>();
66 pm.getPreferredActivities(intentList, prefActList, packageName);
67 Log.d(TAG, "Have " + prefActList.size() + " number of activities in preferred list");
68 return prefActList.size() > 0;
69 }
70
71}