* commit 'cda0ab683604ade10ea11298887421801ae6b144': Show usb charging notification when in host mode
This commit is contained in:
@@ -19,15 +19,19 @@ package com.android.server.usb;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.hardware.usb.UsbAccessory;
|
import android.hardware.usb.UsbAccessory;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
|
import android.hardware.usb.UsbPort;
|
||||||
|
import android.hardware.usb.UsbPortStatus;
|
||||||
import android.os.FileUtils;
|
import android.os.FileUtils;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -105,6 +109,7 @@ public class UsbDeviceManager {
|
|||||||
private static final int MSG_USER_SWITCHED = 5;
|
private static final int MSG_USER_SWITCHED = 5;
|
||||||
private static final int MSG_SET_USB_DATA_UNLOCKED = 6;
|
private static final int MSG_SET_USB_DATA_UNLOCKED = 6;
|
||||||
private static final int MSG_UPDATE_USER_RESTRICTIONS = 7;
|
private static final int MSG_UPDATE_USER_RESTRICTIONS = 7;
|
||||||
|
private static final int MSG_UPDATE_HOST_STATE = 8;
|
||||||
|
|
||||||
private static final int AUDIO_MODE_SOURCE = 1;
|
private static final int AUDIO_MODE_SOURCE = 1;
|
||||||
|
|
||||||
@@ -175,6 +180,15 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final BroadcastReceiver mHostReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
UsbPort port = intent.getParcelableExtra(UsbManager.EXTRA_PORT);
|
||||||
|
UsbPortStatus status = intent.getParcelableExtra(UsbManager.EXTRA_PORT_STATUS);
|
||||||
|
mHandler.updateHostState(port, status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public UsbDeviceManager(Context context, UsbAlsaManager alsaManager) {
|
public UsbDeviceManager(Context context, UsbAlsaManager alsaManager) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mUsbAlsaManager = alsaManager;
|
mUsbAlsaManager = alsaManager;
|
||||||
@@ -197,6 +211,8 @@ public class UsbDeviceManager {
|
|||||||
if (secureAdbEnabled && !dataEncrypted) {
|
if (secureAdbEnabled && !dataEncrypted) {
|
||||||
mDebuggingManager = new UsbDebuggingManager(context);
|
mDebuggingManager = new UsbDebuggingManager(context);
|
||||||
}
|
}
|
||||||
|
mContext.registerReceiver(mHostReceiver,
|
||||||
|
new IntentFilter(UsbManager.ACTION_USB_PORT_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
private UsbSettingsManager getCurrentSettings() {
|
private UsbSettingsManager getCurrentSettings() {
|
||||||
@@ -299,6 +315,7 @@ public class UsbDeviceManager {
|
|||||||
|
|
||||||
// current USB state
|
// current USB state
|
||||||
private boolean mConnected;
|
private boolean mConnected;
|
||||||
|
private boolean mHostConnected;
|
||||||
private boolean mConfigured;
|
private boolean mConfigured;
|
||||||
private boolean mUsbDataUnlocked;
|
private boolean mUsbDataUnlocked;
|
||||||
private String mCurrentFunctions;
|
private String mCurrentFunctions;
|
||||||
@@ -377,6 +394,11 @@ public class UsbDeviceManager {
|
|||||||
sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0);
|
sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateHostState(UsbPort port, UsbPortStatus status) {
|
||||||
|
boolean hostConnected = status.getCurrentDataRole() == UsbPort.DATA_ROLE_HOST;
|
||||||
|
obtainMessage(MSG_UPDATE_HOST_STATE, hostConnected ? 1 :0, 0).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean waitForState(String state) {
|
private boolean waitForState(String state) {
|
||||||
// wait for the transition to complete.
|
// wait for the transition to complete.
|
||||||
// give up after 1 second.
|
// give up after 1 second.
|
||||||
@@ -652,6 +674,10 @@ public class UsbDeviceManager {
|
|||||||
updateUsbFunctions();
|
updateUsbFunctions();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MSG_UPDATE_HOST_STATE:
|
||||||
|
mHostConnected = (msg.arg1 == 1);
|
||||||
|
updateUsbNotification();
|
||||||
|
break;
|
||||||
case MSG_ENABLE_ADB:
|
case MSG_ENABLE_ADB:
|
||||||
setAdbEnabled(msg.arg1 == 1);
|
setAdbEnabled(msg.arg1 == 1);
|
||||||
break;
|
break;
|
||||||
@@ -707,7 +733,7 @@ public class UsbDeviceManager {
|
|||||||
if (mNotificationManager == null || !mUseUsbNotification) return;
|
if (mNotificationManager == null || !mUseUsbNotification) return;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
Resources r = mContext.getResources();
|
Resources r = mContext.getResources();
|
||||||
if (mConnected) {
|
if (mConnected || mHostConnected) {
|
||||||
if (!mUsbDataUnlocked) {
|
if (!mUsbDataUnlocked) {
|
||||||
id = com.android.internal.R.string.usb_charging_notification_title;
|
id = com.android.internal.R.string.usb_charging_notification_title;
|
||||||
} else if (UsbManager.containsFunction(mCurrentFunctions,
|
} else if (UsbManager.containsFunction(mCurrentFunctions,
|
||||||
|
|||||||
Reference in New Issue
Block a user