@Override public void handleMessage(Message msg) { synchronized (mLock) { switch (msg.what) { case MSG_UPDATE_STATE: if (mConnected != mLastConnected || mConfiguration != mLastConfiguration) { if (mConnected == 0) { if (UsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_ACCESSORY)) { // make sure accessory mode is off, and restore default functions Log.d(TAG, "exited USB accessory mode"); if (!UsbManager.setFunctionEnabled( UsbManager.USB_FUNCTION_ACCESSORY, false)) { Log.e(TAG, "could not disable accessory function"); } int count = mDefaultFunctions.size(); for (int i = 0; i < count; i++) { String function = mDefaultFunctions.get(i); if (!UsbManager.setFunctionEnabled(function, true)) { Log.e(TAG, "could not reenable function " + function); } } if (mCurrentAccessory != null) { mDeviceManager.accessoryDetached(mCurrentAccessory); mCurrentAccessory = null; } } } final ContentResolver cr = mContext.getContentResolver(); if (Settings.Secure.getInt(cr, Settings.Secure.DEVICE_PROVISIONED, 0) == 0) { Slog.i(TAG, "Device not provisioned, skipping USB broadcast"); return; } mLastConnected = mConnected; mLastConfiguration = mConfiguration; // send a sticky broadcast containing current USB state Intent intent = new Intent(UsbManager.ACTION_USB_STATE); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra(UsbManager.USB_CONNECTED, mConnected != 0); intent.putExtra(UsbManager.USB_CONFIGURATION, mConfiguration); addEnabledFunctionsLocked(intent); mContext.sendStickyBroadcast(intent); } break; case MSG_FUNCTION_ENABLED: case MSG_FUNCTION_DISABLED: functionEnabledLocked((String) msg.obj, msg.what == MSG_FUNCTION_ENABLED); break; } } }
public void ding(int tick) { context.sendStickyBroadcast(new Intent(ACTION_JTT_TICK).putExtra(EXTRA_JTT, tick)); }