LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ApplicationManager.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef __ApplicationManager_h__
23 #define __ApplicationManager_h__
24 
25 #include "Common.h"
26 
27 #include <vector>
28 #include <string>
29 #include <list>
30 #include <map>
31 #include <set>
32 
33 #include "lunaservice.h"
34 #include "Mutex.h"
35 #include "MimeSystem.h"
36 
37 #include <QObject>
38 #include <QBitArray>
39 
41 class PackageDescription;
42 class ServiceDescription;
43 class LaunchPoint;
44 class CommandHandler;
45 class ResourceHandler;
46 class RedirectHandler;
47 
48 //LAUNCHER3-ADDED:
49 namespace LaunchPointUpdatedReason
50 {
51  enum Enum
52  {
53  INVALID = 0,
58  };
59 }
60 
61 namespace LaunchPointAddedReason
62 {
63  enum Enum
64  {
65  INVALID = 0,
67  PostLaunchPointUpdateAdded, // temp flag - see AppMonitor::slotLaunchPointAdded
69  };
70 }
71 
72 namespace LaunchPointRemovedReason
73 {
74  enum Enum
75  {
76  INVALID = 0,
79  };
80 }
81 
82 // sort items in the search set by title
83 struct cmptitle {
84  bool operator()(const LaunchPoint*,const LaunchPoint*) const;
85 };
86 typedef std::set<const LaunchPoint*,cmptitle> SearchSet;
87 
88 namespace DimensionsSystemInterface
89 {
90 class AppEffector;
91 }
92 
94 {
95  Q_OBJECT
96 
97 public:
98 
99  //LAUNCHER3-ADDED: TEMP: need a better way to send LS messages but for now, just letting AppEffector in
100  // launcher have access to the service handle in here (with the proper precautions)
102 
103  typedef std::vector<const LaunchPoint *> LaunchPointCollection;
104 
106 
107  static ApplicationManager* instance();
108 
109  bool init();
110  void scan();
111  void postInstallScan(const std::string& appId);
112  void postInstallScan(json_object * pPackageInfoJson, const std::string& packageFolder);
113 
114  void launchBootTimeApps();
115  bool isLaunchAtBootApp(const std::string& appId);
116 
117  ApplicationDescription* getAppById(const std::string& id);
119  ApplicationDescription* getAppByMime(const std::string& mime);
120  ApplicationDescription* getPendingAppById(const std::string& id);
121 
122  PackageDescription* getPackageInfoByAppId(const std::string& anyAppIdInPackage);
123  PackageDescription* getPackageInfoByServiceId(const std::string& anyServiceIdInPackage);
124  PackageDescription* getPackageInfoByPackageId(const std::string& packageId);
125 
126  ServiceDescription* getServiceInfoByServiceId(const std::string& serviceId);
127 
128  bool getAppsByPackageId(const std::string& packageId, std::vector<ApplicationDescription *>& r_apps);
129  bool getServicesByPackageId(const std::string& packageId, std::vector<ServiceDescription *>& r_services);
130 
131  void searchLaunchPoints(SearchSet& matchedByTitle, SearchSet& matchedByKeyword, const std::string& searchTerm) const;
132 
133  bool removePendingApp(const std::string& id);
134  bool removePackage(const std::string& id,int cause);
135  const LaunchPoint* getLaunchPointById(const std::string& launchPointId);
136  const LaunchPoint* getLaunchPointByIdHardwareCompatibleAppsOnly(const std::string& launchPointId);
137 
138  std::string addLaunchPoint(const std::string& id,
139  const std::string& title,
140  const std::string& menuName,
141  const std::string& icon,
142  const std::string& params,
143  const bool removable=true);
144  bool removeLaunchPoint(const std::string& launchPointId,std::string& extendedReturnCause);
145  // NOTE: this will need to be extended in the future to support other field updates
146  bool updateLaunchPointIcon(const std::string& launchPointId, const std::string& newIconPath);
147 
148  bool enableDockModeLaunchPoint (const char* appId);
149  bool disableDockModeLaunchPoint (const char* appId);
150 
151  LaunchPointCollection dockLaunchPoints(bool *needsUpdate = NULL);
155 
156  const std::set<const LaunchPoint*>& enabledDockModeLaunchPoints() { return m_dockModeLaunchPoints; }
157 
158  std::vector<ApplicationDescription*> allApps();
159  std::map<std::string, PackageDescription*> allPackages();
160 
161 
162  std::string mimeTableAsJsonString();
163 
164  void relayStatus(const std::string& jsonPayload,const unsigned long ticketId);
165 
167  bool isTrustedInstallerApp (const std::string& uri) const;
168  bool isTrustedPalmApp(const ApplicationDescription* appDesc) const;
169  bool isTrustedPalmApp(const std::string& appId);
170 
171  //LAUNCHER3-ADDED: this is intended to be a one-stop shopping point to tell the launcher if this is an app which
172  // ships with the platform (either HPalm's own app or a "2nd party" contractor/partner app which should be treated the same way)
173  // For now it will just be a passthrough to isTrustedPalm().
174  bool isFactoryPlatformApp(const std::string& appId);
175 
177  unsigned long m_ticket;
179  std::string m_mime;
181 
182  DownloadRequest (unsigned long ticket, const std::string& ovrHandlerAppId, const std::string& strMime, bool isSubscribed)
183  : m_ticket(ticket), m_overrideHandlerAppId (ovrHandlerAppId), m_mime (strMime), m_isSubscribed (isSubscribed)
184  { }
185 
186  DownloadRequest (unsigned long ticket, bool isSubscribed)
187  : m_ticket (ticket), m_isSubscribed (isSubscribed)
188  { }
189  };
190 
191  static unsigned long s_ticketGenerator;
192 
193  static unsigned long generateNewTicket();
194 
195  static bool cbDownloadManagerUpdate (LSHandle* lsHandle, LSMessage* msg, void* user_data);
196  static bool isRemoteFile (const char* uri);
197  static bool isAppPackage(const char* uri);
198 
199  static bool getAppEntryPointFromAppinfoFile(const std::string& baseDirOfApp,std::string& r_entryPointPath);
200 
201  static bool cbAppInstallServiceConnection (LSHandle* lshandle, LSMessage* msg, void* user_data);
202  static bool cbApplicationStatusCallback (LSHandle* lsHandle, LSMessage* msg, void* user_data);
203  void handleApplicationStatusUpdates(LSMessage* msg);
204 
209  };
210  static void executeLockApp(const std::string& appId,ExecuteLockOperation op);
211 
212  void dbgEmitSignalLaunchPointUpdated(const LaunchPoint * lp,const QBitArray& statusBits);
213  static QString dbgOutputLaunchpointUpdateReasons(const QBitArray& reasons);
214 
215 Q_SIGNALS:
216 
217  //LAUNCHER3-ADD: (modified)
218  void signalLaunchPointRemoved(const LaunchPoint*,QBitArray reasons = QBitArray());
219  void signalLaunchPointUpdated(const LaunchPoint*,QBitArray reasons = QBitArray());
220  void signalLaunchPointAdded(const LaunchPoint*,QBitArray reasons = QBitArray());
221 
222  //LAUNCHER3-ADD:
223  void signalInitialScanStart();
224  void signalInitialScanEnd();
227 
228  //--end
229 
232 
233 public Q_SLOTS:
234 
235  void slotBuiltInAppEntryPoint_DockMode(const std::string& argsAsStringEncodedJson);
236  void slotBuiltInAppEntryPoint_VoiceDial(const std::string& argsAsStringEncodedJson);
238 
239  void slotBuiltInAppEntryPoint_Launchermode0(const std::string& argsAsStringEncodedJson);
240 
241 private:
242 
243  void scanForApplications();
244  void scanForPackages();
245  void createPackageDescriptionForOldApps();
246  void scanForServices();
247  void scanForSystemApplications();
248  void scanForPendingApplications();
249  void scanForLaunchPoints(std::string launchPointFolder);
250  void scanApplicationsFolders(const std::string& appFolders);
251  void scanApplicationsFolders(const std::string& appFoldersPath,std::map<std::string,ApplicationDescription *>& foundApps);
252  ApplicationDescription* scanOneApplicationFolder(const std::string& appFolderPath);
253  PackageDescription* scanOnePackageFolder(const std::string& packageFolderPath);
254  ServiceDescription* scanOneServiceFolder(const std::string& serviceFolderPath);
255 
256  ApplicationDescription* installApp(const std::string& appId);
257  ApplicationDescription* installSysApp(const std::string& appId);
258  bool removeApp(const std::string& id,int cause);
259  bool removeSysApp(const std::string& id);
260 
261  //discoverAppChanges: temporal non-safety; apps may change state after the lists are generated. Call under proper locks
262  void discoverAppChanges(std::vector<ApplicationDescription *>& added,std::vector<ApplicationDescription *>& removed,std::vector<ApplicationDescription *>& changed);
263 
264  ApplicationDescription* getAppById( const std::string& appId,const std::map<std::string,ApplicationDescription *>& appMap);
265 
266  void scanFolderResursively( const std::string& path );
267  void clear();
268  void dumpStats();
269  std::string findUniqueFileName(const std::string& folder);
270  bool isNumber(const std::string& str) const;
271  static bool isValidMimeType( const std::string& mime );
272  static bool isGenericMimeType( const std::string& mime );
273  static std::string getContentType(const std::string& mime);
274  static bool urlSchemeIsFile( const std::string& url );
275  static std::string deriveMimeTypeFromFileMagic( const std::string& localFilePath );
276 
277  static void createOrUpdatePackageManifest(PackageDescription* packageDesc);
278 
279  static void serviceInstallerInstallApp(const std::string& id, const std::string& type, const std::string& root);
280  static void serviceInstallerUninstallApp(const std::string& id, const std::string& type, const std::string& root);
281 
282  void runAppInstallScripts();
283  void loadHiddenApps();
284  void hideApp(const std::string& appId);
285  bool isAppHidden(const std::string& appId) const;
286  bool isSysappAllowed(const std::string& sysappId,const std::string& sourcePath);
287 
288  void executeLockAppLoaded(const std::string& appId,ExecuteLockOperation op);
289  static std::set<std::string> s_appExeclockSet;
290  static Mutex s_mutexExecLockFunctions;
291 
292  std::set<std::string> m_hiddenApps;
293  std::vector<ApplicationDescription*> m_registeredApps;
294  std::vector<ApplicationDescription*> m_systemApps;
295  std::vector<ApplicationDescription*> m_pendingApps;
296 
297  std::set<const LaunchPoint*> m_dockModeLaunchPoints;
298 
299  std::map<std::string, PackageDescription*> m_registeredPackages;
300  std::map<std::string, ServiceDescription*> m_registeredServices;
301 
302  Mutex m_mutex;
303 
304  bool startService();
305  void stopService();
306  void postLaunchPointChange(const LaunchPoint* lp, const std::string& change);
307  LSPalmService* m_service;
308  LSHandle* m_serviceHandlePublic;
309  LSHandle* m_serviceHandlePrivate;
310  static long s_ticketId;
311  bool m_initialScan;
312 
314  ApplicationManager& operator=( const ApplicationManager& );
316 };
317 
318 // Calback for the ListRunningApps response generated by the AppManager service
319 void appManagerCallback_listRunningApps( const std::string& runnigAppsJsonArray );
320 
321 #endif // __ApplicationManager_h__