diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index e579e07125f..07289bc4a4c 100755
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -230,6 +230,8 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
+import android.hardware.usb.UsbManager;
+import android.os.BatteryManager;
/**
* WindowManagerPolicy implementation for the Android phone UI. This
@@ -306,7 +308,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
static final int PENDING_KEY_NULL = -1;
-
+
+ public static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
@@ -1923,6 +1926,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
filter.addAction(Intent.ACTION_DREAMING_STARTED);
filter.addAction(Intent.ACTION_DREAMING_STOPPED);
context.registerReceiver(mDreamReceiver, filter);
+
+ //swl add
+ filter = new IntentFilter(ACTION_USB_PERMISSION);
+ filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+ context.registerReceiver(mUsbReceiver, filter);
// register for multiuser-relevant broadcasts
filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
@@ -4370,7 +4378,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
};
+
+ //swl add
+ BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
+ int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
+ boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
+ if (usbCharge) {
+ Intent mainActivityIntent =new Intent();
+ mainActivityIntent.setClassName("com.google.android.apps.photos","com.google.android.apps.photos.home.HomeActivity");
+ mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(mainActivityIntent);
+ } else {
+ return;
+ }
+ }
+ }
+ };
+ // end
BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {