1 /*
2  * Copyright (C) 2016 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.managedprovisioning.e2eui;
17 
18 import android.content.Intent;
19 import android.util.Log;
20 import com.android.managedprovisioning.TestInstrumentationRunner;
21 import com.android.managedprovisioning.preprovisioning.PreProvisioningActivity;
22 
23 public class TestPreProvisioningActivity extends PreProvisioningActivity {
24     private static final String TAG = "TestPreProvisioningActivity";
25 
26     private final ProvisioningResultListener mlistener;
27 
TestPreProvisioningActivity(ProvisioningResultListener listener)28     public TestPreProvisioningActivity(ProvisioningResultListener listener) {
29         mlistener = listener;
30     }
31 
32     /** ManagedProfileTest is running in ManagedProvisioning process, while the AdminReceiver is in
33      * test package process. Mock the calling package to pretend we provision it from test package,
34      * not from ManagedProvisioning.
35      */
36     @Override
getCallingPackage()37     public String getCallingPackage() {
38         return TestInstrumentationRunner.TEST_PACKAGE_NAME;
39     }
40 
41     @Override
onActivityResult(int requestCode, int resultCode, Intent data)42     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
43         Log.i(TAG, "onActivityResult " + requestCode);
44         // Return the result code to the test and verify it.
45         if (requestCode == PROVISIONING_REQUEST_CODE) {
46             mlistener.setPreprovisioningActivityResult(resultCode == RESULT_OK);
47         }
48         super.onActivityResult(requestCode, resultCode, data);
49     }
50 }
51