1 /* 2 * Copyright (C) 2023 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.security.cts.CVE_2023_21254_helper; 18 19 import static android.Manifest.permission.RECORD_AUDIO; 20 import static android.app.ApplicationExitInfo.REASON_USER_REQUESTED; 21 22 import android.app.Activity; 23 import android.content.pm.PackageManager; 24 25 public class PocActivity extends Activity { 26 private static final int REQUEST_CODE = 1; 27 28 @Override onResume()29 protected void onResume() { 30 super.onResume(); 31 if (checkSelfPermission(RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { 32 requestPermissions(new String[] {RECORD_AUDIO}, REQUEST_CODE); 33 } 34 } 35 36 @Override onRequestPermissionsResult(int requestCode, String[] permissions, int[] results)37 public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) { 38 super.onRequestPermissionsResult(requestCode, permissions, results); 39 if (requestCode == REQUEST_CODE 40 && permissions[0].equals(RECORD_AUDIO) 41 && results[0] == PackageManager.PERMISSION_GRANTED) { 42 // Terminate app process if one-time permission is granted 43 System.exit(REASON_USER_REQUESTED); 44 } 45 } 46 } 47