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 {
static final int STUFFING_SIZE_BYTES = 20*1024*1024;
static final int STUFFING_SIZE_INTS = STUFFING_SIZE_BYTES/4;
int[] mStuffing;
static final int PAGE_SIZE = 4*1024;
static final long TICK_DELAY = 4*60*60*1000;
static final int MSG_TICK = 1;
final Handler mHandler = new Handler() {
@Override public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_TICK:
startService(new Intent(FakeApp.this, FakeBackgroundService.class));
sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
break;
default:
super.handleMessage(msg);
break;
}
}
};
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.currentProcessName();
Slog.i("FakeOEMFeatures", "Creating app in process: " + processName);
if (!getApplicationInfo().packageName.equals(processName)) {
return;
}
final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
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_APPLICATION_OVERLAY);
dialog.show();
}
FakeView view = new FakeView(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
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);
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);
mHandler.sendEmptyMessage(MSG_TICK);
mStuffing = new int[STUFFING_SIZE_INTS];
for (int i=0; i<STUFFING_SIZE_BYTES/PAGE_SIZE; i++) {
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;
}
}
}
}