252 aStateOld); |
252 aStateOld); |
253 break; |
253 break; |
254 } |
254 } |
255 LOG1( "Starting USB personality in device state: %d", aStateNew ); |
255 LOG1( "Starting USB personality in device state: %d", aStateNew ); |
256 iPersonalityHandler->StateChangeNotify( aStateOld, aStateNew ); |
256 iPersonalityHandler->StateChangeNotify( aStateOld, aStateNew ); |
257 // Check AskOnConnection setting every time |
|
258 if( ( iSupportedPersonalities.Count() > 1 ) && |
|
259 !IsAskOnConnectionSuppression() ) |
|
260 { |
|
261 // read setting if there is more than one personality |
|
262 iPersonalityRepository->Get( |
|
263 KUsbWatcherChangeOnConnectionSetting, |
|
264 iAskOnConnectionSetting ); |
|
265 } |
|
266 |
257 |
267 if( ( iState == EUsbIdle ) && !iPersonalityChangeOngoing ) |
258 if( ( iState == EUsbIdle ) && !iPersonalityChangeOngoing ) |
268 { |
259 { |
269 Start(); |
260 Start(); |
270 } |
261 } |
271 else if( ( iState != EUsbStarted ) && !iPersonalityChangeOngoing ) |
262 else if( ( iState != EUsbStarted ) && !iPersonalityChangeOngoing ) |
272 { |
263 { |
273 Cancel(); |
264 Cancel(); |
274 Start(); |
265 Start(); |
275 } |
266 } |
276 |
|
277 // Let's turn ask on connection off after start cause we will |
|
278 // issue it only when cable is connected |
|
279 iAskOnConnectionSetting = KUsbWatcherChangeOnConnectionOff; |
|
280 |
267 |
281 //start usbdevcon only in normal global state |
268 //start usbdevcon only in normal global state |
282 TInt globalState = |
269 TInt globalState = |
283 CUsbGlobalSystemStateObserver::GlobalSystemState(); |
270 CUsbGlobalSystemStateObserver::GlobalSystemState(); |
284 if( ( ESwStateNormalRfOn == globalState ) || |
271 if( ( ESwStateNormalRfOn == globalState ) || |
528 |
515 |
529 LOG1( "USB device state after unlock: %d", state ); |
516 LOG1( "USB device state after unlock: %d", state ); |
530 if( EUsbDeviceStateAttached == state || EUsbDeviceStatePowered == state) |
517 if( EUsbDeviceStateAttached == state || EUsbDeviceStatePowered == state) |
531 { |
518 { |
532 LOG( "Starting USB personality" ); |
519 LOG( "Starting USB personality" ); |
533 TInt err = iPersonalityRepository->Get( |
520 Start(); |
534 KUsbWatcherChangeOnConnectionSetting, iAskOnConnectionSetting ); |
|
535 if( KErrNone == err ) |
|
536 { |
|
537 Start(); |
|
538 iAskOnConnectionSetting = KUsbWatcherChangeOnConnectionOff; |
|
539 } |
|
540 else |
|
541 { |
|
542 LOG1( "Error: CRepository::Get = %d", err ); |
|
543 } |
|
544 } |
521 } |
545 } |
522 } |
546 |
523 |
547 // ---------------------------------------------------------------------------- |
524 // ---------------------------------------------------------------------------- |
548 // This method is called when client wants to set new personality. |
525 // This method is called when client wants to set new personality. |
768 RProperty::Set( KPSUidUsbWatcher, |
745 RProperty::Set( KPSUidUsbWatcher, |
769 KUsbWatcherSelectedPersonality, iPersonalityId ); |
746 KUsbWatcherSelectedPersonality, iPersonalityId ); |
770 iStarted = ETrue; |
747 iStarted = ETrue; |
771 // Restore personality to normal in charging mode |
748 // Restore personality to normal in charging mode |
772 iSetPreviousPersonalityOnDisconnect = ETrue; |
749 iSetPreviousPersonalityOnDisconnect = ETrue; |
773 iPersonalityHandler->StartPersonality( iPersonalityId, |
750 iPersonalityHandler->StartPersonality( iPersonalityId, iStatus ); |
774 KUsbWatcherChangeOnConnectionOff, iStatus ); |
|
775 } |
751 } |
776 else |
752 else |
777 { |
753 { |
778 LOG1( "GetChargingPersonalityId = %d. Not started", ret ); |
754 LOG1( "GetChargingPersonalityId = %d. Not started", ret ); |
779 } |
755 } |
788 { |
764 { |
789 iGlobalStateObserver->Cancel(); |
765 iGlobalStateObserver->Cancel(); |
790 RProperty::Set( KPSUidUsbWatcher, |
766 RProperty::Set( KPSUidUsbWatcher, |
791 KUsbWatcherSelectedPersonality, iPersonalityId ); |
767 KUsbWatcherSelectedPersonality, iPersonalityId ); |
792 iStarted = ETrue; |
768 iStarted = ETrue; |
793 iPersonalityHandler->StartPersonality( iPersonalityId, |
769 iPersonalityHandler->StartPersonality( iPersonalityId, iStatus ); |
794 iAskOnConnectionSetting, iStatus ); |
|
795 } |
770 } |
796 else |
771 else |
797 { |
772 { |
798 LOG( "Device LOCKED, USB personality NOT start" ); |
773 LOG( "Device LOCKED, USB personality NOT start" ); |
799 } |
774 } |
1032 LOG2( "ret = %d ( aPersonalityId: %d )", ret, aPersonalityId ); |
1007 LOG2( "ret = %d ( aPersonalityId: %d )", ret, aPersonalityId ); |
1033 return ret; |
1008 return ret; |
1034 } |
1009 } |
1035 |
1010 |
1036 // ---------------------------------------------------------------------------- |
1011 // ---------------------------------------------------------------------------- |
1037 // Check if there is an observer with ask on connection suppression |
|
1038 // ---------------------------------------------------------------------------- |
|
1039 // |
|
1040 TBool CUsbWatcher::IsAskOnConnectionSuppression() |
|
1041 { |
|
1042 LOG_FUNC |
|
1043 |
|
1044 TBool ret( EFalse ); |
|
1045 for( TInt i = 0; i < iObservers.Count(); i++ ) |
|
1046 { |
|
1047 if( iObservers[i]->IsAskOnConnectionSuppressed() ) |
|
1048 { |
|
1049 ret = ETrue; |
|
1050 break; |
|
1051 } |
|
1052 } |
|
1053 LOG1( "Return = %d", ret ); |
|
1054 return ret; |
|
1055 } |
|
1056 |
|
1057 // ---------------------------------------------------------------------------- |
|
1058 // Check current A or B device state |
1012 // Check current A or B device state |
1059 // ---------------------------------------------------------------------------- |
1013 // ---------------------------------------------------------------------------- |
1060 // |
1014 // |
1061 TBool CUsbWatcher::IsDeviceA() |
1015 TBool CUsbWatcher::IsDeviceA() |
1062 { |
1016 { |