diff options
| author | 2018-02-13 17:46:56 +0000 | |
|---|---|---|
| committer | 2018-02-13 17:46:56 +0000 | |
| commit | 2f1f06cbf26dfd5f2abb16ab37871b7acccdb90f (patch) | |
| tree | bce39b29842525e203d72c5418769a71b64f3c2a | |
| parent | c110d25913d692c8c0b2e03ee9c347c2cfd16821 (diff) | |
| parent | 8b361d918ecf9f1d9c5ca3f22549c9058dc2fe37 (diff) | |
Merge "Adding utility method to check the current home app"
| -rw-r--r-- | packages/SystemUI/shared/src/com/android/systemui/shared/system/PackageManagerWrapper.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PackageManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PackageManagerWrapper.java index d5e6e6efb3cf..6fa7db3f2cdb 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PackageManagerWrapper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PackageManagerWrapper.java @@ -21,8 +21,12 @@ import android.content.ComponentName; import android.content.pm.ActivityInfo; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.os.RemoteException; +import java.util.ArrayList; +import java.util.List; + public class PackageManagerWrapper { private static final String TAG = "PackageManagerWrapper"; @@ -47,4 +51,42 @@ public class PackageManagerWrapper { return null; } } + + /** + * @return true if the packageName belongs to the current preferred home app on the device. + * + * If will also return false if there are multiple home apps and the user has not picked any + * preferred home, in which case the user would see a disambiguation screen on going to home. + */ + public boolean isDefaultHomeActivity(String packageName) { + List<ResolveInfo> allHomeCandidates = new ArrayList<>(); + ComponentName home; + try { + home = mIPackageManager.getHomeActivities(allHomeCandidates); + } catch (RemoteException e) { + e.printStackTrace(); + return false; + } + + if (home != null && packageName.equals(home.getPackageName())) { + return true; + } + + // Find the launcher with the highest priority and return that component if there are no + // other home activity with the same priority. + int lastPriority = Integer.MIN_VALUE; + ComponentName lastComponent = null; + final int size = allHomeCandidates.size(); + for (int i = 0; i < size; i++) { + final ResolveInfo ri = allHomeCandidates.get(i); + if (ri.priority > lastPriority) { + lastComponent = ri.activityInfo.getComponentName(); + lastPriority = ri.priority; + } else if (ri.priority == lastPriority) { + // Two components found with same priority. + lastComponent = null; + } + } + return lastComponent != null && packageName.equals(lastComponent.getPackageName()); + } } |