Fix TelephonyManager to grab the best context
It may not be called from an app so the app context may not exist. Check and grab the best one. Also remove the log that nobody paid attention to if the constructor is called again from the same process. One context seems to be as useful as another. bug:5572369 bug:5622514 Change-Id: Iad23b30c7c8fe5b8d1f81a1e060eaf0cd0e3019d
This commit is contained in:
@@ -60,16 +60,16 @@ public class TelephonyManager {
|
||||
|
||||
/** @hide */
|
||||
public TelephonyManager(Context context) {
|
||||
context = context.getApplicationContext();
|
||||
if (sContext == null) {
|
||||
sContext = context;
|
||||
Context appContext = context.getApplicationContext();
|
||||
if (appContext != null) {
|
||||
sContext = appContext;
|
||||
} else {
|
||||
sContext = context;
|
||||
}
|
||||
|
||||
sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
|
||||
"telephony.registry"));
|
||||
} else if (sContext != context) {
|
||||
Log.e(TAG, "Hidden constructor called more than once per process!");
|
||||
Log.e(TAG, "Original: " + sContext.getPackageName() + ", new: " +
|
||||
context.getPackageName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user