• 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 
17 package com.android.modules.updatablesharedlibs.apps.targetT;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.junit.Assert.assertThrows;
21 
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import junit.framework.Assert;
25 
26 import com.google.common.truth.Correspondence;
27 
28 import android.content.Context;
29 import android.content.pm.ApplicationInfo;
30 import android.content.pm.PackageManager;
31 import androidx.test.platform.app.InstrumentationRegistry;
32 import androidx.test.runner.AndroidJUnit4;
33 
34 /**
35  * Tests an app targeting T.
36  *
37  * <p>With the shared libraries included in this test, none of the shared libraries present in this
38  * test should be included for this app.
39  */
40 @RunWith(AndroidJUnit4.class)
41 public class UpdatableSharedLibraryTargetTTest {
42     private static final Correspondence<String, String> CONTAINS_SUBSTRING =
43             Correspondence.from(String::contains, "contains");
44     private static final Context sContext = InstrumentationRegistry.getInstrumentation()
45             .getContext();
46 
47     @Test
checkHasNoSharedLibrary()48     public void checkHasNoSharedLibrary() throws Exception {
49         String packageName = sContext.getPackageName();
50         ApplicationInfo appInfo = sContext.getPackageManager().getApplicationInfo(packageName,
51                 PackageManager.GET_SHARED_LIBRARY_FILES);
52 
53         assertThat(appInfo.sharedLibraryFiles)
54             .asList()
55             .comparingElementsUsing(CONTAINS_SUBSTRING)
56             .doesNotContain("com.android.modules.updatablesharedlibs");
57     }
58 
59     @Test
checkHasNoApiAccess()60     public void checkHasNoApiAccess() throws Exception {
61         assertThrows(
62             ClassNotFoundException.class,
63             () -> Class.forName("com.android.modules.updatablesharedlibs.libs.before.t.Api")
64         );
65     }
66 }
67