Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 19 | import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 20 | |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.os.Handler; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 23 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 24 | import androidx.test.annotation.UiThreadTest; |
Dan Shi | ebfde33 | 2018-10-19 14:25:36 -0700 | [diff] [blame] | 25 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 26 | import androidx.test.filters.SmallTest; |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 27 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 28 | import com.android.server.appop.AppOpsService; |
Charles Chen | 40a9d56 | 2019-01-14 21:48:29 +0800 | [diff] [blame] | 29 | import com.android.server.wm.ActivityTaskManagerService; |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 30 | |
| 31 | import org.junit.Before; |
Garfield Tan | b30145c | 2019-08-02 17:31:30 -0700 | [diff] [blame] | 32 | import org.junit.Rule; |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 33 | import org.junit.Test; |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 34 | |
| 35 | import java.io.File; |
| 36 | |
| 37 | /** |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 38 | * Build/Install/Run: |
Tadashi G. Takaoka | d3eb645 | 2018-11-03 18:21:40 -0700 | [diff] [blame] | 39 | * atest FrameworksServicesTests:AppErrorDialogTest |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 40 | */ |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 41 | @SmallTest |
Dan Shi | ebfde33 | 2018-10-19 14:25:36 -0700 | [diff] [blame] | 42 | @FlakyTest(bugId = 113616538) |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 43 | public class AppErrorDialogTest { |
| 44 | |
Garfield Tan | b30145c | 2019-08-02 17:31:30 -0700 | [diff] [blame] | 45 | @Rule |
| 46 | public ServiceThreadRule mServiceThreadRule = new ServiceThreadRule(); |
| 47 | |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 48 | private Context mContext; |
| 49 | private ActivityManagerService mService; |
| 50 | |
| 51 | @Before |
| 52 | public void setUp() throws Exception { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 53 | mContext = getInstrumentation().getTargetContext(); |
Sudheer Shanka | 5269e50 | 2019-08-07 16:15:23 -0700 | [diff] [blame] | 54 | mService = new ActivityManagerService(new ActivityManagerService.Injector(mContext) { |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 55 | @Override |
| 56 | public AppOpsService getAppOpsService(File file, Handler handler) { |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Handler getUiHandler(ActivityManagerService service) { |
Garfield Tan | b30145c | 2019-08-02 17:31:30 -0700 | [diff] [blame] | 62 | return mServiceThreadRule.getThread().getThreadHandler(); |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean isNetworkRestrictedForUid(int uid) { |
| 67 | return false; |
| 68 | } |
Garfield Tan | b30145c | 2019-08-02 17:31:30 -0700 | [diff] [blame] | 69 | }, mServiceThreadRule.getThread()); |
Charles Chen | 40a9d56 | 2019-01-14 21:48:29 +0800 | [diff] [blame] | 70 | mService.mActivityTaskManager = new ActivityTaskManagerService(mContext); |
| 71 | mService.mActivityTaskManager.initialize(null, null, mContext.getMainLooper()); |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Test |
| 75 | @UiThreadTest |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 76 | public void testCreateWorks() { |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 77 | AppErrorDialog.Data data = new AppErrorDialog.Data(); |
Charles Chen | 40a9d56 | 2019-01-14 21:48:29 +0800 | [diff] [blame] | 78 | data.proc = new ProcessRecord(mService, mContext.getApplicationInfo(), "name", 12345); |
Adrian Roos | 0da67d66 | 2017-04-17 14:50:22 -0700 | [diff] [blame] | 79 | data.result = new AppErrorResult(); |
| 80 | |
| 81 | AppErrorDialog dialog = new AppErrorDialog(mContext, mService, data); |
| 82 | |
| 83 | dialog.create(); |
| 84 | } |
| 85 | } |