66import androidx .media3 .ui .PlayerView ;
77import android .net .Uri ;
88import android .os .Bundle ;
9- import android .os .Handler ;
10- import android .os .Looper ;
119import android .util .Log ;
12- import android .view .View ;
13- import android .widget .Button ;
1410import com .newrelic .videoagent .core .NRVideo ;
1511import com .newrelic .videoagent .core .NRVideoPlayerConfiguration ;
1612import com .newrelic .videoagent .core .NewRelicVideoAgent ;
@@ -26,7 +22,6 @@ public class VideoPlayer extends AppCompatActivity {
2622
2723 private ExoPlayer player ;
2824 private Integer trackerId ;
29- private boolean isStressingCPU = false ;
3025
3126 @ Override
3227 protected void onCreate (Bundle savedInstanceState ) {
@@ -64,26 +59,7 @@ protected void onDestroy() {
6459 }
6560
6661 private void playVideo (String videoUrl ) {
67- //player = new ExoPlayer.Builder(this).build();
68- //Create ExoPlayer with custom configuration for easier frame drop detection
69- androidx .media3 .exoplayer .DefaultLoadControl loadControl = new androidx .media3 .exoplayer .DefaultLoadControl .Builder ()
70- .setBufferDurationsMs (
71- 500 , // Min buffer (very low to stress system)
72- 2000 , // Max buffer (low to force frequent loading)
73- 250 , // Buffer for playback
74- 500 // Buffer for playback after rebuffer
75- )
76- .build ();
77-
78- // Use default renderers factory without the problematic operation mode
79- androidx .media3 .exoplayer .DefaultRenderersFactory renderersFactory =
80- new androidx .media3 .exoplayer .DefaultRenderersFactory (this );
81-
82- player = new ExoPlayer .Builder (this )
83- .setLoadControl (loadControl )
84- .setRenderersFactory (renderersFactory )
85- .build ();
86- Log .d ("VideoPlayer" , "ExoPlayer created with LOW BUFFER settings for frame drop detection: " + player .getClass ().getSimpleName ());
62+ player = new ExoPlayer .Builder (this ).build ();
8763
8864 Map <String , Object > customAttr = new HashMap <>();
8965 customAttr .put ("something" , "This is my test title" );
@@ -115,93 +91,5 @@ private void playVideo(String videoUrl) {
11591 // Prepare the player.
11692 player .setPlayWhenReady (true );
11793 player .prepare ();
118-
119- // Add button to trigger frame drops for testing
120- setupFrameDropTestButton ();
121- }
122- private void setupFrameDropTestButton () {
123- Button frameDropButton = findViewById (R .id .button_frame_drop_attack );
124- if (frameDropButton != null ) {
125- frameDropButton .setOnClickListener (new View .OnClickListener () {
126- @ Override
127- public void onClick (View v ) {
128- ManualFrameDropAttack ();
129- }
130- });
131- }
132- }
133- private void ManualFrameDropAttack () {
134- // Attack 1: Saturate ALL threads with MAXIMUM priority
135- int cores = Runtime .getRuntime ().availableProcessors ();
136- for (int i = 0 ; i < cores * 4 ; i ++) { // 4x oversaturate
137- new Thread (new Runnable () {
138- @ Override
139- public void run () {
140- android .os .Process .setThreadPriority (android .os .Process .THREAD_PRIORITY_URGENT_AUDIO );
141- while (isStressingCPU ) {
142- // Most CPU-intensive operations possible
143- for (int j = 0 ; j < 10000000 ; j ++) { // 10 million iterations
144- double result = Math .pow (Math .sin (j ), Math .cos (j )) * Math .sqrt (j * Math .PI ) * Math .log (j + 1 );
145- }
146- }
147- }
148- }).start ();
149- }
150-
151- // Attack 2: Memory allocation bomb
152- new Thread (new Runnable () {
153- @ Override
154- public void run () {
155- try {
156- List <byte []> memoryBomb = new ArrayList <>();
157- for (int i = 0 ; i < 1000 ; i ++) {
158- memoryBomb .add (new byte [50 * 1024 * 1024 ]); // 50MB chunks
159- if (i % 5 == 0 ) System .gc (); // Frequent GC
160- }
161- } catch (OutOfMemoryError e ) {
162- Log .d ("VideoPlayer" , "Memory bomb successful - OOM triggered" );
163- }
164- }
165- }).start ();
166-
167- // Attack 3: Main thread destruction
168- brutalMainThreadBlocking ();
169-
170- isStressingCPU = true ;
171-
172- // Stop after 20 seconds
173- new Handler (Looper .getMainLooper ()).postDelayed (new Runnable () {
174- @ Override
175- public void run () {
176- isStressingCPU = false ;
177- }
178- }, 20000 );
179- }
180- private void brutalMainThreadBlocking () {
181- final Handler mainHandler = new Handler (Looper .getMainLooper ());
182- final Runnable blocker = new Runnable () {
183- int iteration = 0 ;
184-
185- @ Override
186- public void run () {
187- if (iteration < 100 ) {
188- // Block main thread for 200ms
189- long startTime = System .currentTimeMillis ();
190- while (System .currentTimeMillis () - startTime < 200 ) {
191- // Intensive work on main thread
192- for (int i = 0 ; i < 1000000 ; i ++) {
193- Math .sin (i * Math .PI );
194- }
195- }
196-
197- iteration ++;
198- Log .d ("VideoPlayer" , "Main thread blocked for 200ms - iteration " + iteration );
199-
200- // Block again in 100ms
201- mainHandler .postDelayed (this , 100 );
202- }
203- }
204- };
205- mainHandler .post (blocker );
20694 }
20795}
0 commit comments