Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.tradefed.utils;
     18 
     19 import android.content.BroadcastReceiver;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.util.Log;
     23 
     24 /**
     25  * A BroadcastReceiver that starts a service to dismiss the keyguard.
     26  *
     27  * adb shell am broadcast -a com.android.tradefed.actor.DEVICE_SETUP
     28  */
     29 public class DeviceSetupIntentReceiver extends BroadcastReceiver {
     30 
     31     public static final String
     32             DEVICE_SETUP_INTENT = "com.android.tradefed.utils.DEVICE_SETUP";
     33     public static final String TAG = "DeviceSetupUtil";
     34     private final Intent intent = new Intent();
     35 
     36     @Override
     37     public void onReceive(Context context, Intent intent) {
     38         if (DEVICE_SETUP_INTENT.equals(intent.getAction())) {
     39             Log.v(TAG, "Starting Service");
     40             intent.setClass(context, DeviceSetupService.class);
     41             context.startService(intent);
     42         } else if (Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())) {
     43             // when power is disconnected assume the usb is disconnect,
     44             // stop the service from holding the wake lock
     45             Log.v(TAG, "Stopping Service");
     46             intent.setClass(context, DeviceSetupService.class);
     47             context.stopService(intent);
     48         } else if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())) {
     49             // when power is connected assume the usb is connected,
     50             // restart the service to acquire the wake lock
     51             Log.v(TAG, "Re-starting Service");
     52             intent.setClass(context, DeviceSetupService.class);
     53             context.startService(intent);
     54         }
     55         Log.v(TAG, "Recevied: " + intent.getAction());
     56     }
     57 }
     58