<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
public class LockService extends Service {
PowerManager.WakeLock wl;
WindowManager mWindowManager;
boolean isShowing;
View mView;
Thread mThread;
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_SCREEN_ON)) {
if (isShowing) {
if ((mThread == null)
|| ((mThread != null) && (!mThread.isAlive())))
mThread = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(1000);
mWindowManager.removeView(mView);
isShowing = false;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
mThread.start();
}
}
if (action.equals(Intent.ACTION_SCREEN_OFF)) {
if (!isShowing) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
|
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
mWindowManager.addView(mView, params);
isShowing = true;
}
}
}
};
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
mView = new View(this);
mView.setBackgroundColor(Color.BLACK);
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"com.google.syncloc.SyncLocService");
wl.acquire();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
//intentFilter.addAction(Intent.ACTION_USER_PRESENT);
intentFilter.setPriority(999);
registerReceiver(mReceiver, intentFilter);
super.onCreate();
}
@Override
public void onDestroy() {
if (isShowing)
mWindowManager.removeView(mView);
if ((mThread != null) && (mThread.isAlive()))
mThread.interrupt();
wl.release();
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
}
void setup()
{
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
delay(300);
digitalWrite(7, HIGH);
Serial.begin(115200);
Serial.print("\r\nStart");
acc.powerOn();
}
Device addressed… Requesting device descriptor.
found possible device. swithcing to serial mode
device supports protcol 1
Setup packet error: D
Device addressed… Requesting device descriptor.
found android acessory device
config desc
interface desc
interface desc
C
D
Accessory connected. Message length: -1
Accessory connected. Message length: -1
Accessory connected. Message length: -1
Device addressed… Requesting device descriptor.
found possible device. swithcing to serial mode
Data packet error: 5could not read device protocol version
Device addressed… Requesting device descriptor.
Setup packet error: D
Device descriptor cannot be retrieved. Trying again