1 /**
2  * Copyright (C) 2024 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 package com.android.telephony.imsmedia;
17 
18 import android.app.Application;
19 import android.content.Context;
20 
21 import com.android.telephony.imsmedia.util.Log;
22 
23 /**
24  * Extension of Application class to catch unhandled exception and release wake lock.
25  */
26 public class ImsMediaApplication extends Application {
27     private static final String TAG = "ImsMediaApplication";
28     private static Context sAppContext;
29 
30     @Override
onCreate()31     public void onCreate() {
32         super.onCreate();
33         sAppContext = getApplicationContext();
34         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
35             @Override
36             public void uncaughtException(Thread t, Throwable e) {
37                 e.printStackTrace();
38                 Log.e(TAG, "UncaughtException. Releasing all wakelocks.");
39                 WakeLockManager wakeLockManager = WakeLockManager.getInstance();
40                 if (wakeLockManager != null) {
41                     wakeLockManager.cleanup();
42                 }
43             }
44         });
45     }
46 
47     /**
48      * Static method to get application context.
49      * @return returns application context.
50      */
getAppContext()51     public static Context getAppContext() {
52         return sAppContext;
53     }
54 }
55