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 android.appsearch.app.a; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.testng.Assert.expectThrows; 22 23 import android.app.appsearch.AppSearchManager; 24 import android.content.Context; 25 26 import androidx.test.ext.junit.runners.AndroidJUnit4; 27 import androidx.test.platform.app.InstrumentationRegistry; 28 29 import com.android.server.appsearch.testing.AppSearchSessionShimImpl; 30 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 import java.util.concurrent.ExecutionException; 35 36 @RunWith(AndroidJUnit4.class) 37 public class AppSearchInstantAppTest { 38 39 private static final String DB_NAME = ""; 40 41 @Test testInstantAppDoesntHaveAccess()42 public void testInstantAppDoesntHaveAccess() { 43 Context context = InstrumentationRegistry.getInstrumentation().getContext(); 44 assertThat(context.getPackageManager().isInstantApp()).isTrue(); 45 46 int userId = context.getUserId(); 47 ExecutionException exception = expectThrows(ExecutionException.class, () -> 48 AppSearchSessionShimImpl.createSearchSession( 49 new AppSearchManager.SearchContext.Builder(DB_NAME).build(), 50 userId).get()); 51 assertThat(exception.getMessage()).contains( 52 "AppSearchResult is a failure: [FAILURE(8)]: SecurityException: Caller not allowed " 53 + "to create AppSearch session"); 54 } 55 } 56