Force cleaning fields in Activity's onDestroy + other leak related fixes

This commit is contained in:
Sylvain Berfini 2019-07-17 16:12:43 +02:00
parent 7f8b231437
commit b9e14f1fa5
20 changed files with 167 additions and 65 deletions

View file

@ -156,16 +156,6 @@ public class AboutActivity extends MainActivity {
}; };
} }
@Override
public void onPause() {
Core core = LinphoneManager.getCore();
if (core != null) {
core.removeListener(mListener);
}
super.onPause();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -181,6 +171,24 @@ public class AboutActivity extends MainActivity {
} }
} }
@Override
public void onPause() {
Core core = LinphoneManager.getCore();
if (core != null) {
core.removeListener(mListener);
}
super.onPause();
}
@Override
protected void onDestroy() {
mListener = null;
mProgress = null;
super.onDestroy();
}
private void displayUploadLogsInProgress() { private void displayUploadLogsInProgress() {
if (mUploadInProgress) { if (mUploadInProgress) {
return; return;

View file

@ -148,6 +148,19 @@ public class DialerActivity extends MainActivity implements AddressText.AddressC
super.onPause(); super.onPause();
} }
@Override
protected void onDestroy() {
mAddress = null;
mStartCall = null;
mAddCall = null;
mTransferCall = null;
mAddContact = null;
mBackToCall = null;
mListener = null;
super.onDestroy();
}
private void initUI(View view) { private void initUI(View view) {
mAddress = view.findViewById(R.id.address); mAddress = view.findViewById(R.id.address);
mAddress.setAddressListener(this); mAddress.setAddressListener(this);

View file

@ -84,7 +84,7 @@ public abstract class MainActivity extends LinphoneGenericActivity
private TextView mMissedMessages; private TextView mMissedMessages;
protected View mContactsSelected; protected View mContactsSelected;
protected View mHistorySelected; protected View mHistorySelected;
View mDialerSelected; protected View mDialerSelected;
protected View mChatSelected; protected View mChatSelected;
private LinearLayout mTopBar; private LinearLayout mTopBar;
private TextView mTopBarTitle; private TextView mTopBarTitle;
@ -350,6 +350,26 @@ public abstract class MainActivity extends LinphoneGenericActivity
super.onPause(); super.onPause();
} }
@Override
protected void onDestroy() {
mMissedCalls = null;
mMissedMessages = null;
mContactsSelected = null;
mHistorySelected = null;
mDialerSelected = null;
mChatSelected = null;
mTopBar = null;
mTopBarTitle = null;
mTabBar = null;
mSideMenuFragment = null;
mStatusBarFragment = null;
mListener = null;
super.onDestroy();
}
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
try { try {

View file

@ -49,7 +49,7 @@ public abstract class AssistantActivity extends LinphoneGenericActivity
implements CountryPicker.CountryPickedListener { implements CountryPicker.CountryPickedListener {
static AccountCreator mAccountCreator; static AccountCreator mAccountCreator;
ImageView mBack; protected ImageView mBack;
private AlertDialog mCountryPickerDialog; private AlertDialog mCountryPickerDialog;
private CountryPicker mCountryPicker; private CountryPicker mCountryPicker;
@ -95,6 +95,15 @@ public abstract class AssistantActivity extends LinphoneGenericActivity
}); });
} }
@Override
protected void onDestroy() {
mBack = null;
mCountryPickerDialog = null;
mCountryPicker = null;
super.onDestroy();
}
@Override @Override
public void onCountryClicked(DialPlan dialPlan) { public void onCountryClicked(DialPlan dialPlan) {
if (mCountryPickerDialog != null) { if (mCountryPickerDialog != null) {
@ -166,6 +175,8 @@ public abstract class AssistantActivity extends LinphoneGenericActivity
intent = new Intent(this, OpenH264DownloadAssistantActivity.class); intent = new Intent(this, OpenH264DownloadAssistantActivity.class);
} else {*/ } else {*/
intent = new Intent(this, DialerActivity.class); intent = new Intent(this, DialerActivity.class);
intent.addFlags(
Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
// } // }
} }
startActivity(intent); startActivity(intent);

View file

@ -130,17 +130,8 @@ public class MenuAssistantActivity extends AssistantActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (!getResources() if (getResources()
.getBoolean(R.bool.forbid_to_leave_assistant_before_account_configuration)) { .getBoolean(R.bool.forbid_to_leave_assistant_before_account_configuration)) {
mBack.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
LinphonePreferences.instance().firstLaunchSuccessful();
goToLinphoneActivity();
}
});
} else {
mBack.setEnabled(false); mBack.setEnabled(false);
} }
} }

