String processName = ActivityThread.currentProcessName();
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()) {
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;
}
}