CameraApp.java revision ebd95379407dc99471d8091c7f23189ac0997d82
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
17package com.android.camera.app;
18
19import android.app.Application;
20import android.app.NotificationManager;
21import android.content.Context;
22
23import com.android.camera.MediaSaverImpl;
24import com.android.camera.debug.LogHelper;
25import com.android.camera.processing.ProcessingServiceManager;
26import com.android.camera.remote.RemoteShutterListener;
27import com.android.camera.session.CaptureSessionManager;
28import com.android.camera.session.CaptureSessionManagerImpl;
29import com.android.camera.session.PlaceholderManager;
30import com.android.camera.session.SessionStorageManager;
31import com.android.camera.session.SessionStorageManagerImpl;
32import com.android.camera.util.CameraUtil;
33import com.android.camera.util.RemoteShutterHelper;
34import com.android.camera.util.SessionStatsCollector;
35import com.android.camera.util.UsageStatistics;
36
37/**
38 * The Camera application class containing important services and functionality
39 * to be used across modules.
40 */
41public class CameraApp extends Application implements CameraServices {
42    private MediaSaver mMediaSaver;
43    private CaptureSessionManager mSessionManager;
44    private SessionStorageManager mSessionStorageManager;
45    private MemoryManagerImpl mMemoryManager;
46    private PlaceholderManager mPlaceHolderManager;
47    private RemoteShutterListener mRemoteShutterListener;
48
49    @Override
50    public void onCreate() {
51        super.onCreate();
52
53        Context context = getApplicationContext();
54        LogHelper.initialize(context);
55
56        // It is important that this gets called early in execution before the app has had
57        // the opportunity to create any shared preferences.
58        UsageStatistics.instance().initialize(this);
59        SessionStatsCollector.instance().initialize(this);
60        CameraUtil.initialize(this);
61
62        ProcessingServiceManager.initSingleton(context);
63
64        mMediaSaver = new MediaSaverImpl();
65        mPlaceHolderManager = new PlaceholderManager(context);
66        mSessionStorageManager = SessionStorageManagerImpl.create(this);
67        mSessionManager = new CaptureSessionManagerImpl(mMediaSaver, getContentResolver(),
68                mPlaceHolderManager, mSessionStorageManager);
69        mMemoryManager = MemoryManagerImpl.create(getApplicationContext(), mMediaSaver);
70        mRemoteShutterListener = RemoteShutterHelper.create(this);
71
72        clearNotifications();
73    }
74
75    @Override
76    public CaptureSessionManager getCaptureSessionManager() {
77        return mSessionManager;
78    }
79
80    @Override
81    public MemoryManager getMemoryManager() {
82        return mMemoryManager;
83    }
84
85    @Override
86    @Deprecated
87    public MediaSaver getMediaSaver() {
88        return mMediaSaver;
89    }
90
91    @Override
92    public RemoteShutterListener getRemoteShutterListener() {
93        return mRemoteShutterListener;
94    }
95
96    /**
97     * Clears all notifications. This cleans up notifications that we might have
98     * created earlier but remained after a crash.
99     */
100    private void clearNotifications() {
101        NotificationManager manager = (NotificationManager) getSystemService(
102                Context.NOTIFICATION_SERVICE);
103        if (manager != null) {
104            manager.cancelAll();
105        }
106    }
107}
108