1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.camera.app; 18 19 import android.app.Application; 20 import android.app.NotificationManager; 21 import android.content.Context; 22 23 import com.android.camera.MediaSaverImpl; 24 import com.android.camera.debug.LogHelper; 25 import com.android.camera.processing.ProcessingServiceManager; 26 import com.android.camera.remote.RemoteShutterListener; 27 import com.android.camera.session.CaptureSessionManager; 28 import com.android.camera.session.CaptureSessionManagerImpl; 29 import com.android.camera.session.PlaceholderManager; 30 import com.android.camera.session.SessionStorageManager; 31 import com.android.camera.session.SessionStorageManagerImpl; 32 import com.android.camera.settings.SettingsManager; 33 import com.android.camera.util.CameraUtil; 34 import com.android.camera.util.RemoteShutterHelper; 35 import com.android.camera.util.SessionStatsCollector; 36 import com.android.camera.util.UsageStatistics; 37 38 /** 39 * The Camera application class containing important services and functionality 40 * to be used across modules. 41 */ 42 public class CameraApp extends Application implements CameraServices { 43 private MediaSaver mMediaSaver; 44 private CaptureSessionManager mSessionManager; 45 private SessionStorageManager mSessionStorageManager; 46 private MemoryManagerImpl mMemoryManager; 47 private PlaceholderManager mPlaceHolderManager; 48 private RemoteShutterListener mRemoteShutterListener; 49 private MotionManager mMotionManager; 50 private SettingsManager mSettingsManager; 51 52 @Override onCreate()53 public void onCreate() { 54 super.onCreate(); 55 56 Context context = getApplicationContext(); 57 LogHelper.initialize(context); 58 59 // It is important that this gets called early in execution before the 60 // app has had the opportunity to create any shared preferences. 61 UsageStatistics.instance().initialize(this); 62 SessionStatsCollector.instance().initialize(this); 63 CameraUtil.initialize(this); 64 65 ProcessingServiceManager.initSingleton(context); 66 67 mMediaSaver = new MediaSaverImpl(); 68 mPlaceHolderManager = new PlaceholderManager(context); 69 mSessionStorageManager = SessionStorageManagerImpl.create(this); 70 mSessionManager = new CaptureSessionManagerImpl(mMediaSaver, getContentResolver(), 71 mPlaceHolderManager, mSessionStorageManager); 72 mMemoryManager = MemoryManagerImpl.create(getApplicationContext(), mMediaSaver); 73 mRemoteShutterListener = RemoteShutterHelper.create(this); 74 mSettingsManager = new SettingsManager(this); 75 76 clearNotifications(); 77 78 mMotionManager = new MotionManager(context); 79 } 80 81 @Override getCaptureSessionManager()82 public CaptureSessionManager getCaptureSessionManager() { 83 return mSessionManager; 84 } 85 86 @Override getMemoryManager()87 public MemoryManager getMemoryManager() { 88 return mMemoryManager; 89 } 90 91 @Override getMotionManager()92 public MotionManager getMotionManager() { 93 return mMotionManager; 94 } 95 96 @Override 97 @Deprecated getMediaSaver()98 public MediaSaver getMediaSaver() { 99 return mMediaSaver; 100 } 101 102 @Override getRemoteShutterListener()103 public RemoteShutterListener getRemoteShutterListener() { 104 return mRemoteShutterListener; 105 } 106 107 @Override getSettingsManager()108 public SettingsManager getSettingsManager() { 109 return mSettingsManager; 110 } 111 112 /** 113 * Clears all notifications. This cleans up notifications that we might have 114 * created earlier but remained after a crash. 115 */ clearNotifications()116 private void clearNotifications() { 117 NotificationManager manager = (NotificationManager) getSystemService( 118 Context.NOTIFICATION_SERVICE); 119 if (manager != null) { 120 manager.cancelAll(); 121 } 122 } 123 } 124