Merge "Use a cached context when possible." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
2c507b92c2
@@ -23,6 +23,7 @@ import android.os.Bundle;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.telephony.IPhoneSubInfo;
|
import com.android.internal.telephony.IPhoneSubInfo;
|
||||||
import com.android.internal.telephony.ITelephony;
|
import com.android.internal.telephony.ITelephony;
|
||||||
@@ -55,14 +56,21 @@ import java.util.List;
|
|||||||
public class TelephonyManager {
|
public class TelephonyManager {
|
||||||
private static final String TAG = "TelephonyManager";
|
private static final String TAG = "TelephonyManager";
|
||||||
|
|
||||||
private Context mContext;
|
private static Context sContext;
|
||||||
private ITelephonyRegistry mRegistry;
|
private static ITelephonyRegistry sRegistry;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public TelephonyManager(Context context) {
|
public TelephonyManager(Context context) {
|
||||||
mContext = context;
|
if (sContext == null) {
|
||||||
mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
|
sContext = context;
|
||||||
|
|
||||||
|
sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
|
||||||
"telephony.registry"));
|
"telephony.registry"));
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Hidden constructor called more than once per process!");
|
||||||
|
Log.e(TAG, "Original: " + sContext.getPackageName() + ", new: " +
|
||||||
|
context.getPackageName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -71,7 +79,8 @@ public class TelephonyManager {
|
|||||||
|
|
||||||
private static TelephonyManager sInstance = new TelephonyManager();
|
private static TelephonyManager sInstance = new TelephonyManager();
|
||||||
|
|
||||||
/** @hide */
|
/** @hide
|
||||||
|
/* @deprecated - use getSystemService as described above */
|
||||||
public static TelephonyManager getDefault() {
|
public static TelephonyManager getDefault() {
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
@@ -889,10 +898,10 @@ public class TelephonyManager {
|
|||||||
* LISTEN_ flags.
|
* LISTEN_ flags.
|
||||||
*/
|
*/
|
||||||
public void listen(PhoneStateListener listener, int events) {
|
public void listen(PhoneStateListener listener, int events) {
|
||||||
String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
|
String pkgForDebug = sContext != null ? sContext.getPackageName() : "<unknown>";
|
||||||
try {
|
try {
|
||||||
Boolean notifyNow = (getITelephony() != null);
|
Boolean notifyNow = (getITelephony() != null);
|
||||||
mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
|
sRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
// system process dead
|
// system process dead
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
@@ -967,7 +976,8 @@ public class TelephonyManager {
|
|||||||
* @hide pending API review
|
* @hide pending API review
|
||||||
*/
|
*/
|
||||||
public boolean isVoiceCapable() {
|
public boolean isVoiceCapable() {
|
||||||
return mContext.getResources().getBoolean(
|
if (sContext == null) return true;
|
||||||
|
return sContext.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_voice_capable);
|
com.android.internal.R.bool.config_voice_capable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -983,7 +993,8 @@ public class TelephonyManager {
|
|||||||
* @hide pending API review
|
* @hide pending API review
|
||||||
*/
|
*/
|
||||||
public boolean isSmsCapable() {
|
public boolean isSmsCapable() {
|
||||||
return mContext.getResources().getBoolean(
|
if (sContext == null) return true;
|
||||||
|
return sContext.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_sms_capable);
|
com.android.internal.R.bool.config_sms_capable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user