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
public void 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() {
if (mUploadInProgress) {
return;

View file

@ -148,6 +148,19 @@ public class DialerActivity extends MainActivity implements AddressText.AddressC
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) {
mAddress = view.findViewById(R.id.address);
mAddress.setAddressListener(this);

View file

@ -84,7 +84,7 @@ public abstract class MainActivity extends LinphoneGenericActivity
private TextView mMissedMessages;
protected View mContactsSelected;
protected View mHistorySelected;
View mDialerSelected;
protected View mDialerSelected;
protected View mChatSelected;
private LinearLayout mTopBar;
private TextView mTopBarTitle;
@ -350,6 +350,26 @@ public abstract class MainActivity extends LinphoneGenericActivity
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
protected void onSaveInstanceState(Bundle outState) {
try {

View file

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

View file

@ -130,17 +130,8 @@ public class MenuAssistantActivity extends AssistantActivity {
@Override
protected void onResume() {
super.onResume();
if (!getResources()
if (getResources()
.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);
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -97,6 +97,7 @@ public class NotificationsManager {
Intent notifIntent = new Intent(mContext, DialerActivity.class);
notifIntent.putExtra("Notification", true);
addFlagsToIntent(notifIntent);
PendingIntent pendingIntent =
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() {
LinphoneService.instance().startForeground(SERVICE_NOTIF_ID, mServiceNotification);
mCurrentForegroundServiceNotification = SERVICE_NOTIF_ID;
@ -305,6 +310,8 @@ public class NotificationsManager {
Intent notifIntent = new Intent(mContext, ChatActivity.class);
notifIntent.putExtra("RemoteSipUri", conferenceAddress);
notifIntent.putExtra("LocalSipUri", localIdentity.asStringUriOnly());
addFlagsToIntent(notifIntent);
PendingIntent pendingIntent =
PendingIntent.getActivity(
mContext,
@ -357,6 +364,8 @@ public class NotificationsManager {
Intent notifIntent = new Intent(mContext, ChatActivity.class);
notifIntent.putExtra("RemoteSipUri", fromSipUri);
notifIntent.putExtra("LocalSipUri", localIdentity.asStringUriOnly());
addFlagsToIntent(notifIntent);
PendingIntent pendingIntent =
PendingIntent.getActivity(
mContext,
@ -372,6 +381,8 @@ public class NotificationsManager {
public void displayMissedCallNotification(Call call) {
Intent missedCallNotifIntent = new Intent(mContext, HistoryActivity.class);
addFlagsToIntent(missedCallNotifIntent);
PendingIntent pendingIntent =
PendingIntent.getActivity(
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
public void onDeleteSelection(Object[] objectsToDelete) {
int size = mRecordingsAdapter.getSelectedItemCount();

View file

@ -31,38 +31,36 @@ import androidx.annotation.Nullable;
import org.linphone.R;
public class BasicSetting extends LinearLayout {
final Context mContext;
View mView;
protected View mView;
protected SettingListener mListener;
private TextView mTitle;
private TextView mSubtitle;
SettingListener mListener;
public BasicSetting(Context context) {
super(context);
mContext = context;
init(null, 0, 0);
}
public BasicSetting(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mContext = context;
init(attrs, 0, 0);
}
public BasicSetting(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
init(attrs, defStyleAttr, 0);
}
BasicSetting(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mContext = context;
init(attrs, defStyleAttr, defStyleRes);
}
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) {
@ -88,7 +86,8 @@ public class BasicSetting extends LinearLayout {
if (attrs != null) {
TypedArray a =
mContext.getTheme()
getContext()
.getTheme()
.obtainStyledAttributes(
attrs, R.styleable.Settings, defStyleAttr, defStyleRes);
try {

View file

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

View file

@ -53,7 +53,7 @@ public class LedSetting extends BasicSetting {
}
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) {

View file

@ -54,7 +54,9 @@ public class ListSetting extends BasicSetting implements AdapterView.OnItemSelec
}
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) {
@ -67,7 +69,8 @@ public class ListSetting extends BasicSetting implements AdapterView.OnItemSelec
if (attrs != null) {
TypedArray a =
mContext.getTheme()
getContext()
.getTheme()
.obtainStyledAttributes(
attrs, R.styleable.Settings, defStyleAttr, defStyleRes);
try {
@ -92,7 +95,7 @@ public class ListSetting extends BasicSetting implements AdapterView.OnItemSelec
mItems = list;
mItemsValues = valuesList;
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);
mSpinner.setAdapter(dataAdapter);
}

View file

@ -49,7 +49,9 @@ public class SwitchSetting extends BasicSetting {
}
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) {

View file

@ -49,7 +49,9 @@ public class TextSetting extends BasicSetting {
}
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) {
@ -60,7 +62,8 @@ public class TextSetting extends BasicSetting {
if (attrs != null) {
TypedArray a =
mContext.getTheme()
getContext()
.getTheme()
.obtainStyledAttributes(
attrs, R.styleable.Settings, defStyleAttr, defStyleRes);
try {

View file

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

View file

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