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.car.carlauncher; 18 19 import android.annotation.Nullable; 20 import android.content.Intent; 21 import android.graphics.drawable.Drawable; 22 23 /** 24 * Meta data of an app including the display name, the full package name, the icon drawable, and an 25 * intent to either open the app or the media center (for media services). 26 */ 27 28 final class AppMetaData { 29 // The display name of the app 30 @Nullable 31 private final String mDisplayName; 32 // The package name of the app 33 private final String mPackageName; 34 private final Drawable mIcon; 35 private final boolean mIsDistractionOptimized; 36 private final Intent mMainLaunchIntent; 37 private final Intent mAlternateLaunchIntent; 38 39 /** 40 * AppMetaData 41 * @param displayName the name to display in the launcher 42 * @param packageName the application's package 43 * @param icon the application's icon 44 * @param isDistractionOptimized whether mainLaunchIntent is safe for driving 45 * @param mainLaunchIntent what to open by default (goes to the media center for media apps) 46 * @param alternateLaunchIntent temporary allowance for media apps that still need to show UI 47 * beyond sign in and settings 48 */ AppMetaData( CharSequence displayName, String packageName, Drawable icon, boolean isDistractionOptimized, Intent mainLaunchIntent, @Nullable Intent alternateLaunchIntent)49 AppMetaData( 50 CharSequence displayName, 51 String packageName, 52 Drawable icon, 53 boolean isDistractionOptimized, 54 Intent mainLaunchIntent, 55 @Nullable Intent alternateLaunchIntent) { 56 mDisplayName = displayName == null ? "" : displayName.toString(); 57 mPackageName = packageName == null ? "" : packageName; 58 mIcon = icon; 59 mIsDistractionOptimized = isDistractionOptimized; 60 mMainLaunchIntent = mainLaunchIntent; 61 mAlternateLaunchIntent = alternateLaunchIntent; 62 } 63 getDisplayName()64 public String getDisplayName() { 65 return mDisplayName; 66 } 67 getPackageName()68 public String getPackageName() { 69 return mPackageName; 70 } 71 getMainLaunchIntent()72 Intent getMainLaunchIntent() { 73 return mMainLaunchIntent; 74 } 75 getAlternateLaunchIntent()76 Intent getAlternateLaunchIntent() { 77 return mAlternateLaunchIntent; 78 } 79 getIcon()80 public Drawable getIcon() { 81 return mIcon; 82 } 83 getIsDistractionOptimized()84 boolean getIsDistractionOptimized() { 85 return mIsDistractionOptimized; 86 } 87 88 /** 89 * The equality of two AppMetaData is determined by whether the package names are the same. 90 * 91 * @param o Object that this AppMetaData object is compared against 92 * @return {@code true} when two AppMetaData have the same package name 93 */ 94 @Override equals(Object o)95 public boolean equals(Object o) { 96 if (!(o instanceof AppMetaData)) { 97 return false; 98 } else { 99 return ((AppMetaData) o).getPackageName().equals(mPackageName); 100 } 101 } 102 103 @Override hashCode()104 public int hashCode() { 105 return mPackageName.hashCode(); 106 } 107 } 108