Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Put in defense for issue 278 #290

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -19,11 +20,14 @@
/**
* Dialog to prompt the user to go to the app's settings screen and enable permissions. If the user
* clicks 'OK' on the dialog, they are sent to the settings screen. The result is returned to the
* Activity via {@link Activity#onActivityResult(int, int, Intent)}.
* Activity via {@see Activity#onActivityResult(int, int, Intent)}.
* <p>
* Use the {@link Builder} to create and display a dialog.
*/
public class AppSettingsDialog implements Parcelable {

private static final String TAG = "EasyPermissions";

public static final int DEFAULT_SETTINGS_REQ_CODE = 16061;

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down Expand Up @@ -83,6 +87,19 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,

static AppSettingsDialog fromIntent(Intent intent, Activity activity) {
AppSettingsDialog dialog = intent.getParcelableExtra(AppSettingsDialog.EXTRA_APP_SETTINGS);

// It's not clear how this could happen, but in the case that it does we should try
// to avoid a runtime crash and just use the default dialog.
// https://github.com/googlesamples/easypermissions/issues/278
if (dialog == null) {
Log.e(TAG, "Intent contains null value for EXTRA_APP_SETTINGS: "
+ "intent=" + intent
+ ", "
+ "extras=" + intent.getExtras());

dialog = new AppSettingsDialog.Builder(activity).build();
}

dialog.setActivityOrFragment(activity);
return dialog;
}
Expand Down Expand Up @@ -261,7 +278,7 @@ public Builder setPositiveButton(@StringRes int textId) {
* Set the negative button text, default is {@link android.R.string#cancel}.
* <p>
* To know if a user cancelled the request, check if your permissions were given with {@link
* EasyPermissions#hasPermissions(Context, String...)} in {@link
* EasyPermissions#hasPermissions(Context, String...)} in {@see
* Activity#onActivityResult(int, int, Intent)}. If you still don't have the right
* permissions, then the request was cancelled.
*/
Expand All @@ -282,7 +299,7 @@ public Builder setNegativeButton(@StringRes int textId) {

/**
* Set the request code use when launching the Settings screen for result, can be retrieved
* in the calling Activity's {@link Activity#onActivityResult(int, int, Intent)} method.
* in the calling Activity's {@see Activity#onActivityResult(int, int, Intent)} method.
* Default is {@link #DEFAULT_SETTINGS_REQ_CODE}.
*/
@NonNull
Expand Down