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 import android.os.Debug; 23 24 import com.android.camera.stats.UsageStatistics; 25 import com.android.camera.stats.profiler.Profile; 26 import com.android.camera.stats.profiler.Profilers; 27 import com.android.camera.util.AndroidContext; 28 import com.android.camera.util.AndroidServices; 29 30 31 /** 32 * The Camera application class containing important services and functionality 33 * to be used across modules. 34 */ 35 public class CameraApp extends Application { 36 /** 37 * This is for debugging only: If set to true, application will not start 38 * until a debugger is attached. 39 * <p> 40 * Use this if you need to debug code that is executed while the app starts 41 * up and it would be too late to attach a debugger afterwards. 42 */ 43 private static final boolean WAIT_FOR_DEBUGGER_ON_START = false; 44 45 @Override onCreate()46 public void onCreate() { 47 super.onCreate(); 48 49 if (WAIT_FOR_DEBUGGER_ON_START) { 50 Debug.waitForDebugger(); 51 } 52 53 // Android context must be the first item initialized. 54 Context context = getApplicationContext(); 55 AndroidContext.initialize(context); 56 57 // This will measure and write to the exception handler if 58 // the time between any two calls or the total time from 59 // start to stop is over 10ms. 60 Profile guard = Profilers.instance().guard("CameraApp onCreate()"); 61 62 // It is important that this gets called early in execution before the 63 // app has had the opportunity to touch shared preferences. 64 FirstRunDetector.instance().initializeTimeOfFirstRun(context); 65 guard.mark("initializeTimeOfFirstRun"); 66 67 UsageStatistics.instance().initialize(this); 68 guard.mark("UsageStatistics.initialize"); 69 70 clearNotifications(); 71 guard.stop("clearNotifications"); 72 } 73 74 /** 75 * Clears all notifications. This cleans up notifications that we might have 76 * created earlier but remained after a crash. 77 */ clearNotifications()78 private void clearNotifications() { 79 NotificationManager manager = AndroidServices.instance().provideNotificationManager(); 80 if (manager != null) { 81 manager.cancelAll(); 82 } 83 } 84 } 85