• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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.apps.common;
18 
19 
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.os.SystemProperties;
23 
24 import androidx.annotation.NonNull;
25 
26 /** Singleton class regrouping common library feature flags. */
27 public class CommonFlags {
28 
29     private static final String FLAG_IMPROPER_IMAGE_REFS_KEY =
30             "com.android.car.apps.common.FlagNonLocalImages";
31 
32     @SuppressWarnings("StaticFieldLeak") // We store the application context, not an activity.
33     private static CommonFlags sInstance;
34 
35     /** Returns the singleton. */
getInstance(Context context)36     public static CommonFlags getInstance(Context context) {
37         if (sInstance == null) {
38             sInstance = new CommonFlags(context);
39         }
40         return sInstance;
41     }
42 
43     private final Context mApplicationContext;
44     private Boolean mFlagImproperImageRefs;
45 
CommonFlags(@onNull Context context)46     private CommonFlags(@NonNull Context context) {
47         mApplicationContext = context.getApplicationContext();
48     }
49 
50     /**
51      * Returns whether improper image references should be flagged (typically tinting the images
52      * in red with {@link R.color.improper_image_refs_tint_color}. This special mode is intended for
53      * third party app developers so they can notice quickly that they are sending improper image
54      * references. Such references include :
55      * <li>remote image instead of a local content uri</li>
56      * <li>bitmap sent over the binder instead of a local content uri</li>
57      * <li>bitmap icon instead of a vector drawable</li>
58      * <p/>
59      *
60      * To activate, either overlay R.bool.flag_improper_image_references to true, or use adb:
61      * <code>
62      *     adb root
63      *     adb shell setprop com.android.car.apps.common.FlagNonLocalImages 1
64      *     adb shell am force-stop APP_PACKAGE # eg: APP_PACKAGE= com.android.car.media
65      * </code>
66      */
shouldFlagImproperImageRefs()67     public boolean shouldFlagImproperImageRefs() {
68         if (mFlagImproperImageRefs == null) {
69             Resources res = mApplicationContext.getResources();
70             mFlagImproperImageRefs = res.getBoolean(R.bool.flag_improper_image_references)
71                     || "1".equals(SystemProperties.get(FLAG_IMPROPER_IMAGE_REFS_KEY, "0"));
72         }
73         return mFlagImproperImageRefs;
74     }
75 }
76