• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.server.pm.parsing;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.pm.parsing.component.ParsedComponent;
22 import android.util.Pair;
23 
24 import com.android.server.pm.PackageSetting;
25 
26 /**
27  * For exposing internal fields to the rest of the server, enforcing that any overridden state from
28  * a {@link com.android.server.pm.PackageSetting} is applied.
29  *
30  * TODO(chiuwinson): The fields on ParsedComponent are not actually hidden. Will need to find a
31  *   way to enforce the mechanism now that they exist in core instead of server. Can't rely on
32  *   package-private.
33  *
34  * @hide
35  */
36 public class ParsedComponentStateUtils {
37 
38     @NonNull
getNonLocalizedLabelAndIcon(ParsedComponent component, @Nullable PackageSetting pkgSetting, int userId)39     public static Pair<CharSequence, Integer> getNonLocalizedLabelAndIcon(ParsedComponent component,
40             @Nullable PackageSetting pkgSetting, int userId) {
41         CharSequence label = component.getNonLocalizedLabel();
42         int icon = component.getIcon();
43 
44         Pair<String, Integer> overrideLabelIcon = pkgSetting == null ? null :
45                 pkgSetting.readUserState(userId)
46                         .getOverrideLabelIconForComponent(component.getComponentName());
47         if (overrideLabelIcon != null) {
48             if (overrideLabelIcon.first != null) {
49                 label = overrideLabelIcon.first;
50             }
51             if (overrideLabelIcon.second != null) {
52                 icon = overrideLabelIcon.second;
53             }
54         }
55 
56         return Pair.create(label, icon);
57     }
58 }
59