View file

@ -504,6 +504,8 @@ public class CallActivity extends LinphoneGenericActivity
mCallTimer.stop(); mCallTimer.stop();
mCallTimer = null; mCallTimer = null;
mListener = null;
mLocalPreview = null; mLocalPreview = null;
mRemoteVideo = null; mRemoteVideo = null;
mStatsFragment = null; mStatsFragment = null;
@ -868,6 +870,7 @@ public class CallActivity extends LinphoneGenericActivity
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClass(this, DialerActivity.class); intent.setClass(this, DialerActivity.class);
intent.putExtra("Transfer", false); intent.putExtra("Transfer", false);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent); startActivity(intent);
} }
@ -875,12 +878,14 @@ public class CallActivity extends LinphoneGenericActivity
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClass(this, DialerActivity.class); intent.setClass(this, DialerActivity.class);
intent.putExtra("Transfer", true); intent.putExtra("Transfer", true);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent); startActivity(intent);
} }
private void goToChatList() { private void goToChatList() {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClass(this, ChatActivity.class); intent.setClass(this, ChatActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent); startActivity(intent);
} }

View file

@ -124,16 +124,26 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
@Override @Override
public void onCallStateChanged( public void onCallStateChanged(
Core core, Call call, State state, String message) { Core core, Call call, State state, String message) {
if (call == mCall && State.End == state) { if (call == mCall) {
if (state == State.Connected) {
startActivity(
new Intent(CallIncomingActivity.this, CallActivity.class));
}
}
if (LinphoneManager.getCore().getCallsNb() == 0) {
finish(); finish();
} else if (state == State.Connected) {
startActivity(
new Intent(CallIncomingActivity.this, CallActivity.class));
} }
} }
}; };
} }
@Override
protected void onStart() {
super.onStart();
checkAndRequestCallPermissions();
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@ -174,12 +184,6 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
} }
} }
@Override
protected void onStart() {
super.onStart();
checkAndRequestCallPermissions();
}
@Override @Override
protected void onPause() { protected void onPause() {
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
@ -189,6 +193,17 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
super.onPause(); super.onPause();
} }
@Override
protected void onDestroy() {
mName = null;
mNumber = null;
mCall = null;
mListener = null;
mVideoDisplay = null;
super.onDestroy();
}
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (LinphoneService.isReady() if (LinphoneService.isReady()
@ -218,7 +233,6 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
mAlreadyAcceptedOrDeniedCall = true; mAlreadyAcceptedOrDeniedCall = true;
mCall.terminate(); mCall.terminate();
finish();
} }
private void answer() { private void answer() {

View file

@ -94,35 +94,30 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
getString(R.string.error_call_declined), getString(R.string.error_call_declined),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
decline();
} else if (call.getErrorInfo().getReason() == Reason.NotFound) { } else if (call.getErrorInfo().getReason() == Reason.NotFound) {
Toast.makeText( Toast.makeText(
CallOutgoingActivity.this, CallOutgoingActivity.this,
getString(R.string.error_user_not_found), getString(R.string.error_user_not_found),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
decline();
} else if (call.getErrorInfo().getReason() == Reason.NotAcceptable) { } else if (call.getErrorInfo().getReason() == Reason.NotAcceptable) {
Toast.makeText( Toast.makeText(
CallOutgoingActivity.this, CallOutgoingActivity.this,
getString(R.string.error_incompatible_media), getString(R.string.error_incompatible_media),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
decline();
} else if (call.getErrorInfo().getReason() == Reason.Busy) { } else if (call.getErrorInfo().getReason() == Reason.Busy) {
Toast.makeText( Toast.makeText(
CallOutgoingActivity.this, CallOutgoingActivity.this,
getString(R.string.error_user_busy), getString(R.string.error_user_busy),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
decline();
} else if (message != null) { } else if (message != null) {
Toast.makeText( Toast.makeText(
CallOutgoingActivity.this, CallOutgoingActivity.this,
getString(R.string.error_unknown) + " - " + message, getString(R.string.error_unknown) + " - " + message,
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
decline();
} }
} else if (state == State.End) { } else if (state == State.End) {
// Convert Core message for internalization // Convert Core message for internalization
@ -132,7 +127,6 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
getString(R.string.error_call_declined), getString(R.string.error_call_declined),
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
decline();
} }
} else if (state == State.Connected) { } else if (state == State.Connected) {
startActivity( startActivity(
@ -146,6 +140,12 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
}; };
} }
@Override
protected void onStart() {
super.onStart();
checkAndRequestCallPermissions();
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@ -188,12 +188,6 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
mNumber.setText(LinphoneUtils.getDisplayableAddress(address)); mNumber.setText(LinphoneUtils.getDisplayableAddress(address));
} }
@Override
protected void onStart() {
super.onStart();
checkAndRequestCallPermissions();
}
@Override @Override
protected void onPause() { protected void onPause() {
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
@ -203,6 +197,18 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
super.onPause(); super.onPause();
} }
@Override
protected void onDestroy() {
mName = null;
mNumber = null;
mMicro = null;
mSpeaker = null;
mCall = null;
mListener = null;
super.onDestroy();
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int id = v.getId(); int id = v.getId();

View file

@ -37,8 +37,8 @@ public class CallStatsAdapter extends BaseExpandableListAdapter {
private final Context mContext; private final Context mContext;
private List<Call> mCalls; private List<Call> mCalls;
public CallStatsAdapter(Context mContext) { public CallStatsAdapter(Context context) {
this.mContext = mContext; mContext = context;
mCalls = new ArrayList<>(); mCalls = new ArrayList<>();
} }

View file

@ -86,5 +86,6 @@ class ApiTwentyFivePlus {
} }
shortcutManager.setDynamicShortcuts(shortcuts); shortcutManager.setDynamicShortcuts(shortcuts);
manager.destroy();
} }
} }

