Merge "network: fix binder object leakage in settings" am: bdcd3a3975
am: 5408baabdd
am: 00f25b5d5f
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2136792 Change-Id: I344cc9da6dfbb456c258ea96d9d9b47a5dac67d3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -43,6 +43,7 @@ import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -97,6 +98,7 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
private SwitchPreference mEthernetTether;
|
||||
|
||||
private BroadcastReceiver mTetherChangeReceiver;
|
||||
private BroadcastReceiver mBluetoothStateReceiver;
|
||||
|
||||
private String[] mBluetoothRegexs;
|
||||
private AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<>();
|
||||
@@ -167,6 +169,12 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener,
|
||||
BluetoothProfile.PAN);
|
||||
}
|
||||
if (mBluetoothStateReceiver == null) {
|
||||
mBluetoothStateReceiver = new BluetoothStateReceiver();
|
||||
mContext.registerReceiver(
|
||||
mBluetoothStateReceiver,
|
||||
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||
}
|
||||
|
||||
setupTetherPreference();
|
||||
setTopIntroPreferenceTitle();
|
||||
@@ -216,6 +224,10 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
if (profile != null && adapter != null) {
|
||||
adapter.closeProfileProxy(BluetoothProfile.PAN, profile);
|
||||
}
|
||||
if (mBluetoothStateReceiver != null) {
|
||||
mContext.unregisterReceiver(mBluetoothStateReceiver);
|
||||
mBluetoothStateReceiver = null;
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -255,6 +267,30 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
}
|
||||
|
||||
private class BluetoothStateReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
Log.i(TAG, "onReceive: action: " + action);
|
||||
|
||||
if (TextUtils.equals(action, BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||
final int state =
|
||||
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
||||
Log.i(TAG, "onReceive: state: " + BluetoothAdapter.nameForState(state));
|
||||
final BluetoothProfile profile = mBluetoothPan.get();
|
||||
switch(state) {
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (profile == null && adapter != null) {
|
||||
adapter.getProfileProxy(mContext, mProfileServiceListener,
|
||||
BluetoothProfile.PAN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TetherChangeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context content, Intent intent) {
|
||||
@@ -558,13 +594,16 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
|
||||
private BluetoothProfile.ServiceListener mProfileServiceListener =
|
||||
new BluetoothProfile.ServiceListener() {
|
||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||
mBluetoothPan.set((BluetoothPan) proxy);
|
||||
}
|
||||
public void onServiceDisconnected(int profile) {
|
||||
mBluetoothPan.set(null);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||
if (mBluetoothPan.get() == null) {
|
||||
mBluetoothPan.set((BluetoothPan) proxy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(int profile) { /* Do nothing */ }
|
||||
};
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
Reference in New Issue
Block a user