summaryrefslogtreecommitdiff
path: root/packages/FakeOemFeatures/src
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-02-27 18:37:40 -0800
committerDianne Hackborn <hackbod@google.com>2012-02-27 18:46:29 -0800
commitd459f4bbfcfe4989a0e2298b3cfd36064b386b88 (patch)
tree2daf1a933af25393ef94b5d086cacb92aef1bf47 /packages/FakeOemFeatures/src
parent35ae6e2a841d8a287bccb56881f58e9fe24a07b6 (diff)
You could think of this as what an OEM might do.
Except it does nothing. But eat resources. Yum, yum! Current we create five processes. The main process sucks up 16MB of RAM and creates a full-screen window; only on high-end devices does the window (and process) use the GPU. The second through fourth processes just sits there not really doing anything except using process overhead. The fifth process runs a background service, slowing eating RAM until it gets killed by the system (as the system will ultimately do with background services). It also creates a full-screen window, and always uses the GPU even on low-end devices. Change-Id: Ibe9e25f7dbd889f4dc83eed6a3c09b9b0437b4e3
Diffstat (limited to 'packages/FakeOemFeatures/src')
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java157
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java110
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService.java31
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService2.java20
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService3.java20
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeView.java79
6 files changed, 417 insertions, 0 deletions
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java
new file mode 100644
index 000000000000..436e57976c98
--- /dev/null
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fakeoemfeatures;
+
+import android.app.ActivityManager;
+import android.app.ActivityThread;
+import android.app.AlertDialog;
+import android.app.Application;
+import android.app.Dialog;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.util.Slog;
+import android.view.Display;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+
+public class FakeApp extends Application {
+ // Stuffing of 20MB
+ static final int STUFFING_SIZE_BYTES = 20*1024*1024;
+ static final int STUFFING_SIZE_INTS = STUFFING_SIZE_BYTES/4;
+ int[] mStuffing;
+
+ // Assume 4k pages.
+ static final int PAGE_SIZE = 4*1024;
+
+ static final long TICK_DELAY = 4*60*60*1000; // One hour
+ static final int MSG_TICK = 1;
+ final Handler mHandler = new Handler() {
+ @Override public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_TICK:
+ // Our service is IMPORTANT. We know, we wrote it.
+ // We need to keep that thing running. Because WE KNOW.
+ // Damn you users, STOP MESSING WITH US.
+ startService(new Intent(FakeApp.this, FakeBackgroundService.class));
+ sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
+ break;
+ default:
+ super.handleMessage(msg);
+ break;
+ }
+ }
+ };
+
+ // Always run another process for more per-process overhead.
+ ServiceConnection mServiceConnection = new ServiceConnection() {
+ @Override public void onServiceConnected(ComponentName name, IBinder service) {
+ }
+
+ @Override public void onServiceDisconnected(ComponentName name) {
+ }
+ };
+ ServiceConnection mServiceConnection2 = new ServiceConnection() {
+ @Override public void onServiceConnected(ComponentName name, IBinder service) {
+ }
+
+ @Override public void onServiceDisconnected(ComponentName name) {
+ }
+ };
+ ServiceConnection mServiceConnection3 = new ServiceConnection() {
+ @Override public void onServiceConnected(ComponentName name, IBinder service) {
+ }
+
+ @Override public void onServiceDisconnected(ComponentName name) {
+ }
+ };
+
+ @Override
+ public void onCreate() {
+ String processName = ActivityThread.currentPackageName();
+ Slog.i("FakeOEMFeatures", "Creating app in process: " + processName);
+ if (!getApplicationInfo().packageName.equals(processName)) {
+ // If we are not in the main process of the app, then don't do
+ // our extra overhead stuff.
+ return;
+ }
+
+ final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
+ final Display display = wm.getDefaultDisplay();
+
+ // Check to make sure we are not running on a user build. If this
+ // is a user build, WARN! Do not want!
+ if ("user".equals(android.os.Build.TYPE)) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Should not be on user build");
+ builder.setMessage("The app Fake OEM Features should not be installed on a "
+ + "user build. Please remove this .apk before shipping this build to "
+ + " your customers!");
+ builder.setCancelable(false);
+ builder.setPositiveButton("I understand", null);
+ Dialog dialog = builder.create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ // Make a fake window that is always around eating graphics resources.
+ FakeView view = new FakeView(this);
+ WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
+ WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+ | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ if (ActivityManager.isHighEndGfx(display)) {
+ lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
+ }
+ lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
+ lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
+ int maxSize = display.getMaximumSizeDimension();
+ maxSize *= 2;
+ lp.x = maxSize;
+ lp.y = maxSize;
+ lp.setTitle(getPackageName());
+ wm.addView(view, lp);
+
+ // Bind to a fake service we want to keep running in another process.
+ bindService(new Intent(this, FakeCoreService.class), mServiceConnection,
+ Context.BIND_AUTO_CREATE);
+ bindService(new Intent(this, FakeCoreService2.class), mServiceConnection2,
+ Context.BIND_AUTO_CREATE);
+ bindService(new Intent(this, FakeCoreService3.class), mServiceConnection3,
+ Context.BIND_AUTO_CREATE);
+
+ // Start to a fake service that should run in the background of
+ // another process.
+ mHandler.sendEmptyMessage(MSG_TICK);
+
+ // Make a fake allocation to consume some RAM.
+ mStuffing = new int[STUFFING_SIZE_INTS];
+ for (int i=0; i<STUFFING_SIZE_BYTES/PAGE_SIZE; i++) {
+ // Fill each page with a unique value.
+ final int VAL = i*2 + 100;
+ final int OFF = (i*PAGE_SIZE)/4;
+ for (int j=0; j<(PAGE_SIZE/4); j++) {
+ mStuffing[OFF+j] = VAL;
+ }
+ }
+ }
+}
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java
new file mode 100644
index 000000000000..5d1a3980d726
--- /dev/null
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fakeoemfeatures;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import android.app.Dialog;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.view.Display;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+
+public class FakeBackgroundService extends Service {
+ final ArrayList<int[]> mAllocs = new ArrayList<int[]>();
+
+ final Random mRandom = new Random();
+
+ static final long TICK_DELAY = 30*1000; // 30 seconds
+ static final int MSG_TICK = 1;
+ final Handler mHandler = new Handler() {
+ @Override public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_TICK:
+ // We are awesome! To prove we are doing awesome stuff,
+ // we must use some memory! It wouldn't be awesome if
+ // we didn't use memory!
+ for (int i=0; i<5; i++) {
+ try {
+ int[] alloc = new int[FakeApp.PAGE_SIZE/4];
+ mAllocs.add(alloc);
+ final int VAL = mRandom.nextInt();
+ for (int j=0; j<FakeApp.PAGE_SIZE/4; j++) {
+ alloc[j] = VAL;
+ }
+ } catch (OutOfMemoryError e) {
+ }
+ }
+ sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
+ break;
+ default:
+ super.handleMessage(msg);
+ break;
+ }
+ }
+ };
+
+ @Override public void onCreate() {
+ super.onCreate();
+ mHandler.sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
+
+ final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
+ final Display display = wm.getDefaultDisplay();
+
+ // Make a fake window that is always around eating graphics resources.
+ FakeView view = new FakeView(this);
+ Dialog dialog = new Dialog(this, android.R.style.Theme_Holo_Dialog);
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.getWindow().setFlags(
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+ | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
+ | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+ | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
+ | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
+ | WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+ dialog.getWindow().setDimAmount(0);
+ dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
+ int maxSize = display.getMaximumSizeDimension();
+ maxSize *= 2;
+ lp.x = maxSize;
+ lp.y = maxSize;
+ lp.setTitle(getPackageName() + ":background");
+ dialog.getWindow().setAttributes(lp);
+ dialog.getWindow().setContentView(view);
+ dialog.show();
+ }
+
+ @Override public void onDestroy() {
+ super.onDestroy();
+ mHandler.removeMessages(MSG_TICK);
+ }
+
+ @Override public IBinder onBind(Intent intent) {
+ return null;
+ }
+}
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService.java
new file mode 100644
index 000000000000..86bc506b5f72
--- /dev/null
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fakeoemfeatures;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.IBinder;
+
+public class FakeCoreService extends Service {
+ final Binder mBinder = new Binder();
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+}
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService2.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService2.java
new file mode 100644
index 000000000000..f06988dbcaa5
--- /dev/null
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService2.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fakeoemfeatures;
+
+public class FakeCoreService2 extends FakeCoreService {
+}
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService3.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService3.java
new file mode 100644
index 000000000000..a35adb227022
--- /dev/null
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeCoreService3.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fakeoemfeatures;
+
+public class FakeCoreService3 extends FakeCoreService {
+}
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeView.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeView.java
new file mode 100644
index 000000000000..276d55ee9a5e
--- /dev/null
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeView.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fakeoemfeatures;
+
+import java.util.Random;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.os.Handler;
+import android.os.Message;
+import android.view.View;
+
+/**
+ * Dummy view to emulate stuff an OEM may want to do.
+ */
+public class FakeView extends View {
+ static final long TICK_DELAY = 30*1000; // 30 seconds
+ static final int MSG_TICK = 1;
+
+ final Handler mHandler = new Handler() {
+ @Override public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_TICK:
+ invalidate();
+ sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
+ break;
+ default:
+ super.handleMessage(msg);
+ break;
+ }
+ }
+ };
+
+ final Paint mPaint = new Paint();
+ final Random mRandom = new Random();
+
+ public FakeView(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ mHandler.sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ mHandler.removeMessages(MSG_TICK);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ canvas.drawColor(0xff000000);
+ mPaint.setTextSize(mRandom.nextInt(40) + 10);
+ mPaint.setColor(0xff000000 + mRandom.nextInt(0x1000000));
+ int x = mRandom.nextInt(getWidth()) - (getWidth()/2);
+ int y = mRandom.nextInt(getHeight());
+ canvas.drawText("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ x, y, mPaint);
+ }
+}