20 #include "fmserviceutilshandler.h" |
20 #include "fmserviceutilshandler.h" |
21 #include "fmcommon.h" |
21 #include "fmcommon.h" |
22 #include <shareui.h> |
22 #include <shareui.h> |
23 #include <afactivitystorage.h> |
23 #include <afactivitystorage.h> |
24 |
24 |
25 FmServiceUtilsPrivate::FmServiceUtilsPrivate() |
25 // CONSTANTS |
26 :mShareUi( 0 ), mServiceUtilsHandler( 0 ), mActivityStorage( 0 ) |
26 const int KAppCloseMiniSecTimeout = 1000; |
|
27 |
|
28 FmServiceUtilsPrivate::FmServiceUtilsPrivate( QObject *parent ) : QObject( parent ), |
|
29 mShareUi( 0 ), mServiceUtilsHandler( 0 ), mActivityStorage( 0 ), |
|
30 mIsCloseAppsFinished( false ), mIsCloseAppsTimeup( false ) |
27 { |
31 { |
28 |
32 connect(&mCloseAppTimer, SIGNAL(timeout()), this, SLOT(onCloseAppTimeup())); |
29 } |
33 } |
30 |
34 |
31 FmServiceUtilsPrivate::~FmServiceUtilsPrivate() |
35 FmServiceUtilsPrivate::~FmServiceUtilsPrivate() |
32 { |
36 { |
33 if( mShareUi ) { |
37 if( mShareUi ) { |
73 */ |
77 */ |
74 CFmServiceUtilsHandler *FmServiceUtilsPrivate::serviceUtilsHandler() |
78 CFmServiceUtilsHandler *FmServiceUtilsPrivate::serviceUtilsHandler() |
75 { |
79 { |
76 if( !mServiceUtilsHandler ) { |
80 if( !mServiceUtilsHandler ) { |
77 TRAPD(err, mServiceUtilsHandler = CFmServiceUtilsHandler::NewL()); |
81 TRAPD(err, mServiceUtilsHandler = CFmServiceUtilsHandler::NewL()); |
78 if( err != KErrNone ) { |
82 if( err == KErrNone ) { |
|
83 mServiceUtilsHandler->setObserver( this ); |
|
84 } else { |
79 mServiceUtilsHandler = 0; |
85 mServiceUtilsHandler = 0; |
80 } |
86 } |
81 } |
87 } |
82 return mServiceUtilsHandler; |
88 return mServiceUtilsHandler; |
83 } |
89 } |
96 this is synchronous which will take a while, please call this function in thread |
102 this is synchronous which will take a while, please call this function in thread |
97 */ |
103 */ |
98 void FmServiceUtilsPrivate::closeApps() |
104 void FmServiceUtilsPrivate::closeApps() |
99 { |
105 { |
100 CFmServiceUtilsHandler *utilsHandler = serviceUtilsHandler(); |
106 CFmServiceUtilsHandler *utilsHandler = serviceUtilsHandler(); |
|
107 mIsCloseAppsFinished = false; |
|
108 mIsCloseAppsTimeup = false; |
101 if( utilsHandler ) { |
109 if( utilsHandler ) { |
102 TRAP_IGNORE( utilsHandler->CloseAppsL() ); |
110 TRAP_IGNORE( utilsHandler->CloseAppsL() ); |
|
111 } |
|
112 |
|
113 // Memory card formatting cannot be executed if there are open files on it. |
|
114 // It has been detected, that in some cases memory card using applications |
|
115 // have no time to close file handles before formatting is tried to be executed. |
|
116 // To address this issue, we need to add a delay here after client-notification |
|
117 // about pending format and real formatting procedure. |
|
118 mCloseAppTimer.start( KAppCloseMiniSecTimeout ); |
|
119 |
|
120 //loop will be closed on both mIsCloseAppsFinished and mIsCloseAppsTimeup turned to true |
|
121 mCloseAppLoop.exec(); |
|
122 } |
|
123 |
|
124 /* |
|
125 This is observer function inherit from MServiceUtilsObserver |
|
126 So end with L letter no matter if it will leave |
|
127 handle close apps complete, exit loop if mIsCloseAppsTimeup is true |
|
128 */ |
|
129 void FmServiceUtilsPrivate::handleCloseAppCompleteL( TInt err ) |
|
130 { |
|
131 Q_UNUSED( err ); |
|
132 mIsCloseAppsFinished = true; |
|
133 if( mIsCloseAppsTimeup ) { |
|
134 mCloseAppLoop.exit(); |
|
135 } |
|
136 } |
|
137 |
|
138 /* |
|
139 handle close apps time up. exit loop if mIsCloseAppsFinished is true |
|
140 */ |
|
141 void FmServiceUtilsPrivate::onCloseAppTimeup() |
|
142 { |
|
143 mCloseAppTimer.stop(); |
|
144 mIsCloseAppsTimeup = true; |
|
145 if( mIsCloseAppsFinished ) { |
|
146 mCloseAppLoop.exit(); |
103 } |
147 } |
104 } |
148 } |
105 |
149 |
106 /*! |
150 /*! |
107 call CBaBackupSessionWrapper to restart apps |
151 call CBaBackupSessionWrapper to restart apps |