View file

@ -97,6 +97,7 @@ public class NotificationsManager {
Intent notifIntent = new Intent(mContext, DialerActivity.class); Intent notifIntent = new Intent(mContext, DialerActivity.class);
notifIntent.putExtra("Notification", true); notifIntent.putExtra("Notification", true);
addFlagsToIntent(notifIntent);
PendingIntent pendingIntent = PendingIntent pendingIntent =
PendingIntent.getActivity( PendingIntent.getActivity(
@ -220,6 +221,10 @@ public class NotificationsManager {
} }
} }
private void addFlagsToIntent(Intent intent) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
}
public void startForeground() { public void startForeground() {
LinphoneService.instance().startForeground(SERVICE_NOTIF_ID, mServiceNotification); LinphoneService.instance().startForeground(SERVICE_NOTIF_ID, mServiceNotification);
mCurrentForegroundServiceNotification = SERVICE_NOTIF_ID; mCurrentForegroundServiceNotification = SERVICE_NOTIF_ID;
@ -305,6 +310,8 @@ public class NotificationsManager {
Intent notifIntent = new Intent(mContext, ChatActivity.class); Intent notifIntent = new Intent(mContext, ChatActivity.class);
notifIntent.putExtra("RemoteSipUri", conferenceAddress); notifIntent.putExtra("RemoteSipUri", conferenceAddress);
notifIntent.putExtra("LocalSipUri", localIdentity.asStringUriOnly()); notifIntent.putExtra("LocalSipUri", localIdentity.asStringUriOnly());
addFlagsToIntent(notifIntent);
PendingIntent pendingIntent = PendingIntent pendingIntent =
PendingIntent.getActivity( PendingIntent.getActivity(
mContext, mContext,
@ -357,6 +364,8 @@ public class NotificationsManager {
Intent notifIntent = new Intent(mContext, ChatActivity.class); Intent notifIntent = new Intent(mContext, ChatActivity.class);
notifIntent.putExtra("RemoteSipUri", fromSipUri); notifIntent.putExtra("RemoteSipUri", fromSipUri);
notifIntent.putExtra("LocalSipUri", localIdentity.asStringUriOnly()); notifIntent.putExtra("LocalSipUri", localIdentity.asStringUriOnly());
addFlagsToIntent(notifIntent);
PendingIntent pendingIntent = PendingIntent pendingIntent =
PendingIntent.getActivity( PendingIntent.getActivity(
mContext, mContext,
@ -372,6 +381,8 @@ public class NotificationsManager {
public void displayMissedCallNotification(Call call) { public void displayMissedCallNotification(Call call) {
Intent missedCallNotifIntent = new Intent(mContext, HistoryActivity.class); Intent missedCallNotifIntent = new Intent(mContext, HistoryActivity.class);
addFlagsToIntent(missedCallNotifIntent);
PendingIntent pendingIntent = PendingIntent pendingIntent =
PendingIntent.getActivity( PendingIntent.getActivity(
mContext, mContext,

View file

@ -138,6 +138,17 @@ public class RecordingsActivity extends MainActivity
} }
} }
@Override
protected void onDestroy() {
mRecordingList = null;
mRecordings = null;
mNoRecordings = null;
mRecordingsAdapter = null;
mSelectableHelper = null;
super.onDestroy();
}
@Override @Override
public void onDeleteSelection(Object[] objectsToDelete) { public void onDeleteSelection(Object[] objectsToDelete) {
int size = mRecordingsAdapter.getSelectedItemCount(); int size = mRecordingsAdapter.getSelectedItemCount();

View file

@ -31,38 +31,36 @@ import androidx.annotation.Nullable;
import org.linphone.R; import org.linphone.R;
public class BasicSetting extends LinearLayout { public class BasicSetting extends LinearLayout {
final Context mContext; protected View mView;
View mView; protected SettingListener mListener;
private TextView mTitle; private TextView mTitle;
private TextView mSubtitle; private TextView mSubtitle;
SettingListener mListener;
public BasicSetting(Context context) { public BasicSetting(Context context) {
super(context); super(context);
mContext = context;
init(null, 0, 0); init(null, 0, 0);
} }
public BasicSetting(Context context, @Nullable AttributeSet attrs) { public BasicSetting(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mContext = context;
init(attrs, 0, 0); init(attrs, 0, 0);
} }
public BasicSetting(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { public BasicSetting(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
mContext = context;
init(attrs, defStyleAttr, 0); init(attrs, defStyleAttr, 0);
} }
BasicSetting(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { BasicSetting(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
mContext = context;
init(attrs, defStyleAttr, defStyleRes); init(attrs, defStyleAttr, defStyleRes);
} }
void inflateView() { void inflateView() {
mView = LayoutInflater.from(mContext).inflate(R.layout.settings_widget_basic, this, true); mView =
LayoutInflater.from(getContext())
.inflate(R.layout.settings_widget_basic, this, true);
} }
public void setListener(SettingListener listener) { public void setListener(SettingListener listener) {
@ -88,7 +86,8 @@ public class BasicSetting extends LinearLayout {
if (attrs != null) { if (attrs != null) {
TypedArray a = TypedArray a =
mContext.getTheme() getContext()
.getTheme()
.obtainStyledAttributes( .obtainStyledAttributes(
attrs, R.styleable.Settings, defStyleAttr, defStyleRes); attrs, R.styleable.Settings, defStyleAttr, defStyleRes);
try { try {

View file

@ -50,7 +50,7 @@ public class CheckBoxSetting extends BasicSetting {
protected void inflateView() { protected void inflateView() {
mView = mView =
LayoutInflater.from(mContext) LayoutInflater.from(getContext())
.inflate(R.layout.settings_widget_checkbox, this, true); .inflate(R.layout.settings_widget_checkbox, this, true);
} }

View file

@ -53,7 +53,7 @@ public class LedSetting extends BasicSetting {
} }
protected void inflateView() { protected void inflateView() {
mView = LayoutInflater.from(mContext).inflate(R.layout.settings_widget_led, this, true); mView = LayoutInflater.from(getContext()).inflate(R.layout.settings_widget_led, this, true);
} }
protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {

View file

@ -54,7 +54,9 @@ public class ListSetting extends BasicSetting implements AdapterView.OnItemSelec
} }
protected void inflateView() { protected void inflateView() {
mView = LayoutInflater.from(mContext).inflate(R.layout.settings_widget_list, this, true); mView =
LayoutInflater.from(getContext())
.inflate(R.layout.settings_widget_list, this, true);
} }
protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@ -67,7 +69,8 @@ public class ListSetting extends BasicSetting implements AdapterView.OnItemSelec
if (attrs != null) { if (attrs != null) {
TypedArray a = TypedArray a =
mContext.getTheme() getContext()
.getTheme()
.obtainStyledAttributes( .obtainStyledAttributes(
attrs, R.styleable.Settings, defStyleAttr, defStyleRes); attrs, R.styleable.Settings, defStyleAttr, defStyleRes);
try { try {
@ -92,7 +95,7 @@ public class ListSetting extends BasicSetting implements AdapterView.OnItemSelec
mItems = list; mItems = list;
mItemsValues = valuesList; mItemsValues = valuesList;
ArrayAdapter<String> dataAdapter = ArrayAdapter<String> dataAdapter =
new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, list); new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(dataAdapter); mSpinner.setAdapter(dataAdapter);
} }

View file

@ -49,7 +49,9 @@ public class SwitchSetting extends BasicSetting {
} }
protected void inflateView() { protected void inflateView() {
mView = LayoutInflater.from(mContext).inflate(R.layout.settings_widget_switch, this, true); mView =
LayoutInflater.from(getContext())
.inflate(R.layout.settings_widget_switch, this, true);
} }
protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {

View file

@ -49,7 +49,9 @@ public class TextSetting extends BasicSetting {
} }
protected void inflateView() { protected void inflateView() {
mView = LayoutInflater.from(mContext).inflate(R.layout.settings_widget_text, this, true); mView =
LayoutInflater.from(getContext())
.inflate(R.layout.settings_widget_text, this, true);
} }
protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { protected void init(@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@ -60,7 +62,8 @@ public class TextSetting extends BasicSetting {
if (attrs != null) { if (attrs != null) {
TypedArray a = TypedArray a =
mContext.getTheme() getContext()
.getTheme()
.obtainStyledAttributes( .obtainStyledAttributes(
attrs, R.styleable.Settings, defStyleAttr, defStyleRes); attrs, R.styleable.Settings, defStyleAttr, defStyleRes);
try { try {

View file

@ -43,6 +43,10 @@ public class LinphoneShortcutManager {
mCategories.add(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION); mCategories.add(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION);
} }
public void destroy() {
mContext = null;
}
public ShortcutInfo createChatRoomShortcutInfo( public ShortcutInfo createChatRoomShortcutInfo(
LinphoneContact contact, String chatRoomAddress) { LinphoneContact contact, String chatRoomAddress) {
if (contact == null) return null; if (contact == null) return null;

View file

@ -41,7 +41,7 @@ public class SelectableHelper {
private int mDialogDeleteMessageResourceId; private int mDialogDeleteMessageResourceId;
public SelectableHelper(View view, DeleteListener listener) { public SelectableHelper(View view, DeleteListener listener) {
mContext = view.getContext(); mContext = view.getContext().getApplicationContext();
mDeleteListener = listener; mDeleteListener = listener;
mEditTopBar = view.findViewById(R.id.edit_list); mEditTopBar = view.findViewById(R.id.edit_list);