1 /*
2  * Copyright (C) 2018 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.cts.verifier.managedprovisioning;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.Bundle;
23 import android.util.Log;
24 
25 import androidx.core.content.FileProvider;
26 
27 import java.io.File;
28 
29 /** Cts Verifier helper activity that runs only in the primary profile.*/
30 public class ByodPrimaryHelperActivity extends Activity {
31 
32     private static final String TAG = "ByodPrimaryHlprActivity";
33     private static final int REQUEST_INSTALL_PACKAGE = 1;
34 
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         if (ByodHelperActivity.ACTION_INSTALL_APK_IN_PRIMARY.equals(getIntent().getAction())) {
39             final Uri uri = FileProvider.getUriForFile(this, Utils.FILE_PROVIDER_AUTHORITY,
40                     new File(ByodFlowTestActivity.HELPER_APP_PATH));
41             final Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE)
42                     .setData(uri)
43                     .putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
44                     .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
45                     .putExtra(Intent.EXTRA_RETURN_RESULT, true)
46                     .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
47             startActivityForResult(installIntent, REQUEST_INSTALL_PACKAGE);
48         }
49     }
50 
51     @Override
onActivityResult(int requestCode, int resultCode, Intent data)52     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
53         if (requestCode == REQUEST_INSTALL_PACKAGE) {
54             Log.w(TAG, "Receiving installer result " + resultCode + ".");
55             finish();
56         }
57     }
58 }