• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 package com.android.car.ui.paintbooth;
17 
18 import android.app.Application;
19 import android.content.Context;
20 
21 import com.android.car.ui.sharedlibrarysupport.SharedLibraryConfigProvider;
22 import com.android.car.ui.sharedlibrarysupport.SharedLibrarySpecifier;
23 
24 import java.util.Collections;
25 import java.util.Set;
26 import java.util.stream.Collectors;
27 
28 /**
29  * A {@link Application} subclass that implements {@link SharedLibraryConfigProvider},
30  * allowing PaintBooth to disable the shared library.
31  */
32 @SuppressWarnings("AndroidJdkLibsChecker")
33 public class PaintBoothApplication extends Application implements SharedLibraryConfigProvider {
34     public static final String SHARED_PREFERENCES_FILE = "paintbooth_shared_prefs";
35     public static final String SHARED_PREFERENCES_SHARED_LIB_DENYLIST =
36             "paintbooth_shared_lib_deny";
37 
38     @Override
getSharedLibraryDenyList()39     public Set<SharedLibrarySpecifier> getSharedLibraryDenyList() {
40         return getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE)
41                 .getStringSet(SHARED_PREFERENCES_SHARED_LIB_DENYLIST, Collections.emptySet())
42                 .stream()
43                 .map(packageName -> SharedLibrarySpecifier.builder()
44                         .setPackageName(packageName)
45                         .build())
46                 .collect(Collectors.toSet());
47     }
48 }
49