blob: 377bfd1170a6d54223509bcd70f51abb1deb0aaf [file] [log] [blame]
Adrian Roos0da67d662017-04-17 14:50:22 -07001/*
2 * Copyright (C) 2017 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
17package com.android.server.am;
18
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090019import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
20
Adrian Roos0da67d662017-04-17 14:50:22 -070021import android.content.Context;
22import android.os.Handler;
Brett Chabota26eda92018-07-23 13:08:30 -070023
Brett Chabota26eda92018-07-23 13:08:30 -070024import androidx.test.annotation.UiThreadTest;
Dan Shiebfde332018-10-19 14:25:36 -070025import androidx.test.filters.FlakyTest;
Brett Chabota26eda92018-07-23 13:08:30 -070026import androidx.test.filters.SmallTest;
Adrian Roos0da67d662017-04-17 14:50:22 -070027
Svet Ganov8455ba22019-01-02 13:05:56 -080028import com.android.server.appop.AppOpsService;
Charles Chen40a9d562019-01-14 21:48:29 +080029import com.android.server.wm.ActivityTaskManagerService;
Adrian Roos0da67d662017-04-17 14:50:22 -070030
31import org.junit.Before;
Garfield Tanb30145c2019-08-02 17:31:30 -070032import org.junit.Rule;
Adrian Roos0da67d662017-04-17 14:50:22 -070033import org.junit.Test;
Adrian Roos0da67d662017-04-17 14:50:22 -070034
35import java.io.File;
36
37/**
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090038 * Build/Install/Run:
Tadashi G. Takaokad3eb6452018-11-03 18:21:40 -070039 * atest FrameworksServicesTests:AppErrorDialogTest
Adrian Roos0da67d662017-04-17 14:50:22 -070040 */
Adrian Roos0da67d662017-04-17 14:50:22 -070041@SmallTest
Dan Shiebfde332018-10-19 14:25:36 -070042@FlakyTest(bugId = 113616538)
Adrian Roos0da67d662017-04-17 14:50:22 -070043public class AppErrorDialogTest {
44
Garfield Tanb30145c2019-08-02 17:31:30 -070045 @Rule
46 public ServiceThreadRule mServiceThreadRule = new ServiceThreadRule();
47
Adrian Roos0da67d662017-04-17 14:50:22 -070048 private Context mContext;
49 private ActivityManagerService mService;
50
51 @Before
52 public void setUp() throws Exception {
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090053 mContext = getInstrumentation().getTargetContext();
Sudheer Shanka5269e502019-08-07 16:15:23 -070054 mService = new ActivityManagerService(new ActivityManagerService.Injector(mContext) {
Adrian Roos0da67d662017-04-17 14:50:22 -070055 @Override
56 public AppOpsService getAppOpsService(File file, Handler handler) {
57 return null;
58 }
59
60 @Override
61 public Handler getUiHandler(ActivityManagerService service) {
Garfield Tanb30145c2019-08-02 17:31:30 -070062 return mServiceThreadRule.getThread().getThreadHandler();
Adrian Roos0da67d662017-04-17 14:50:22 -070063 }
64
65 @Override
66 public boolean isNetworkRestrictedForUid(int uid) {
67 return false;
68 }
Garfield Tanb30145c2019-08-02 17:31:30 -070069 }, mServiceThreadRule.getThread());
Charles Chen40a9d562019-01-14 21:48:29 +080070 mService.mActivityTaskManager = new ActivityTaskManagerService(mContext);
71 mService.mActivityTaskManager.initialize(null, null, mContext.getMainLooper());
Adrian Roos0da67d662017-04-17 14:50:22 -070072 }
73
74 @Test
75 @UiThreadTest
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090076 public void testCreateWorks() {
Adrian Roos0da67d662017-04-17 14:50:22 -070077 AppErrorDialog.Data data = new AppErrorDialog.Data();
Charles Chen40a9d562019-01-14 21:48:29 +080078 data.proc = new ProcessRecord(mService, mContext.getApplicationInfo(), "name", 12345);
Adrian Roos0da67d662017-04-17 14:50:22 -070079 data.result = new AppErrorResult();
80
81 AppErrorDialog dialog = new AppErrorDialog(mContext, mService, data);
82
83 dialog.create();
84 }
85}